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