Search code examples
javajerseyjax-rsdropwizardjersey-client

Why does Jersey log a question mark for the entity in my POST request?


I want to access a REST service from my Dropwizard app using a Jersey client. Same technique works fine in different places, but in the present case the service always returns a 500 although I know the URL, etc. are correct. Since I can't modify the service I want to log my requests to verify that they're fine (because I suspect my entity is not properly serialized).

Therefore I registered a logger on the client like this:

restClient.register(new LoggingFilter(Logger.getAnonymousLogger(), true));

But it just never logs my entity. I always get this:

INFO  [2015-07-01 14:12:47,433] unknown.jul.logger: 1 * Sending client request on thread dw-admin-34
1 > POST [My URL which is correct]
1 > Accept: application/json
1 > Accept-Encoding: gzip
1 > Content-Type: application/json
?     

Does it mean it doesn't recognize any entity?

This is how I build the client:

this.restClient = new JerseyClientBuilder(dropwizardEnvironment)
                .using(MyConfiguration.jerseyClient) // new JerseyClientConfiguration() in Dropwizard config class
                .build("my client name");

And here's how I make the request:

Response r = restClient.target(address)
                .request(MediaType.APPLICATION_JSON)
                .acceptEncoding("gzip")
                .post(Entity.json(entity)); //omitting entity. It's very simple and I checked that its values are fine

I'm pretty new to all of this, so probably this is just some stupid noob mistake. Any ideas why the request body is not properly logged?


Solution

  • The problem was that the Jersey client gzipped the body by default. After disabling taht it logs and works like a charm.