How do you get logging from the CXF Rest Client?

给你一囗甜甜゛ 提交于 2019-12-02 01:50:40
Daniel Kaplan

Here's how you do it with CXF:

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.WebClient;
import org.json.JSONException;
import org.json.JSONObject;
...
    WebClient client = WebClient.create(endPoint, providers).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON);
    ClientConfiguration config = WebClient.getConfig(client);
    config.getInInterceptors().add(new LoggingInInterceptor());
    config.getOutInterceptors().add(new LoggingOutInterceptor());

Using the JAX-RS 2.0 client from CXF 3.1.x I am having some trouble getting the LoggingInInterceptor and LoggingOutInterceptor to work. I changed to use the LoggingFeature as described at http://cxf.apache.org/docs/message-logging.html and it worked first try:

Client client = ClientBuilder.newBuilder().register(LoggingFeature.class).build()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!