How do you get logging from the CXF Rest Client?

后端 未结 2 1361
时光说笑
时光说笑 2021-01-20 02:03

This took me quite a long time to figure out. I\'m asking this question so I can answer it for others:

How do you get useful logging info from the CXF Rest Client?

相关标签:
2条回答
  • 2021-01-20 02:13

    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());
    
    0 讨论(0)
  • 2021-01-20 02:34

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

    0 讨论(0)
提交回复
热议问题