java - Get request body of my request -


how actual body of request do?

    invocation = webtarget.path("somepath")     .request(mediatype.application_json)     .buildput(entity.entity(account, mediatype.application_json));     log.debug(i.... ); // want log request 

you try wrap outputstream entity. first, using javax.ws.rs.client.clientrequestfilter add custom outputstream clientrequestcontext.

client client = clientbuilder.newclient().register(myloggingfilter.class);  public class myloggingoutputstreamwrapper extends outputstream{   static final logger logger = logger.getlogger(...);   bytearrayoutputstream mybuffer = new ...   private outputstream target;    public myloggingoutputstreamwrapper(outputstream target){ ...    // smarter implement write(byte [], int, int) , call here    public void write(byte [] data){     mybuffer.write(data);     target.write(data);   }    ... // other methods delegate target, other write method    public void close(){     // not sure, if converting buffer string enough. may in different encoding platform default     logger.log(mybuffer.tostring());     target.close();   } }  @provider public class myloggingfilter implements clientrequestfilter{   // implement clientrequestfilter.filter method   @override   public void filter(clientrequestcontext requestcontext) throws ioexception {      requestcontext.setentityoutputstream(new myloggingoutputstreamwrapper(requestcontext.getentityoutputstream()));   } 

i'm not sure @ point outputstream used serialize data. @ moment invoke buildput(), more on fly @ access of webclient.

another approach getting underlying httpclient , registering listener there body.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -