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一定是有效的

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值