> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Tuesday, February 22, 2011 2:53 AM
> To: [email protected]
> Subject: Re: Dynamically turning on request/response logging in jax-rs
> 
> 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:
> 
> 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.

Is it possible to remove the interceptors dynamically also?  I'd have to be 
able to turn logging on and off dynamically.

> 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.

What would be the tradeoffs of these two approaches?

Reply via email to