Jersey: Print the actual request

后端 未结 4 652
-上瘾入骨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条回答
  •  -上瘾入骨i
    2020-11-28 23:53

    @ivan.cikic's answer is for Jersey 1.x. Here's how you do it in Jersey 2.x:

    import org.glassfish.jersey.client.ClientConfig;
    import org.glassfish.jersey.filter.LoggingFilter;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import javax.ws.rs.client.Client;
    import javax.ws.rs.client.ClientBuilder;
    import javax.ws.rs.client.Entity;
    import javax.ws.rs.client.WebTarget;
    import javax.ws.rs.core.Form;
    import javax.ws.rs.core.MediaType;
    
    ...
    
            ClientConfig config = new ClientConfig();
    
            Client client = ClientBuilder.newClient(config);
            client.register(new LoggingFilter());
    

    This is irrelevant but I just have to complain: The new LoggingFilter is really annoying because it forces you to use Java Util Logging. It would be better if it gave me control over the logger. Seems like a step backwards in design.

提交回复
热议问题