On Wednesday 15 September 2010 7:53:56 am [email protected] wrote:
> Hi,
>
> I'd like to have a single Interceptor for in & outbound messages. My goal
> is to add a little statistic info. When was the web service called how
> long did it take to process it and so on.
>
> I read in the archive how to do this:
> http://cxf.547215.n5.nabble.com/Around-interceptor-td560176.html#a560176
If you keep reading down that thread, particularly my responses, you'll note
that I explain that it doesn't work across chains. Since chains (and the
associated out messages) aren't created until they are needed, you really
cannot add them from a single interceptor.
One IDEA would be to add a "getExtraInterceptors()" call onto the exchange.
When a new interceptor chain is setup, any of those interceptors set there
would be added. I'd happily review a patch for that. :-)
Dan
> But this does not seem to work anymore with the current release.
> Because the exchange is null when the message is inbound.
>
> Here a little code to illustrate my problem.
>
>
> private OutboundInterceptor out = new OutboundInterceptor();
>
> public StatisticsInterceptor() {
> super(Phase.READ);
> addAfter(ReadHeadersInterceptor.class.getName());
> }
>
> public void handleMessage(SoapMessage message) throws Fault {
>
> Exchange ex = message.getExchange();
> ex.getOutMessage().getInterceptorChain().add(out);
>
> if (message.getVersion() instanceof Soap11) {
> Map<String, List<String>> headers = CastUtils.cast((Map)
> message.get(Message.PROTOCOL_HEADERS));
>
> if (headers != null) {
> List<String> sa = headers.get("SOAPAction");
> if (sa != null && sa.size() > 0) {
> System.out.println("soap action " + sa.get(0));
> }
> }
> }
> }
>
> static class OutboundInterceptor extends AbstractSoapInterceptor {
> public OutboundInterceptor() {
> super(Phase.MARSHAL_ENDING);
> addAfter(BareOutInterceptor.class.getName());
> }
>
> public void handleMessage(SoapMessage message) throws Fault {
> System.out.println("Outbound Interceptor!");
> }
> }
>
> Cheers,
> Pete
--
Daniel Kulp
[email protected]
http://dankulp.com/blog