logging - How to log request body in JAX-RS client -


i need see request body client jax-rs request in order verify serialization works correct , reuse request test clients postman.

i know it's possible activate logging jersey using example resource.addfilter(new com.sun.jersey.api.client.filter.loggingfilter());. however, don't use jersey or resteasy implementation directly, abstracted via jax-rs api:

final webtarget target =          clientbuilder.newbuilder().build().target("http://localhost:8080"); 

how can enable logging here?


result

the answer @peeskillet + this snippet.

however close() method snippet not being invoked jax-rs implementation (org.jboss.resteasy:resteasy-client-3.0.11.final in case).

jax-rs 2.0 (which looks you're using), has clientrequestfilter. can register client or webtarget. filter method, can entity, , logging

public class loggingfilter implements clientrequestfilter {     private static final logger log = logger.getlogger(loggingfilter.class.getname());      @override     public void filter(clientrequestcontext requestcontext) throws ioexception {         log.log(level.info, requestcontext.getentity().tostring());     } }  [...]  client client = clientbuilder.newclient(); client.register(new loggingfilter()); 

also clientrequestcontext api other goodies might find interesting.

update

see also:


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -