简体   繁体   中英

JAX-WS @WebService on RESTful web-service endpoint

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:

  • What is a Response in a SOAP response?
  • Will the response use JSON as the representation?
  • How are the methods called?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM