On Jun 11, 2009, at 10:26 PM, Paul Sandoz wrote:
>
> On Jun 12, 2009, at 12:00 AM, Igor Minar wrote:
>
>>
>> On Jun 11, 2009, at 5:46 AM, Paul Sandoz wrote:
>>
>>>
>>> On Jun 11, 2009, at 2:29 PM, Igor Minar wrote:
>>>
>>>> Hi there,
>>>>
>>>> I'm curious as to why it is illegal to inject request as a method  
>>>> parameter for methods annotated with @GET.
>>>>
>>>
>>> You can do this:
>>>
>>> @GET
>>> public String get(@Context HttpServletRequest hsr) {
>>>  String remoteAddress = hsr.getRemoteAddr();
>>> }
>>>
>>
>> That's what I tried, but I'm getting an error that such a method is  
>> an illegal/invalid method for given http method. I'm using 1.1.0-ea.
>>
>
> I cannot reproduce, It works for me.
@Singleton
@Path("/test")
public class TestResource {
  @GET
     @Produces({MediaType.APPLICATION_XML , MediaType.APPLICATION_JSON})
     public List<User> getUsers(
                         final @MatrixParam("foo") String foo,
                         final @MatrixParam("bar") String bar,
                         final @MatrixParam("baz") String baz,
                         ...
                         final @Context HttpServletRequest req) { .... }
>
> Can you send the log/stack trace (if any) ?
>
Jun 11, 2009 11:54:24 PM  
com.sun.jersey.server.impl.application.WebApplicationImpl initiate
INFO: Initiating Jersey application, version 'Jersey: 1.1.0-ea  
04/30/2009 05:54 PM'
Exception in thread "main"  
com.sun.jersey.api.container.ContainerException: Method, public  
java.util.List  
com 
.sun 
.webeng 
.foo 
.resource 
.TestResource 
.getUsers 
(java 
.lang 
.String 
,java 
.lang 
.String 
,java 
.lang 
.String 
,java 
.lang 
.String 
,java 
.lang 
.String 
,java 
.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest),  
annotated with GET of resource, class  
com.sun.webeng.foo.resource.TestResource, is not recognized as valid  
Java method annotated with @HttpMethod.
         at  
com 
.sun 
.jersey 
.server 
.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:92)
         at  
com 
.sun 
.jersey 
.server 
.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:69)
         at  
com 
.sun 
.jersey 
.server 
.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:61)
         at  
com 
.sun 
.jersey 
.server.impl.model.ResourceClass.processMethods(ResourceClass.java:283)
         at  
com 
.sun.jersey.server.impl.model.ResourceClass.<init>(ResourceClass.java: 
131)
         at  
com 
.sun 
.jersey 
.server 
.impl 
.application 
.WebApplicationImpl.newResourceClass(WebApplicationImpl.java:350)
         at  
com 
.sun 
.jersey 
.server 
.impl 
.application 
.WebApplicationImpl.getResourceClass(WebApplicationImpl.java:323)
         at  
com 
.sun 
.jersey 
.server 
.impl 
.application 
.WebApplicationImpl.processRootResources(WebApplicationImpl.java:811)
         at  
com 
.sun 
.jersey 
.server 
.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java: 
594)
         at  
com 
.sun 
.jersey 
.api.container.ContainerFactory.createContainer(ContainerFactory.java: 
168)
         at  
com 
.sun 
.jersey 
.api.container.ContainerFactory.createContainer(ContainerFactory.java: 
251)
         at  
com 
.sun 
.jersey 
.api.container.ContainerFactory.createContainer(ContainerFactory.java: 
233)
         at  
com 
.sun 
.jersey 
.simple.container.SimpleServerFactory.create(SimpleServerFactory.java: 
140)
         at  
com 
.sun 
.jersey 
.simple.container.SimpleServerFactory.create(SimpleServerFactory.java: 
92)
         at com.sun.webeng.foo.Foo.main(Foo.java:13)
> Can you inject "@Context HttpServletRequest hsr" as a field of the  
> class instead?
I can, but nothing gets injected, the request ends up being null.  
Though the app at least starts without exceptions.
>
> Are you deploying using a Web container?
I'm using SimpleServerFactory.
thanks!
/i
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>