users@jersey.java.net

Re: [Jersey] problem with JAX-WS and JAX-RS annotations in the same class.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 15 Oct 2008 08:34:39 +0200

On Oct 14, 2008, at 11:26 PM, Steve S wrote:

> I have several Web Services that I have annotated with JAX-WS
> annotations. I would like to expose the same functionality as Rest
> services using Jersey's JAX-RS annotations. I've noticed that
> everything works great until I annotate a method parameter with a
> @WebParam annotation, as in the following:
>
> @Path("saveRequest")
> @POST
> @WebMethod
> @WebResult(name="request")
> public FileRequest saveRequest(@WebParam(name="request") FileRequest
> request) {
> // code removed.
> }
>
> When I deploy to GlassFish, Jersey issues the following complaint:
> java.lang.IllegalStateException: ContainerBase.addChild: start:
> LifecycleException:
> com.sun.jersey.api.container.ContainerException: Method, public
> com.pinnacol.cms.entity.FileRequest
> com
> .pinnacol
> .cms
> .service
> .RestfulEndpoint.saveRequest(com.pinnacol.cms.entity.FileRequest),
> annotated with POST of resource, class
> com.pinnacol.cms.service.RestfulEndpoint, is not recognized as valid
> Java method annotated with @HttpMethod.
>
> If I remove the @WebParam annotation, everything works fine.
>
> Is this a bug with the way Jersey processes the annotations?
>

I think so, Jersey is being too aggressive. It should treat a
parameter with any unrecognized annotations as a parameter with no
annotations and thus be considered an entity parameter. Could you log
an issue?

The work around is to have another method that defers to saveRequest:

   @Path("saveRequest")
   @POST
   public FileRequest postSaveRequest(FileRequest request) {
     return saveRequest(request);
   }

I presume FileRequest is a JAXB type?

Paul.