| Line 9... |
Line 9... |
| 9 |
import javax.servlet.http.Cookie;
|
9 |
import javax.servlet.http.Cookie;
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
10 |
import javax.servlet.http.HttpServletRequest;
|
| 11 |
import javax.servlet.http.HttpServletResponse;
|
11 |
import javax.servlet.http.HttpServletResponse;
|
| 12 |
import javax.servlet.http.HttpSession;
|
12 |
import javax.servlet.http.HttpSession;
|
| 13 |
|
13 |
|
| - |
|
14 |
import nl.bitwalker.useragentutils.BrowserType;
|
| - |
|
15 |
import nl.bitwalker.useragentutils.UserAgent;
|
| - |
|
16 |
|
| 14 |
import org.apache.log4j.Logger;
|
17 |
import org.apache.log4j.Logger;
|
| 15 |
import org.apache.struts2.ServletActionContext;
|
18 |
import org.apache.struts2.ServletActionContext;
|
| 16 |
|
19 |
|
| 17 |
import com.opensymphony.xwork2.ActionInvocation;
|
20 |
import com.opensymphony.xwork2.ActionInvocation;
|
| 18 |
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
21 |
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
| Line 33... |
Line 36... |
| 33 |
@Override
|
36 |
@Override
|
| 34 |
public String intercept(ActionInvocation invocation) throws Exception {
|
37 |
public String intercept(ActionInvocation invocation) throws Exception {
|
| 35 |
final Object action = invocation.getAction();
|
38 |
final Object action = invocation.getAction();
|
| 36 |
|
39 |
|
| 37 |
HttpServletRequest request = ServletActionContext.getRequest();
|
40 |
HttpServletRequest request = ServletActionContext.getRequest();
|
| - |
|
41 |
|
| - |
|
42 |
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
| - |
|
43 |
log.info("User browser is:" + userAgent.getBrowser() + " OS is:" + userAgent.getOperatingSystem());
|
| - |
|
44 |
|
| - |
|
45 |
|
| 38 |
HttpSession session = request.getSession(); // Get the existing session or create a new one
|
46 |
HttpSession session = request.getSession(); // Get the existing session or create a new one
|
| 39 |
|
47 |
|
| 40 |
//getCookiesMap(request);
|
48 |
//getCookiesMap(request);
|
| 41 |
createCookiesMap(request);
|
49 |
createCookiesMap(request);
|
| 42 |
|
50 |
|
| 43 |
// If the request is for an active session.
|
51 |
// If the request is for an active session.
|
| 44 |
UserSessionInfo userInfo = (UserSessionInfo) session.getAttribute(USER_INFO);
|
52 |
UserSessionInfo userInfo = (UserSessionInfo) session.getAttribute(USER_INFO);
|
| 45 |
|
53 |
|
| 46 |
// Set the userinfo and the uid cookie if they're not already set.
|
54 |
// Set the userinfo and the uid cookie if they're not already set.
|
| 47 |
if (userInfo == null) {
|
55 |
if (userInfo == null) {
|
| - |
|
56 |
if(userAgent.getBrowser().getBrowserType() == BrowserType.WEB_BROWSER){
|
| 48 |
userInfo = createAndGetSessionFromUIDCookie(session);
|
57 |
userInfo = createAndGetSessionFromUIDCookie(session);
|
| - |
|
58 |
}else{
|
| - |
|
59 |
userInfo = new UserSessionInfo();
|
| - |
|
60 |
}
|
| 49 |
session.setAttribute(USER_INFO, userInfo);
|
61 |
session.setAttribute(USER_INFO, userInfo);
|
| 50 |
}
|
62 |
}
|
| 51 |
else {
|
63 |
else {
|
| 52 |
// Update user cookie in case of new registration and login.
|
64 |
// Update user cookie in case of new registration and login.
|
| 53 |
createUserCookie(userInfo.getUserId(), false);
|
65 |
createUserCookie(userInfo.getUserId(), false);
|