Jersey: Print the actual request

后端 未结 4 664
-上瘾入骨i
-上瘾入骨i 2020-11-28 22:50

How can I view the actual request that Jersey generates and sends to the server? I am having issues with a particular request and the fellow running the webserver asked to

4条回答
  •  盖世英雄少女心
    2020-11-28 23:31

    Since Jersey 2.23, there's a LoggingFeature you could use. The following is a bit simplified example, please note that you can register the feature on WebTarget as well.

    Logger logger = Logger.getLogger(getClass().getName());
    
    Feature feature = new LoggingFeature(logger, Level.INFO, null, null);
    
    Client client = ClientBuilder.newBuilder()
            .register(feature)
            .build();
    
    Response response = client.target("https://www.google.com")
            .queryParam("q", "Hello, World!")
            .request().get();
    

    JavaDoc of LoggingFeature says that the request "and/or" the response is logged lol. On my machine, both are logged.

提交回复
热议问题