cdugga
cdugga

Reputation: 3859

Applying interceptor to Jersey RESTful service wired as Spring @Component

Is it possible to apply a Spring handler interceptor or something similar to a Jersey Restful service? The Jersey service is built with Spring and is inside a Spring @Component?

I noticed that Spring allows the use of handler interceptors for controllers but cant find anything to work with my Jersey-Rest component

Thanks

Upvotes: 2

Views: 3889

Answers (2)

Kishore Bandi
Kishore Bandi

Reputation: 5721

I faced a similar problem and this how I solved it in Jersey. This works similar to HandleInterceptor of Spring.

Upvotes: 0

Stefan
Stefan

Reputation: 1000

Jersey comes with its own servlet and therefore is pretty much outside of Spring MVC, which the Interceptors are part of. You can either:

  • Use a Spring HTTP Filter to massage the HTTPServletRequest and the HTTPServletResponse around Jersey
  • Use a Spring Handled Aspect around your Spring Component inside of Jersey to massage the Method invocation and result.

This guy here did a great job summing up the nuts and bolts: http://www.mkyong.com/webservices/jax-rs/jersey-spring-integration-example/

Upvotes: 3

Related Questions