users@jersey.java.net

Re: [Jersey] Annotation[] parameter in MessageBodyReader.readFrom method.

From: Erick Dovale <edovale_at_gmail.com>
Date: Mon, 26 Jan 2009 11:50:14 -0500

1.0

On Mon, Jan 26, 2009 at 11:48 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> What version of Jersey are you using?
> Paul.
>
> On Jan 26, 2009, at 5:35 PM, Erick Dovale wrote:
>
> Hi Paul,
> Thanks a lot for the quick reply.
> I think this is more than a bug in the javadoc then. I tried annotating the
> entity parameter with an annotation of my own and jersey craches on it. This
> is the exception I am getting:
>
>
> SEVERE: Exception occurred when intialization
> com.sun.jersey.api.container.ContainerException: Method, public
> javax.ws.rs.core.Response
> com.bps.iproject.jersey.resources.BlueprintControlControlTestResource.addControlTestsToControl(java.util.LinkedHashSet,long,long),
> annotated with PUT of resource, class
> com.bps.iproject.jersey.resources.BlueprintControlControlTestResource, is
> not recognized as valid Java method annotated with @HttpMethod.
> at
> com.sun.jersey.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:74)
> at
> com.sun.jersey.impl.model.method.ResourceHttpMethod.<init>(ResourceHttpMethod.java:56)
> at
> com.sun.jersey.impl.model.ResourceClass.processMethods(ResourceClass.java:244)
> at
> com.sun.jersey.impl.model.ResourceClass.<init>(ResourceClass.java:116)
> at
> com.sun.jersey.impl.application.WebApplicationImpl.newResourceClass(WebApplicationImpl.java:292)
> at
> com.sun.jersey.impl.application.WebApplicationImpl.getResourceClass(WebApplicationImpl.java:263)
> at
> com.sun.jersey.impl.application.WebApplicationImpl.processRootResources(WebApplicationImpl.java:827)
> at
> com.sun.jersey.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:671)
> at
> com.sun.jersey.spi.spring.container.servlet.SpringServlet.initiate(SpringServlet.java:66)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.load(ServletContainer.java:538)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:197)
> at
> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
> at
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
> at
> org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
> at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4364)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
> at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
> at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
> at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
> at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
> Jan 26, 2009 11:28:28 AM org.apache.catalina.core.ApplicationContext log
>
>
> Here is the signature of the method:
>
>
>> @PUT public Response addQuestionsToBlueprintControl(@JSONPath("questions")
>> LinkedHashSet<Question> questions,
>> @PathParam("blueprintId") long blueprintId,
>> @PathParam("controlId") long controlId)
>>
>
> Where JSONPath is my annotation defined like this:
>
> @Target({ElementType.PARAMETER})
>> @Retention(RetentionPolicy.RUNTIME)
>> public @interface JSONPath {
>>
>> String value();
>>
>> }
>>
>
> I have an instance of MessageBodyReader that is able to convert the reuest
> entity to a LinkedHashSet<Question>.
>
> This exception I get during application startup and jersey fails to start
> because of this.
> Any ideas?
>
> Thanks.
>
> On Mon, Jan 26, 2009 at 4:54 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
>> Hi Erick,
>>
>>
>> On Jan 26, 2009, at 4:17 AM, Erick Dovale wrote:
>>
>> Hi,
>>> Can anyone explain what annotations are passed in the Annotation[]
>>> parameter in the readFrom method in MessageBodyReader?
>>> I can't understand the javadoc; this is what it says:
>>>
>>> an array of the annotations on the declaration of the artifact that will
>>> be initialized with the produced instance. E.g. if the message body is to be
>>> converted into a method parameter, this will be the annotations on that
>>> parameter returned by <code>Class.getParameterAnnotations</code>.
>>>
>>> First, I could not find such method in java.lang.Class.
>>> Am I missing something?? or this javadoc a bit screwy?
>>>
>>>
>> Bug in the JavaDoc. It should be "Method.getParameterAnnotations"
>>
>> If there is a resource method say:
>>
>> @POST
>> public void post(@QueryParam String a, @XYZ @ABC MyType entity) { ... }
>>
>> Then the parameter "entity" is selected to be the parameter that the
>> request entity will be serialized to with the selected message body writer.
>> The array of annotations will be those declared on the parameter "entity".
>>
>> Paul.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
>