如何从cxf out interceptor获取会话

时间:2017-02-13 16:58:22

标签: java spring session cxf

我在拦截器中有一个cxf""绑定到接收阶段,将数据存储到会话中。

MyCxfInInterceptor(在拦截器中)

public class MyCxfInInterceptor extends AbstractSoapInterceptor {
    public MyCxfInInterceptor() {
        super(Phase.RECEIVE);
    }
    public void handleMessage(SoapMessage message) throws Fault {
        HttpServletRequest request (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
        HttpSession session = request.getSession(true);

        session.setAttribute("foo","bar");
    }
}

MyCxfOutInterceptor(Out interceptor)

public class MyCxfOutInterceptor extends AbstractSoapInterceptor {
      public MyCxfOutInterceptor() {
        super(Phase.SEND);
      }


      public void handleMessage(SoapMessage message) throws Fault {
        //TODO Retrieve data from session.
      }
    }

我想将这些数据检索到我的" out拦截器"。我该怎么办?

我不知道如何从HttpServletResponse检索会话。也许会议不再可用。有没有其他方式存储&检索数据?

春天可能有帮助吗?

1 个答案:

答案 0 :(得分:1)

您可以使用Exchange在进出拦截器之间交换数据

拦截器

public void handleMessage(SoapMessage message) throws Fault {
  message.getExchange().put("foo","bar");
}

拦截器

public void handleMessage(SoapMessage message) throws Fault {
  Object obj = message.getExchange().get("foo");
 }