java - Is there a way to obtain the request information from javax.ws.rs.Client in Jersey? -


i trying make standard in logging projects build on top of jersey, , want provide simple way log request information , response in case exception occurs. following code illustrates idea :

    client client = null;     response response = null;     try {         client = clientbuilder.newclient();         response = client.target("<url>")                 .request(mediatype.application_json)                 .post(entity);     } catch( exception ex) {         //send information exception mapping json log         throw new serviceexception( client,response );     } 

the problem how can obtain following in serviceexception class:

    string url = client.geturi().tostring(); //only 1 using webtarget     multivaluedmap<string, string> headers = client.getheaders();     string body = client.getentity();     multivaluedmap<string, string> queryparams = client.getqueryparams();         string method = client.getmethod(); 

i tried accessing webtarget without luck.

thanks in advance!

jersey has logging support both client side , server side. documentation shows how register client. can registered webttarget.

if not satisfied results, , want implement own, implement same way jersey does: combination of writerinterceptor log request entity stream1 , client(request|response)filter2 other parts of request , response (like headers , request line).

you can @ source clientloggingfilter , logginginterceptor ideas implementation.


1 - needs use interceptor, instead of using filter everything, because filter give pre-seriazlied object, can anything, difficult log. it's easier generic logging input stream.

2 - see filters , interceptors


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -