Use the @Context annotation to inject everything you want into your method:
@GET public Response getWhatever(@Context ServletContext servletContext) { String myParm = servletContext.getInitParameter("parmName"); }
With @Context you can enter HttpHeaders, UriInfo, Request, HttpServletRequest, HttpServletResponse, ServletConvig, ServletContext, SecurityContext.
Or something else if you use this code:
public class MyApplication extends Application { public MyApplication(@Context Dispatcher dispatcher) { MyClass myInstance = new MyClass(); dispatcher.getDefautlContextObjects(). put(MyClass.class, myInstance); } } @GET public Response getWhatever(@Context MyClass myInstance) { myInstance.doWhatever(); }
Mark lutton
source share