Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call 1 jersey resource class from another Jersey resource class with @Context ServletContext

I have Jersey resource class A calling a method in resource class B.Both classes have a @Context ServletContext servletContext at the class level. When I instantiate class B to call it from resource class A using its empty constructor, servletContext is null in the class B method being called. Is there any Jersey framework way I can call class B and yet have the servletContext retain its values/attributes from class A.

like image 408
Vijay Avatar asked Aug 04 '11 15:08

Vijay


1 Answers

You can instantiate class B using ResourceContext. I.e. in class A you can have:

@Context private ResourceContext rc;

And then in you can instantiate resource B as follows:

B resourceB = rc.getResource(B.class);

See ResourceContext javadoc for more info.

like image 130
Martin Matula Avatar answered Nov 02 '22 14:11

Martin Matula