如何在服务器上获取球衣日志?

2022-01-21 00:00:00 java jersey

我将球衣用于 REST WS.如何在服务器端启用球衣日志?

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

长篇大论:我得到一个客户端异常 - 但我在 tomcat 日志中看不到任何内容[它甚至没有达到我的方法].由于堆栈跟踪说toReturnValue"它确实从服务器得到了一些东西.但我不知道服务器说了什么.

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)

推荐答案

如果要在服务端开启日志,需要注册LoggingFilter Jersey 过滤器(在容器端).

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

此过滤器将记录请求/响应标头和实体.

这是您需要添加到 ResourceConfig 类的内容:

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());

相关文章