Web Services support
EJBs provide seamless support for exposing business functionality as web services - REST and SOAP being two variants. The annotations responsible to this magic are
@Path
@WebService
@Path
and@WebService
are not a part of the EJB specification. They belong to JSR 311 (JAX-RS) and JSR 181 (JAX-WS) specifications respectively
@WebService
@WebService
The real beauty lies in the fact that session beans can be decorated with this annotation and the EJB container automagically exposes their functionality as SOAP based web services.
As you might have already noticed in the above example, JSR 181 exposes other annotations like @WebMethod
, @WebResult
, @WebParam
etc. to help further refine your web service methods.
In order to gain more flexibility and ease of extension, a better approach would be to provide a layer of indirection with the help of an additional session bean
Delegate actual service calls to an injected EJB instance
Avoid tight coupling between your Web Service layer and EJB business tier logic
@Path
@Path
REST web services cannot lag behind SOAP. Can they ! Java EE provides you the ability to use the @Path
annotation to expose session beans over a RESTful interface. I guess you have already realized that the idea is not very different compared to the SOAP based web service interface approach.
Similar to SOAP based approach
Avoid coupling b/w your EJB and RESTful interface by introducing another layer of abstraction/facade
Continue to enrich your EJB methods with additional annotations from the JAX-RS API e.g.
@PUT
,@DELETE
,@PathParam
etc.
Up ahead...
The next chapter covers exception handling and its one and only annotation
Last updated
Was this helpful?