zoukankan      html  css  js  c++  java
  • The FlexSession is invalid问题

    package com.cmbj.soa.servicemonitor.view.service.impl;
    
    import java.util.Enumeration;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import flex.messaging.HttpFlexSession;
    import flex.messaging.MessageBrokerServlet;
    
    public class KMessageBrokerServlet extends MessageBrokerServlet {
    	@Override
    	public void service(HttpServletRequest req, HttpServletResponse res) { 
    		HttpSession httpSession = req.getSession(true);
    		HttpFlexSession flexSession = (HttpFlexSession)httpSession.getAttribute("__flexSession");
    		if( flexSession != null && !flexSession.isValid()){  
    			httpSession.removeAttribute("__flexSession");  
    		} 
    //		HttpSession httpSession = req.getSession(true);
    //		
    //		Enumeration<String> names = httpSession.getAttributeNames();
    //		String name = null;
    //		for (;  names.hasMoreElements();) {
    //			name = names.nextElement();
    //			if (httpSession.getAttribute(name) instanceof HttpFlexSession) {
    //				HttpFlexSession flexSession = (HttpFlexSession) httpSession.getAttribute(name);
    //				if(null != flexSession && !flexSession.isValid()){
    //					httpSession.setAttribute(name,null);
    //					httpSession.removeAttribute(name);
    //				}
    //				System.out.println("HttpFlexSession_name is " + name);
    //			}
    //		}
    		super.service(req, res);
    	}
    }
    


    重写MessageBrokerServlet的service方法,因为异常的源头来自该servlet用了一个invalid的HttpFlexSession去获取Principal,所以只要再service方法之前先判断下当前的HttpFlexSession是否已经无效,无效的话我们就从当前的HttpSession中移除这个无效的HttpFlexSession即可。这样,就能保证MessageBrokerServlet中所用的HttpFlexSession一定是有效的

  • 相关阅读:
    Jedis 源代码阅读一 —— Jedis
    Java中的${pageContext.request.contextPath}
    VMware Workstation 12 安装mac os x 10.11
    机器学习——朴素贝叶斯分类器
    Codeforces 138C(区间更新+离散化)
    Threejs 官网
    深刻理解Nginx之Nginx完整安装
    Apache + Tomcat 负载均衡 session复制
    小P寻宝记——好基友一起走
    C++数值类型极限值的获取
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3196670.html
Copyright © 2011-2022 走看看