Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get jersey logs at server?

Tags:

java

jersey

I am using jersey for a REST WS. How do I enable jersey logs at server side?

Long story: I get a clientside exception - but I don't see anything in tomcat logs [It doesn't even reach my method]. Since the stack trace is saying "toReturnValue" it did get something from server. But I don't 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) 
like image 980
Fakrudeen Avatar asked Feb 25 '10 08:02

Fakrudeen


2 Answers

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

This filter will log request/response headers and entities.

Here's what you need to add to your 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()); 
like image 92
Brian Clozel Avatar answered Oct 05 '22 22:10

Brian Clozel


Jersey 2 has deprecated LoggingFilter and you now need to use LoggingFeature. In order 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 on the server side:

ResourceConfig config = new ResourceConfig(HelloWorldResource.class); config.register(LoggingFeature.class); 
like image 23
Art Avatar answered Oct 05 '22 21:10

Art