简体   繁体   中英

How to get session from cxf out interceptor

I have a cxf "in interceptor" bound to Receive phase that store data into session.

MyCxfInInterceptor (In interceptor)

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.
      }
    }

I want to retrieve theses data into my "out interceptor". How can i do it ?

I don't know how to retrieve session from HttpServletResponse. Maybe the session is not available anymore. Is there any other way to store & retrieve data?

Spring could be helpful?

You can use the Exchange , to exchange the data between in and out interceptor

In interceptor

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

Out interceptor

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM