Hi Kanishk,
It is a bug in the version of Jersey you are using. Try upgrading to
version 1.1.5.
Injection of HttpServletRequest, HttpServletResponse, ServletContext
and ServletConfig is supported. The latter will only work if you
deploy as a servlet, otherwise if you deploy as a filter you need to
use FilterConfig.
Paul.
On Mar 24, 2010, at 11:06 PM, Kanishk Panwar wrote:
> Fellow Users,
>
> I am using jersey 1.0.3 and I was experimenting with Injections when I
> got this error.
>
> First up I used the code below and it worked correctly.
> @Path("/v1")
> public class V1Service {
> @Context
> HttpContext context;
>
> @GET
> @Path("/test")
> public void test() {
> OutputStream os = null;
>
> try {
> os = context.getResponse().getOutputStream();
> os.write(("this is a test - " + new Date()).getBytes());
> os.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }
>
>
> When I made the modifications [shown below] I got this error.
> com.sun.jersey.api.container.ContainerException: Method, public void
> com.test.V1Service.test(javax.servlet.http.HttpServletResponse),
> annotated with GET of resource, class com.test.V1Service, is not
> recognized as valid Java method annotated with @HttpMethod.
>
> com
> .sun
> .jersey
> .server
> .impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:
> 92)
>
> com
> .sun
> .jersey
> .server
> .impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:
> 69)
>
> com
> .sun
> .jersey
> .server
> .impl
> .model.ResourceClass.processSubResourceMethods(ResourceClass.java:258)
>
> com
> .sun
> .jersey.server.impl.model.ResourceClass.<init>(ResourceClass.java:128)
>
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.newResourceClass(WebApplicationImpl.java:348)
>
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.getResourceClass(WebApplicationImpl.java:321)
>
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.processRootResources(WebApplicationImpl.java:807)
>
> com
> .sun
> .jersey
> .server
> .impl
> .application.WebApplicationImpl.initiate(WebApplicationImpl.java:590)
>
> com
> .sun
> .jersey
> .server
> .impl
> .application.WebApplicationImpl.initiate(WebApplicationImpl.java:383)
>
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.initiate(ServletContainer.java:
> 377)
> com.sun.jersey.spi.container.servlet.ServletContainer
> $InternalWebComponent.initiate(ServletContainer.java:242)
>
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.load(WebComponent.java:449)
>
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.init(WebComponent.java:169)
>
> com
> .sun
> .jersey
> .spi.container.servlet.ServletContainer.init(ServletContainer.java:
> 281)
>
> com
> .sun
> .jersey
> .spi.container.servlet.ServletContainer.init(ServletContainer.java:
> 442)
> javax.servlet.GenericServlet.init(GenericServlet.java:212)
>
> org
> .apache
> .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>
> org
> .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
> 286)
>
> org
> .apache.coyote.http11.Http11Processor.process(Http11Processor.java:
> 845)
> org.apache.coyote.http11.Http11Protocol
> $Http11ConnectionHandler.process(Http11Protocol.java:583)
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
> 447)
> java.lang.Thread.run(Thread.java:637)
>
>
> Given below is the code that generated the error.
> @Path("/v1")
> public class V1Service {
> @GET
> @Path("/test")
> public void test(@Context HttpServletResponse response) {
> OutputStream os = null;
>
> try {
> os = response.getOutputStream();
> os.write(("this is a test - " + new Date()).getBytes());
> os.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> }
>
>
> Any ideas why this is not working correctly? Also, I would like to
> eventually use HttpServletResponse, HttpServletRequest and
> ServletConfig as injections to execute certain logic. Is that a
> possibility?
>
> Any input is greatly appreciated.
>
> Thanks,
> Kanishk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>