I'm new to JAX-RS and I'm trying to understand how the @Context annotation works. I have a REST service and am currently using certain filters to do extra processing for different request types. Inside one of those filters is the following line:
public class SentryFilter {
@Context
HttpServletResponse response;
...
This value is used later on in the filter()
method of that filter. The problem is that the response object is null. I've stepped through a debugger and can't determine why it's null.
From what I've read in the JAX-RS documentation, the @Context annotation for HttpServletResponse can be filled by the resource methods. So, I modified my the API I'm calling to include HttpServletResponse
public interface APIStuff {
@Path("deviceName")
@GET
@Sentry
String getDeviceName(@PathParam("deviceId") @Size(min = 1, max = 1024) final String deviceId, @Context HttpServletResponse httpServletResponse);
...
This returns the same HttpServletResponse is null error.
So the question is, where is this value supposed to be "filled"? The person who wrote the filter class obviously did so with the belief that the response
object would be filled, so I don't think it's a matter of passing in @Context HttpServletResponse
to the filter()
method.