5

I am using jersey to generate http requests and I would like to be able to see the request before it is sent (for debugging purposes).

For example:

WebResource resource = client.resource(url);
resource.header("aa", "bb");
resource.getHeaders(); // Error: how can I do it?

thanks

Shai Ben-Yehuda
  • 134
  • 1
  • 2
  • 8
  • possible duplicate of [Jersey: Print the actual request](http://stackoverflow.com/questions/6860661/jersey-print-the-actual-request) – mateuscb Jul 29 '15 at 16:11

2 Answers2

9

You can use LoggingFilter, as shown here

Community
  • 1
  • 1
ivan.cikic
  • 1,827
  • 1
  • 14
  • 7
-2

You need to add init-params and then implement ContainerRequestFilter

Put it in your web.xml Please note that com.az.jersey.server.AuthFilter is your class that has implemented mentioned above interface.

<init-param>
            <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
            <param-value>com.sun.jersey.api.container.filter.LoggingFilter;com.az.jersey.server.AuthFilter</param-value>
        </init-param>



public class AuthFilter implements ContainerRequestFilter {
    /**
     * Apply the filter : check input request, validate or not with user auth
     * 
     * @param containerRequest
     *            The request from Tomcat server
     */
    @Override
    public ContainerRequest filter(ContainerRequest containerRequest) throws WebApplicationException {
        //GET, POST, PUT, DELETE, ...
        String method = containerRequest.getMethod();
        // myresource/get/56bCA for example
        String path = containerRequest.getPath(true);         

        return containerRequest;
    }
AZ_
  • 21,688
  • 25
  • 143
  • 191