2

I have been working with Glassfish/Jackson for over a year and I always have this problem when introducing a new endpoint implementation: when the endpoint is not reached and I want to understand why, the only hints I have to go on are the returned request, since the execution doesn't reach the desired endpoint or resource (routing/mapping error).

I want to intercept the Jersey mapping/routing execution before reaching endpoints/resources, with the "raw" request, so that I can better understand resource/endpoint mapping and routing problems.

JoseHdez_2
  • 4,040
  • 6
  • 27
  • 44

1 Answers1

2

This answer to a different question, by @xeye, solved this problem for me:

Create a filter that implements ContainerRequestFilter, and override its filter method. This will be where we can intercept all requests for debugging.

// Executed whenever a request is sent to the API server.
// Useful for debugging errors that don't reach the desired endpoint implementation.
@Provider
@Priority(value = 0)
public class MyFilter implements ContainerRequestFilter {
    @Context // request scoped proxy
    private ResourceInfo resourceInfo;

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        try {
            // put a breakpoint or log desired attributes of requestContext here.
        } catch (Exception e) {
            // ignore
        }
   }
}

Then register this new class in your ConfigResource implementation.

public class MyResourceConfig extends ResourceConfig {
    public MyResourceConfig(){
        register(MyFilter.class);
        // ...
    }

(It's OK to Ask and Answer Your Own Questions)

JoseHdez_2
  • 4,040
  • 6
  • 27
  • 44