Subversion Repositories SmartDukaan

Rev

Rev 2145 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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