1

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.

rvillablanca
  • 1,606
  • 3
  • 21
  • 34
  • Are you looking to pass arbitrary data between your own extension of WSS4JInInterceptor and your service implementation? – Patrick Oct 06 '14 at 16:36
  • My extension is a custom crypto instance that calls store procedures to get certificates from database, etc. Some data from SP must be available in my webservice implementation – rvillablanca Oct 06 '14 at 21:18

1 Answers1

4

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");
Patrick
  • 2,102
  • 15
  • 11
  • This response is correct, but I wrote the wrong question. Sorry for that I mistook the concepts. I need pass data from org.apache.ws.security.components.crypto.Crypto to webservice implementation. I will ask again. Thanks @Patrick – rvillablanca Oct 06 '14 at 22:20
  • Is your class implementing Crypto inside CXF? As long as the CXF message has been created, you should be able to add things to the exchange with PhaseInterceptorChain.getCurrentMessage().getExchange().put(). Otherwise, a ThreadLocal might be another option. – Patrick Oct 06 '14 at 22:50
  • oh, you are right, I will try with PhaseInterceptorChain. Thanks ;) – rvillablanca Oct 06 '14 at 23:16
  • I was able to access this context in a class that implements javax.security.auth.callback.Callback and was part of a wss4jInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) and to share data between it and a spring interceptor class that implements org.aopalliance.intercept.MethodInterceptor.MethodInterceptor. It works perfectly! – GreenieMeanie Jun 27 '17 at 14:21