On May 19, 2009, at 5:56 PM, Haresh K wrote:
> I am trying to use @Context annotations for ServletContainer and it
> does not seem to inject the right data.
>
> The program:
>
> @Path (value="/test")
> @Produces ({MediaType.APPLICATION_XML})
> public final class TestResource
> {
> @Context HttpServletRequest servletRequest;
>
> @GET
> public Resource get()
> {
> System.out.println(servletRequest.getCharacterEncoding());
> System.out.println(servletRequest.getContentType());
Makes sense that these two are null since its a GET request with no
body.
> System.out.println(servletRequest.getContextPath());
>
This could be "" if you are deploying at the root context.
Try adding System.out.println(servletRequest.getMethod()) to convince
yourself that the servletRequest is OK.
Marc.
> return null;
> }
> }
>
> produces the following response:
>
> null
> null
>
> null
>
> Is this a bug or am I doing something wrong?
>
> (I am using Jersey 1.0, JDK 1.6, configured Servlet
> com.sun.jersey.spi.container.servlet.ServletContainer )
>
> thanks for your help
> -hk