Subversion Repositories SmartDukaan

Rev

Rev 21626 | Rev 22093 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21626 Rev 22069
Line 1... Line 1...
1
package com.spice.profitmandi.web.util;
1
package com.spice.profitmandi.web.util;
2
 
2
 
3
import javax.servlet.http.Cookie;
3
import javax.servlet.http.Cookie;
4
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletRequest;
-
 
5
import javax.servlet.http.HttpServletResponse;
5
 
6
 
6
import org.slf4j.Logger;
7
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8
import org.slf4j.LoggerFactory;
8
import org.springframework.stereotype.Component;
9
import org.springframework.stereotype.Component;
9
 
10
 
10
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
11
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
11
import com.spice.profitmandi.common.model.ProfitMandiConstants;
12
import com.spice.profitmandi.common.model.ProfitMandiConstants;
12
import com.spice.profitmandi.web.model.FofoDetails;
13
import com.spice.profitmandi.web.model.FofoDetails;
13
 
14
 
14
@Component
15
@Component
15
public class CookiesFetcher {
16
public class CookiesProcessor {
16
	
17
	
17
	private static final Logger LOGGER = LoggerFactory.getLogger(CookiesFetcher.class);
18
	private static final Logger LOGGER = LoggerFactory.getLogger(CookiesProcessor.class);
18
	
19
	
19
	public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
20
	public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
20
		Cookie[] cookies = request.getCookies();
21
		Cookie[] cookies = request.getCookies();
21
		if (cookies == null){
22
		if (cookies == null){
22
			throw new ProfitMandiBusinessException("", "", "");
23
			throw new ProfitMandiBusinessException("", "", "");
23
		}
24
		}
24
		String fofoIdFound = null, emailIdFound = null;
25
		String fofoIdFound = null, emailIdFound = null;
25
		for(Cookie cookie : cookies){
26
		for(Cookie cookie : cookies){
-
 
27
			LOGGER.info("Requested Cookie {}", cookie.getName());
26
			if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
28
			if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
27
				fofoIdFound = cookie.getValue();
29
				fofoIdFound = cookie.getValue();
28
			}
30
			}
29
			if(cookie.getName().equals(ProfitMandiConstants.EMAIL_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
31
			if(cookie.getName().equals(ProfitMandiConstants.EMAIL_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
30
				emailIdFound = cookie.getValue();
32
				emailIdFound = cookie.getValue();
Line 43... Line 45...
43
			fofoDetails.setEmailId(emailIdFound);
45
			fofoDetails.setEmailId(emailIdFound);
44
			return fofoDetails;
46
			return fofoDetails;
45
		}
47
		}
46
		
48
		
47
	}
49
	}
-
 
50
	
-
 
51
	public void removeCookies(HttpServletRequest request, HttpServletResponse response) throws ProfitMandiBusinessException{
-
 
52
		Cookie[] cookies = request.getCookies();
-
 
53
		if (cookies == null){
-
 
54
			throw new ProfitMandiBusinessException("", "", "");
-
 
55
		}
-
 
56
		
-
 
57
		Cookie cookieFofoId = new Cookie(ProfitMandiConstants.FOFO_ID, "");
-
 
58
		Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, "");
-
 
59
		cookieFofoId.setMaxAge(0);
-
 
60
		cookieEmailId.setMaxAge(0);
-
 
61
		response.addCookie(cookieFofoId);
-
 
62
		response.addCookie(cookieEmailId);
-
 
63
	}
48
}
64
}