On Tuesday 22 February 2011 5:52:39 AM Sergey Beryozkin wrote:
> Hi
> 
> On Mon, Feb 21, 2011 at 7:45 PM, KARR, DAVID (ATTSI) <[email protected]> wrote:
> > I need to investigate how I can dynamically turn on request/response
> > logging in JAX-RS.  The doc page on logging appears to assume we're
> > doing JAX-WS.  It appears I can turn on logging statically by adding the
> > "cxf:logging" element to the "jaxrs:features" element, but that's not,
> > what I want.
> 
> You may want to extend CXF LoggingInInterceptor and in its
> handleMessage(Message inMessage) method decide whether to delegate to
> the superclass or not.
> The message properties such as Message.HTTP_REQUEST_METHOD,
> Message.PROTOCOL_HEADERS, Message.REQUEST_URI, Message.QUERY_STRING
> can help...
> 
> Then you can register this custom LoggingInInterceptor in the
> jaxrs:inInterceptors.
> 
> I'm not sure though if you can dynamically add an outbound
> LoggingOutInterceptor dynamically from the in custon interceptor, may
> be the following will work:

You can.  I just discovered this yesterday while looking at some stuff with 
Christan.  :-)

You can do:

message.put(Message.OUT_INTERCEPTORS,
     Collections.singletonList(new LoggingOutInterceptor()));

and it would add that to the out chain when it's calculated.

Dan


 
> if (loggingHasToBeEnabled) {
> 
>     // add LoggingOutInterceptor to the outbound message
> 
>     Message outMessage = new MessageImpl();
>     outMessage.getInterceptorChain().add(new LoggingOutInterceptor());
>     Exchange exchange = inMessage.getExchange();
>     exchange.setOutMessage(outMessage);
>     outMessage.setExchange(exchange);
> 
>     // finally, delegate to the super class for the inbound request be
> logged: super.handleMessage(inMessage);
> }
> 
> This may work - if not then you can create a custom
> LoggingOutInterceptor subclass, register it in the
> jaxrs:outInterceptors, and in its handleMessage(Message outMessage)
> check the property on the outMessage.getExchange() which your custom
> LogginInInterceptor will set if needed on the inMessage.getExchange()
> and if this enabling property has been set then delegate to the
> superclass.
> 
> Alternatively to using the pair of logging interceptors, you may want
> to experiment with PersistInInterceptor and PersistOutInterceptor in
> the rt/management module. The PersistOutInterceptor will provide the
> Exchange details to the injected handler.
> 
> 
> 
> Cheers, Sergey

-- 
Daniel Kulp
[email protected]
http://dankulp.com/blog
Talend - http://www.talend.com

Reply via email to