1

I am using jersey rest api (JAX-RS) of 2.25.1 version. I tried to use LoggingFeature class at server side and as well as client side.

Client side code:

public static void getOperation() {

            ClientConfig config = new ClientConfig();
            config.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY);
            config.register(new LoggingFeature(logger, LoggingFeature.Verbosity.PAYLOAD_ANY));
            Client client = ClientBuilder.newClient(config);
            client.register(ClientEmpReqFilter.class);
            client.register(ClientEmpResFilter.class);

            WebTarget target = client.target("http://localhost:8080").path("restappln/rest/entity");

            String str = target.request(MediaType.APPLICATION_JSON).get(String.class);

            System.out.println(str);
        }

and Server-side code is :

@ApplicationPath("/rest")
public class MyApplication extends ResourceConfig {
    public MyApplication() {
        packages("<package name>");
        register(LoggingFeature.class);
    }
}

I am not able to get logging. I am passing instance of java.util.Logger to the contructor of client config.

config.register(new LoggingFeature(logger, LoggingFeature.Verbosity.PAYLOAD_ANY));
  • Can you show the code for the logger from config.register(new LoggingFeature(logger...? And stack trace from exception would be nice. – FrAn Feb 01 '17 at 06:43
  • Logger logger= Logger.getLogger(); It is simple logger from util package of java. – Himanshu Upadhyay Feb 01 '17 at 08:08
  • You should remove the line that gives the compilation error. As in Jersey documentation if you want to register() your config Class should be type of ResourceConfig not ClientConfig. More info: https://jersey.java.net/documentation/latest/logging_chapter.html – FrAn Feb 01 '17 at 08:46
  • I have posted the solution on a similar question, link: https://stackoverflow.com/questions/40171273/how-to-print-server-responses-using-loggingfeature-in-dropwizard-1-0-2/51443054#51443054 – Vikram Singh Choudhary Jul 20 '18 at 13:04

0 Answers0