Search code examples
web-servicescxfjax-wsws-securitywss4j

Sharing data between CXF interceptor and webservice


I'm using security interceptors with Apache CXF WSS4JInInterceptor.

Is there any way to pass data from interceptor to webservice?

I've been searching for that in WebServiceContext but I can't find it.


Solution

  • You can use the CXF Exchange Map to store arbitrary key/value pairs. The Exchange is available to both input and output messages. In your interceptor, add the object to the Exchange, e.g.

    Object value = ...;
    message.getExchange().put("key", value);
    

    Within your service, you can use PhaseInterceptorChain.getCurrentMessage() to access the exchange and retrieve the object, e.g.

    Object value = PhaseInterceptorChain.getCurrentMessage().getExchange().get("key");