Some time ago in one of the projects I found @WebService annotations on some of the jersey root(@Path) resource classes. As far as I understood at the time it was some legacy code or simply a misused JAX-WS annotation. Recently I stumbled upon this post in which mixing JAX-RS service with @WebService annotation for the sake of EJB mentioned(as a side note, that project I worked on didn't make use of EJB at all, so I still think it was an improper use of @WebService). As a result of all that I am now confused if it is in general justifiable to mix @WebService and JAX-RS. What are the cases for that? Anything apart from EJB features mentioned?
Exposing a JAX-RS bean as the methods of a SOAP WS using @WebService
may be technically possible. It will not lead to a good API design.
Consider some very common JAX-RS methods:
@GET
@Path("/foos")
@Produces("application/json")
public Response getFoos() {
// get all Foos
List<Foo> foos = ...;
return Response.ok(foos).build();
}
@GET
@Path("/foos/{id}")
@Produces("application/json")
public Response getSingleFoo(@PathParam("id") String id) {
// get the Foo
Foo foo = ...;
return Response.ok(foo).build();
}
It is immediatley obvious how the URLs to call these methods will be structured and what the result will be.
But exposing these methods using @WebService
leads to many questions:
Response
in a SOAP response?I can imagine no usecase that is not completely trivial for which it makes sense to expose the same method using both JAX-RS and JAX-WS. It can either be a useful method for one but not for both.
Don't do this.