How to get jersey logs on server?

I use jersey for REST WS. How to enable server side jersey logs?

Long story: I get an exception for clients - but I don't see anything in tomcat logs [It doesn't even reach my method]. Since the stack trace says "toReturnValue", it really got something from the server. But I do not know what the server said.

Exception in thread "main" java.lang.IllegalArgumentException: source parameter must not be null at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:98) at com.sun.xml.internal.ws.message.AbstractMessageImpl.readPayloadAsJAXB(AbstractMessageImpl.java:100) **at com.sun.xml.internal.ws.client.dispatch.JAXBDispatch.toReturnValue(JAXBDispatch.java:74)** at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:191) at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:195) 
+32
java jersey
Feb 25 '10 at 8:10
source share
5 answers

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

This filter will record headers and request / response objects .

Here is what you need to add to the ResourceConfig class:

 @ApplicationPath("/") public class MyApplication extends ResourceConfig { public MyApplication() { // Resources. packages(MyResource.class.getPackage().getName()); register(LoggingFilter.class); } } 

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

 Client client = Client.create(); client.addFilter(new LoggingFilter()); 
+54
Mar 02 2018-10-10T00:
source share

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

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

and server side:

 ResourceConfig config = new ResourceConfig(HelloWorldResource.class); config.register(LoggingFeature.class); 
+9
Oct 21 '16 at 21:50
source share

For Jersey 1.2, add the following entry in web.xml inside the servlet tag:

  <init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value> </init-param> 
+6
Sep 07 '15 at 10:53 on
source share

Jersey 2.0 uses org.glassfish.jersey.filter.LoggingFilter
You can connect it using web.xml

 <!-- Register my custom provider (not needed if it in my.package) AND LoggingFilter. --> <init-param> <param-name>jersey.config.server.provider.classnames</param-name> <param-value>org.glassfish.jersey.filter.LoggingFilter</param-value> </init-param> 

More detailed explanations can be found here.

UPD:

After version 2.23, LoggingFilter deprecated and LoggingFeature should be used. More information can be found in the official documentation.

+5
Oct 12 '14 at 6:57
source share

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

This exception seems to indicate the Unmarshalling JAXB step. Obviously, you received the XML from your REST API, but you will not get what you expect.

Perhaps the XSD you use for sorting / disassembling is outdated or just plain wrong.
Perhaps you are trying to get the wrong object from the response.

Try these steps and give us more information about your problem:

Get XML from response

Using a REST client, for example, a REST client is 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); logger.log(myResource); 

Validate this XML with the XSD you are using

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

+3
Feb 26 '10 at 12:45
source share



All Articles