[ACCEPTED]-How to get jersey logs at server?-jersey

Accepted answer
Score: 61

If you want to turn on logging on the server 5 side, you need to register the LoggingFilter Jersey filter (on the 4 container side).

This filter will log request/response headers and entities.

Here's 3 what you need to add to your ResourceConfig class:

public class MyApplication extends ResourceConfig {

    public MyApplication() {
        // Resources.


Note 2 that the same filter also works on the client 1 side.

Client client = Client.create();
client.addFilter(new LoggingFilter());
Score: 33

Jersey 2 has deprecated LoggingFilter and you now need 3 to use LoggingFeature. In order to use it with a client 2 you can use the following snipette:

this.client = ClientBuilder
            .property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY)
            .property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_CLIENT, "WARNING")

and 1 on the server side:

ResourceConfig config = new ResourceConfig(HelloWorldResource.class);
Score: 10

Jersey 2.0 uses org.glassfish.jersey.filter.LoggingFilter
You can connect it with 3 help of web.xml

<!-- Register my custom provider (not needed if it's in my.package) AND LoggingFilter. -->

More explanations can be found 2 here


After version 2.23 LoggingFilter is deprecated and LoggingFeature should 1 be used. More info can be found in official documentation

Score: 6

For Jersey 1.2 add the following entry into 1 web.xml inside the servlet tag:

Score: 3

Could you show us your client code and tell 12 us about the request as well?

This exception 11 seems to point at the JAXB unmarshalling 10 step. Apparently you received some XML from 9 your REST API, but you don't get what you're 8 waiting for.

Maybe the XSD you're using for 7 marshalling/unmarshalling is outdated or 6 just plain wrong.
Maybe you're trying to 5 get the wrong entity from the response.

Try 4 these steps and give us some more details 3 about your problem:

Get the XML from the response

Using a REST client like 2 Client REST simple (a chrome extension), or your code:

Builder builder = webResource.path("/yourapi/").accept("application/xml");

// get the client response
ClientResponse response = builder.get(ClientResponse.class);

// log the HTTP Status
logger.log("HTTP Status: " + response.getStatus());

// bypass the jaxb step and get the full response
// MyResource myResource = response.getEntity(MyResource.class);
String myResource = response.getEntity(String.class);

Validate this XML with the XSD you're using

This 1 test should fail (if I'm right).

More Related questions