Subversion Repositories SmartDukaan

Rev

Rev 21583 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.web.model.FofoDetails;

@Component
public class CookiesFetcher {
        
        private static final Logger LOGGER = LoggerFactory.getLogger(CookiesFetcher.class);
        
        public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
                Cookie[] cookies = request.getCookies();
                if(cookies == null || cookies.length != 2 || !(cookies[0].getName().equals(ProfitMandiConstants.FOFO_ID) && cookies[1].getName().equals(ProfitMandiConstants.EMAIL_ID))){
                        LOGGER.error("Requested session is not valid");
                        throw new ProfitMandiBusinessException("", "", "");
                }else{
                        FofoDetails fofoDetails = new FofoDetails();
                        fofoDetails.setFofoId(Integer.parseInt(cookies[0].getValue()));
                        fofoDetails.setEmailId(cookies[1].getValue());
                        return fofoDetails;
                }
        }
}