| 419 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.Cookie;
|
|
|
4 |
|
| 832 |
rajveer |
5 |
import org.apache.log4j.Logger;
|
| 507 |
rajveer |
6 |
import org.apache.struts2.convention.annotation.Action;
|
| 419 |
rajveer |
7 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
8 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
9 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
10 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
11 |
|
|
|
12 |
@Results({
|
|
|
13 |
@Result(name="success", type="redirectAction",
|
|
|
14 |
params = {"actionName" , "test"})
|
|
|
15 |
})
|
|
|
16 |
|
|
|
17 |
public class TestController extends BaseController {
|
|
|
18 |
private static final long serialVersionUID = 1L;
|
|
|
19 |
|
| 832 |
rajveer |
20 |
private static Logger log = Logger.getLogger(Class.class);
|
| 419 |
rajveer |
21 |
// HttpServletRequest request;
|
|
|
22 |
// HttpServletResponse response;
|
|
|
23 |
|
|
|
24 |
public TestController(){
|
|
|
25 |
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
|
| 555 |
chandransh |
29 |
// GET /this
|
| 507 |
rajveer |
30 |
@Action("this")
|
| 419 |
rajveer |
31 |
public HttpHeaders index() {
|
| 555 |
chandransh |
32 |
this.session.invalidate();
|
| 419 |
rajveer |
33 |
Cookie[] cookies = request.getCookies();
|
|
|
34 |
boolean foundCookie = false;
|
|
|
35 |
long sessionId = 0;
|
|
|
36 |
|
|
|
37 |
if(cookies != null){
|
|
|
38 |
for(int loopIndex = 0; loopIndex < cookies.length; loopIndex++) {
|
|
|
39 |
Cookie cookie1 = cookies[loopIndex];
|
|
|
40 |
if (cookie1.getName().equals("sessionId")) {
|
|
|
41 |
sessionId = Long.parseLong(cookie1.getValue());
|
| 2145 |
chandransh |
42 |
System.out.println("Session Id is = " + sessionId);
|
| 419 |
rajveer |
43 |
foundCookie = true;
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
|
| 2145 |
chandransh |
49 |
// UserContextServiceClient userContextServiceClient;
|
|
|
50 |
// Client client;
|
| 555 |
chandransh |
51 |
// UserContext context;
|
| 2145 |
chandransh |
52 |
// try {
|
|
|
53 |
// userContextServiceClient = new UserContextServiceClient();
|
|
|
54 |
// client = userContextServiceClient.getClient();
|
| 555 |
chandransh |
55 |
//TODO: Commented out since it's not super-critical to compile TestController
|
|
|
56 |
// if (!foundCookie) {
|
|
|
57 |
// // create new session and set the cookies
|
|
|
58 |
// context = new UserContext();
|
|
|
59 |
// context = client.createContext(context, false);
|
|
|
60 |
// sessionId = context.getSessionid();
|
|
|
61 |
//
|
|
|
62 |
// Cookie loginCookie = new Cookie("sessionId", sessionId+"");
|
|
|
63 |
// loginCookie.setComment("For storing session id");
|
|
|
64 |
// loginCookie.setMaxAge(24*60*60);
|
|
|
65 |
// //loginCookie.setValue("Rajveer");
|
|
|
66 |
// response.addCookie(loginCookie);
|
|
|
67 |
// }
|
|
|
68 |
//
|
|
|
69 |
// else{
|
|
|
70 |
// context = client.getContextFromId(sessionId, false);
|
|
|
71 |
// if(context.getUserState().isIsLoggedIn()){
|
|
|
72 |
// System.out.println("User is logged in with user Id " + context.getId());
|
|
|
73 |
// }
|
|
|
74 |
//
|
|
|
75 |
// }
|
| 2145 |
chandransh |
76 |
//
|
|
|
77 |
//
|
|
|
78 |
// } catch (Exception e1) {
|
|
|
79 |
// // TODO Auto-generated catch block
|
|
|
80 |
// e1.printStackTrace();
|
|
|
81 |
// }
|
| 419 |
rajveer |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
/*
|
|
|
88 |
Map cookiesMap = new HashMap();
|
|
|
89 |
cookiesMap.put("USER_ID", loginCookie);
|
|
|
90 |
setCookiesMap(cookiesMap);
|
|
|
91 |
|
|
|
92 |
log.info( "Cookies map is " + this.getCookiesMap());
|
|
|
93 |
log.info("CartController.index");
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
if(getCookiesMap() != null){
|
|
|
98 |
Cookie loginCookie = (Cookie)getCookiesMap().get("USER_ID");
|
|
|
99 |
log.info("login cookie name is " + loginCookie.getName() );
|
|
|
100 |
log.info("login cookie value is " + loginCookie.getValue());
|
|
|
101 |
}
|
|
|
102 |
*/
|
|
|
103 |
|
|
|
104 |
return new DefaultHttpHeaders("index").disableCaching();
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/*
|
|
|
108 |
@Override
|
|
|
109 |
public void setParameters(Map<String, String[]> reqmap) {
|
|
|
110 |
log.info("setParameters:" + reqmap);
|
|
|
111 |
|
|
|
112 |
this.reqparams = reqmap;
|
|
|
113 |
}
|
|
|
114 |
*/
|
|
|
115 |
|
|
|
116 |
// @Override
|
|
|
117 |
// public void setServletRequest(HttpServletRequest request) {
|
|
|
118 |
// this.request = request;
|
|
|
119 |
// }
|
|
|
120 |
//
|
|
|
121 |
//
|
|
|
122 |
// @Override
|
|
|
123 |
// public void setServletResponse(HttpServletResponse response) {
|
|
|
124 |
// this.response = response;
|
|
|
125 |
// // TODO Auto-generated method stub
|
|
|
126 |
//
|
|
|
127 |
// }
|
|
|
128 |
|
|
|
129 |
}
|