You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Pe...@gmx.net on 2010/09/15 13:53:56 UTC

Single Interceptor for In/Outbound Message

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

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
-- 
GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 Euro/mtl.!*
http://portal.gmx.net/de/go/dsl

Re: Single Interceptor for In/Outbound Message

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday 15 September 2010 7:53:56 am Peter.Neu@gmx.net 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
dkulp@apache.org
http://dankulp.com/blog