| 9269 |
amit.gupta |
1 |
package in.shop2020.mobileapi.serving.controllers;
|
| 9103 |
anupam.sin |
2 |
|
| 9269 |
amit.gupta |
3 |
import in.shop2020.mobileapi.serving.interceptors.UserAware;
|
|
|
4 |
import in.shop2020.mobileapi.serving.services.PageLoaderHandler;
|
|
|
5 |
import in.shop2020.mobileapi.serving.services.UserSessionInfo;
|
|
|
6 |
import in.shop2020.mobileapi.serving.utils.DesEncrypter;
|
| 9103 |
anupam.sin |
7 |
import in.shop2020.model.v1.catalog.Banner;
|
|
|
8 |
import in.shop2020.model.v1.catalog.BannerMap;
|
|
|
9 |
|
|
|
10 |
import java.util.ArrayList;
|
| 10849 |
amit.gupta |
11 |
import java.util.Enumeration;
|
| 9103 |
anupam.sin |
12 |
import java.util.HashMap;
|
| 10849 |
amit.gupta |
13 |
import java.util.Iterator;
|
| 9103 |
anupam.sin |
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
|
|
16 |
|
|
|
17 |
import javax.servlet.http.Cookie;
|
|
|
18 |
import javax.servlet.http.HttpServletRequest;
|
|
|
19 |
import javax.servlet.http.HttpServletResponse;
|
|
|
20 |
import javax.servlet.http.HttpSession;
|
|
|
21 |
|
|
|
22 |
import org.apache.log4j.Logger;
|
|
|
23 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
24 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
25 |
|
| 10300 |
amit.gupta |
26 |
import com.google.gson.Gson;
|
| 9103 |
anupam.sin |
27 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Base class for all user action handlers i.e. controllers
|
|
|
31 |
*
|
|
|
32 |
* @author rajveer
|
|
|
33 |
*/
|
|
|
34 |
public abstract class BaseController extends ValidationAwareSupport implements
|
| 9601 |
amit.gupta |
35 |
ServletResponseAware, ServletRequestAware, UserAware {
|
| 9103 |
anupam.sin |
36 |
/**
|
|
|
37 |
*
|
|
|
38 |
*/
|
|
|
39 |
private static final long serialVersionUID = 1L;
|
|
|
40 |
protected Map<String, Cookie> cookiesMap = null;
|
|
|
41 |
protected HttpServletResponse response;
|
|
|
42 |
protected HttpServletRequest request;
|
|
|
43 |
protected HttpSession session;
|
|
|
44 |
protected String domainName;
|
|
|
45 |
protected UserSessionInfo userinfo = null;
|
|
|
46 |
private static Logger log = Logger.getLogger(Class.class);
|
| 10283 |
amit.gupta |
47 |
private String resultJson;
|
| 9103 |
anupam.sin |
48 |
|
|
|
49 |
protected Cookie userCookie = null;
|
|
|
50 |
|
|
|
51 |
protected Map<String, String> htmlSnippets;
|
|
|
52 |
|
|
|
53 |
PageLoaderHandler pageLoader = null;
|
|
|
54 |
|
|
|
55 |
public static Map<String,List<Banner>> activeBanners = null;
|
|
|
56 |
public static Map<String, List<BannerMap>> allBannersMap = null;
|
|
|
57 |
|
| 9157 |
amit.gupta |
58 |
|
| 9103 |
anupam.sin |
59 |
|
|
|
60 |
public List<BannerMap> getbannermapdetails(String bannerName) {
|
|
|
61 |
return allBannersMap.get(bannerName);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public BaseController() {
|
|
|
66 |
pageLoader = new PageLoaderHandler();
|
|
|
67 |
htmlSnippets = new HashMap<String, String>();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
@Override
|
|
|
71 |
public void setCookiesMap(Map<String, Cookie> cookiesMap) {
|
|
|
72 |
log.info("Received cookiesMap.");
|
|
|
73 |
this.cookiesMap = cookiesMap;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
@Override
|
|
|
77 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
78 |
this.response = response;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
@Override
|
|
|
82 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
83 |
this.request = request;
|
| 10850 |
amit.gupta |
84 |
log.info("request url:" + request.getRequestURL());
|
| 10849 |
amit.gupta |
85 |
Enumeration enu = request.getParameterNames();
|
|
|
86 |
while(enu.hasMoreElements()){
|
|
|
87 |
Object obj = enu.nextElement();
|
|
|
88 |
log.info(obj.toString()+":" + request.getParameter(obj.toString()));
|
|
|
89 |
}
|
| 9103 |
anupam.sin |
90 |
}
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public void setSession(HttpSession session) {
|
|
|
94 |
this.session = session;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
@Override
|
|
|
98 |
public void setUserSessionInfo(UserSessionInfo userInfo) {
|
|
|
99 |
this.userinfo = userInfo;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
@Override
|
|
|
103 |
public void setUserCookie(Cookie userCookie) {
|
|
|
104 |
if(userCookie != null){
|
|
|
105 |
log.info("cookie name is:" + userCookie.getName() + " value is:"+ userCookie.getValue() + " path : " + userCookie.getPath());
|
|
|
106 |
}
|
|
|
107 |
this.userCookie = userCookie;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
@Override
|
|
|
111 |
public void setCookieDomainName(String domainName) {
|
|
|
112 |
this.domainName = domainName;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public UserSessionInfo getUserInfo(){
|
|
|
116 |
return this.userinfo;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
@Override
|
|
|
120 |
public List<Cookie> getCookies() {
|
|
|
121 |
List<Cookie> cookies = new ArrayList<Cookie>();
|
|
|
122 |
return cookies;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public String getCookie(String cookieName, boolean isEncripted, String encriptionString) {
|
|
|
126 |
Cookie cookie = (Cookie) cookiesMap.get(cookieName);
|
|
|
127 |
String cookieVal = null;
|
|
|
128 |
if (cookie != null) {
|
|
|
129 |
cookieVal = cookie.getValue();
|
|
|
130 |
if (isEncripted) {
|
|
|
131 |
DesEncrypter desEncrypter = new DesEncrypter(encriptionString);
|
|
|
132 |
cookieVal = desEncrypter.decrypt(cookieVal);
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
return cookieVal;
|
|
|
136 |
}
|
| 10283 |
amit.gupta |
137 |
|
|
|
138 |
|
| 10300 |
amit.gupta |
139 |
public void setResultJson(Object resultJSon) {
|
| 14195 |
amit.gupta |
140 |
log.info("Result- " + resultJson.toString() );
|
| 10300 |
amit.gupta |
141 |
if(!resultJSon.getClass().equals(String.class)) {
|
|
|
142 |
this.resultJson = new Gson().toJson(resultJSon);
|
|
|
143 |
} else {
|
|
|
144 |
this.resultJson = (String)resultJSon;
|
|
|
145 |
}
|
| 10384 |
amit.gupta |
146 |
log.info("resultJson: " + this.resultJson);
|
| 10283 |
amit.gupta |
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
public String getResultJson() {
|
|
|
151 |
return resultJson;
|
|
|
152 |
}
|
| 9103 |
anupam.sin |
153 |
}
|