添加后HttpSession属性被异常删除

时间:2014-02-28 07:08:14

标签: spring session attributes

*After I add a session attribute using 
    WebUtils.setSessionAttribute(request, VBWebConstants.SESSION_ORDER_BEAN,sellerDetails);

    @RequestMapping(value="/minasidor/step1",method=RequestMethod.GET)
        public ModelAndView step1(HttpServletRequest request,HttpSession session){
            if(logger.isTraceEnabled())logger.trace("VbSellerController ::: step1 ::: start");
            if(logger.isDebugEnabled())logger.debug("[Order Step1] [Start]");
            ModelAndView mav=new ModelAndView("vz-new/mina-sidor/v-orderstep1");
            LoginBean user = (LoginBean) WebUtils.getSessionAttribute(request, VBWebConstants.SESSION_USER);
            mav.addObject("submenu",3);
            if(!checkOrderLifeCycle()){
                mav.addObject("orderNotAllowed", false);
                return mav;
            }
            try{
                String orderValue = "";
                orderValue =  InMemoryCache.getCaProperty(PropertyEnum.MIN_ORDER_VALUE.getDatabasekey());
                int minimumOrderValue = CawebUtil.isInt(orderValue);

            CpSellerDetails sellerDetails=vbOrderService.getStep1Data(user.getGrp_seller_id(),user.getCatalogue_id());
            if(sellerDetails != null){
                mav.addObject("productlist",sellerDetails.getSellerList());
                mav.addObject("totalValue",sellerDetails.getTotalOrderValue());
                mav.addObject("allowedfororder",sellerDetails.getTotalOrderValue() > minimumOrderValue);
                // mav addobject add discount details    Discount Object ArrayList  
                WebUtils.setSessionAttribute(request, VBWebConstants.SESSION_ORDER_STEP_COMPLETED,"step1");
                WebUtils.setSessionAttribute(request, VBWebConstants.SESSION_ORDER_BEAN,sellerDetails);
            }else{
                mav.addObject("allowedfororder",false);
                WebUtils.setSessionAttribute(request, VBWebConstants.SESSION_ORDER_STEP_COMPLETED,null);
            }


        }catch(DataNotFoundException e){
            logger.trace("Exception in retrieving data for step1",e);
            if(logger.isDebugEnabled())logger.debug("[Order Step1 Exception]",e);
        }
        if(logger.isTraceEnabled())logger.trace("VbSellerController ::: step1 ::: end");
        if(logger.isDebugEnabled())logger.debug("[Order Step1] [end]");
        return mav;
    }
Within this step1 method the VBWebConstants.SESSION_ORDER_BEAN session attribute is getting removed instantly after the step1() method finishes executing where as the other session attributes remains the same.When i debug the below Http Listener class 
    public class MyHttpSessionListener implements HttpSessionListener,HttpSessionAttributeListener {



    public static final Logger logger = Logger.getLogger(MyHttpSessionListener.class);
    public void sessionCreated(HttpSessionEvent se) {
        //String ipAddr = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest().getRemoteAddr();
        HttpSession session = se.getSession();

        if(logger.isDebugEnabled()){
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.append("\n").append("-----------     Session Created    -------------- ");
            Enumeration<String> sessionAttrs = session.getAttributeNames();
            while (sessionAttrs.hasMoreElements()) {
                String name =  sessionAttrs.nextElement();
                sbuilder.append("\n").append(" session created ").append(name); 
            }
            sbuilder.append("\n").append(" session  created time "+ CawebUtil.getTimeStampInString(new Timestamp(session.getCreationTime())));
            sbuilder.append("\n").append("---------------------------------------------------- ").append("\n");
            logger.debug(sbuilder.toString());
        }
    }

    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        if(logger.isDebugEnabled()){
            try{
                String ipAddr = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest().getRemoteAddr();
                logger.debug(" session destroyed " +ipAddr);
            }catch (Exception e) {              
            }
        }

    }
    public void attributeAdded(HttpSessionBindingEvent se) {
        String ipAddr = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest().getRemoteAddr();
        HttpSession session = se.getSession();
        if(logger.isDebugEnabled()){
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.append("\n").append("-----------     Attribute added   -------------- from ").append(ipAddr);
            sbuilder.append("\n").append(" session  max inactive time "+ session.getMaxInactiveInterval());
            sbuilder.append("\n").append(" session  id "+ session.getId());
            sbuilder.append("\n").append(" session  attribute added "+ se.getName()).append("  =  ").append(se.getValue());
            sbuilder.append("\n").append(" session  created time "+ CawebUtil.getTimeStampInString(new Timestamp(session.getCreationTime())));
        }

    }
    public void attributeRemoved(HttpSessionBindingEvent se) {
        if(logger.isDebugEnabled() ){
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.append("\n").append("-----------     Attribute removed   -------------- from ");//.append(ipAddr);
            sbuilder.append("\n").append(" session  attribute removed "+ se.getName()).append("  =  ").append(se.getValue());

        }
    }
    public void attributeReplaced(HttpSessionBindingEvent se) {
        if(logger.isDebugEnabled()){
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.append("\n").append("-----------     Attribute replaced   -------------- from ");//.append(ipAddr);
            sbuilder.append("\n").append(" session  attribute "+ se.getName()).append("  =  ").append(se.getValue());
        }
    }
    }
I found that the session attribute is getting removed.Checked through the entire code I couldn't find what's the reason...???

这是我试图添加到会话中的CPSellerDetails类还有其他2个会话属性,其中一个是字符串对象,另一个是bean。它是类的大小,是会话属性的原因异常删除

public class CpSellerDetails implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = -4627284179051380310L;
    private List<SellerProduct>  sellerList ;
    private float totalOrderValue ;
    private VbCpInfoBean cpinfoBean;
    private Integer orderno;
    private float invoiceAmount;
    private Date orderedDate;
    private ArrayList<DiscountVO> discounts;
    private Address billingInfo;

    public VbCpInfoBean getCpInfoBean() {
        return cpinfoBean;
    }
    public void setCpInfoBean(VbCpInfoBean infoBean) {
        this.cpinfoBean = infoBean;
    }
    public List<SellerProduct> getSellerList() {
        return sellerList;
    }
    public void setSellerList(List<SellerProduct> sellerList) {
        this.sellerList = sellerList;
    }
    public float getTotalOrderValue() {
        return totalOrderValue;
    }
    public void setTotalOrderValue(float totalOrderValue) {
        this.totalOrderValue = totalOrderValue;
    }
    public float getInvoiceAmount() {
        return invoiceAmount;
    }
    public void setInvoiceAmount(float invoiceAmount) {
        this.invoiceAmount = invoiceAmount;
    }
    public Integer getOrderno() {
        return orderno;
    }
    public void setOrderno(Integer orderno) {
        this.orderno = orderno;
    }
    public Date getOrderedDate() {
        return orderedDate;
    }
    public void setOrderedDate(Date orderedDate) {
        this.orderedDate = orderedDate;
    }
    public ArrayList<DiscountVO> getDiscounts() {
        return discounts;
    }
    public void setDiscounts(ArrayList<DiscountVO> discounts) {
        this.discounts = discounts;
    }

    public Address getBillingInfo() {
        return billingInfo;
    }
    public void setBillingInfo(Address billingInfo) {
        this.billingInfo = billingInfo;
    }


}*

0 个答案:

没有答案