VishalDevgire
VishalDevgire

Reputation: 4268

PreProcessInterceptor for jersey

RestEasy provides a PreProcessInterceptor using which you can intercept incoming request to your web-service and then you can check things like which method will be invoked in-response to this request accordingly you can decide to let it pass or return a response.

I'm developing a web service using jersey is there any similar class or something in jersey using which i can intercept incoming requests and check details?

Currently i'm using a Filter to capture the requests and do stuff but i want a better approach.

Upvotes: 1

Views: 927

Answers (2)

Michal Gajdos
Michal Gajdos

Reputation: 10379

In Jersey 2.x you can retrieve resource method via:

  • ContainerRequestContext which is passed into the filters ContainerRequestFilter#filter(ContainerRequestContext) method:

    ((ExtendedUriInfo) containerRequestContext.getUriInfo()).getMatchedResourceMethod()
    
  • injecting ExtendedUriInfo into your filter (and call #getMatchedResourceMethod()):

    @Inject
    private ExtendedUriInfo extendedUriInfo;
    

Note: Your filters cannot be annotated with @PreMatching annotation since the matching informations are not available at this moment.

Upvotes: 1

nsawaya
nsawaya

Reputation: 623

check the following, filter the events as needed:

RequestEventListener

Upvotes: 1

Related Questions