EJB 3 specification allows to expose stateless session beans as JAX-WS Web services. EJB is relevant as an integration and remote invocation protocol at least for the following reasons:
- Transaction and security context is built into EJB.
- EJB containers have support for load balancing and failover that it's not easy to reach with simple Web Services.
The best way to realize an EJB 3 Web Service is to follow the following three steps:
- Design the service contract using WSDL.
- Use JAX-WS (wsimport) to generate a corresponding Java interface.
- Create a stateless session bean implementing the interface.
Let's see an example using Jboss Developer Studio and JBoss Wildfly 9. The first EJB 3.2 project follows the Bottom-Up approach: we realize the java code implementing the Web Service and from this one we generate the WSDL file:
Pay attention in this first video, TicketService.wsdl is not automatically generated, I created this file using the Web Service URL. The second EJB project uses the Top-Down approach: starting from the TicketService.wsdl file, we can generate all Web Service classes except the implementation class:
The most important part of the second project is the use of wsimport tool inside an Ant Script for the Web Service classes generation task:
<?xml version = '1.0'?>
<property name="jdk.home" value="C:\Program Files\Java\jdk1.8.0_91" />
<arg line=" -s ../../ejbModule
-p it.javadoor.ws.soap http://localhost:8080/JAX-WS- BottomUp/TicketServiceService/ITicketServiceImpl?wsdl"/>