mercoledì 21 giugno 2017

JAX-WS Web Services : Expose a Stateless Session Bean as Web Service

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'?> 
<!DOCTYPE project>
<project default="wsimport">
  <property name="jdk.home" value="C:\Program Files\Java\jdk1.8.0_91" />
  <target name="wsimport">
    <exec executable="${jdk.home}/bin/wsimport">
      <arg line="  -s ../../ejbModule 
                          -d ../../build/classes 
                          -p http://localhost:8080/JAX-WS-                                                                                       BottomUp/TicketServiceService/ITicketServiceImpl?wsdl"/>

Nessun commento:

Posta un commento