开发者

Enunciate error during invocation when full CRUD is supported in JAX-RS annotated service

I've run into a rather interesting enunciate error:

"No more than one JAX-RS entity parameter is allowed (all other parameters must be annotated with one of the JAX-RS resource parameter annotations)."

I'm using enunciate to build out both a SOAP and REST API, supporting XML and JSON. Enunciate is configured to use all service.* and service.impl.* classes. Each service contains all Javadoc for the enunciate documentation, as well as a [@GET @POST @PUT @DELETE] and a @Path annotation. Each service impl contains a class @Path annotation.

Example interface:

public interface myService {

  @GET
  @Path("/something")
  Object doGetAll();

  @GET
  @Path("/something/{id}"
  Object doGetOne(@PathParam("id") Integer id);

  @PUT
  @Path("/something")
  Object doCreate(/*params*/);

  @POST
  @Path("/something/{id}")
  Object doUpdate(@PathParam("id") Integer id, /*params*/);

  @DELETE
  @Path("/something/{id}")
  Object doDelete(@PathParam("id") Integer id);
}

Example implementation:

@Path("/base")
public class myServiceImpl implements myService {

  Object doGetAll() {/*stuff*/}

  Object doGetOne(Integer id) {/*stuff*/}

  Object doCreate(/*params*/) {/*stuff*/}

  Object doUpdate(Integer id, /*params*/) {/*stuff*/}

  Object doDelete(Integer id) {/*stuff*/}
}

When I comment out the "@POST" and "@PUT" annotations in my service, enunciate will run just fine. However, commenting either back in will fail enunciate with the message above. The catch is that I have services that encompass 2-8 different models (example: my addressService incorporates 3 objects: address, state and country), so I've specified the path contexts (using address) as follows:

on the impl:

@Path("/address")
public class myAddressServiceImpl implements myAddressService {}

on t开发者_JAVA技巧he methods:

@GET
@Path("/{id}")
findAddressById();

@GET
@Path("/states/{id}")
findStateById();

@GET
@Path("/countries/{id}")
findCountryById();

If I can provide more information, I'd be happy to. This has been a rather frustrating problem, because I'm not sure if I've configured enunciate incorrectly (doubtful, it's a basic configuration) or if I'm stretching what JAX-RS can do. I've spent a good bit of time reading tutorials, Googling and looking at Javadoc (for enunciate and JAX-RS), but haven't had much luck.

Has anyone else seen this issue? Any thoughts on what I might do to fix it? I'm getting a feeling this will be one of those "no-duh" fixes...just can't put my finger on it.

Thanks in advance for the help.


An "entity parameter" is a parameter that is specified by the body of the REST request. In other words, the request body is read and an attempt is made to deserialize it into an an object of your parameter type, and then the request is invoked.

Since there can only be one body, there can only be one entity parameter.

The other parameters have to be annotated with @QueryParameter, @PathParameter, etc.

So what this error message is really trying to say is "for all methods that are annotated with @POST and @PUT, you can only have one parameter that is not annotated with some annotation. All other parameters need to have a parameter annotation."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜