本文介绍了如何通过CXF拦截器使会话无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Cxf Web服务的新手,但所提供的信息不知所措。我写了一个cxf Interceptor(cxf:outInterceptors),它扩展了AbstractPhaseInterceptor。服务执行后,我试图使当前会话无效。我的问题是:
I am new to Cxf webservice and bit overwhelmed by information provided. I have written a cxf Interceptor(cxf:outInterceptors) which extends AbstractPhaseInterceptor. I am trying to invalidate the current session after service executes. My issues are:
- 我是否在构造函数中使用了正确的相位? (阶段发送)
- 如何从消息中获取会话信息?现在,对于下面的方法,请求实例返回null。
还是有更好的方法呢?
public ServiceSessionInvalidator() {
super(Phase.SEND);
}
@Override
public void handleMessage(Message message) throws Fault {
System.out.println("Hitting Handler");
HttpSession session;
HttpServletRequest req = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
session = (req != null)? req.getSession(): null;
if(req == null ){
System.out.println("Request is Null");
}
}
输出:
16 Jun 2015 13:35:40 INFO - Inbound Message
----------------------------
ID: 1
Address: http://localhost:8090/services/VariableService/variableService/
Http-Method: GET
---
---
Hitting Handler
Request is Null
16 Jun 2015 13:35:41 INFO - Outbound Message
---------------------------
ID: 1
Response-Code: 200
推荐答案
@Resource
WebServiceContext wsContext;
@Context
private HttpServletRequest request;
private HttpServletRequest invalidateSession() {
MessageContext mc = wsContext.getMessageContext();
HttpServletRequest req;
if (mc != null) {
req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
} else {
req = request;
}
req.getSession().invalidate();
}
这篇关于如何通过CXF拦截器使会话无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!