We have seen how we can expose a Java application as a web service by deploying it as a WAR file in a web container. JAX-WS also allows a stateless session bean to be exposed as a web service by deploying it as a JAR file in an EJB container. The JAX-WS annotations that we use are the same for a stateless session bean as those we used for a Java application.
Below is a listing for the BankEndpointBean
stateless session bean which we have modified to be a web service. The EJB has one business method, addCustomer()
, which adds a new customer to the database. We use the same Customer entity from earlier chapters.
package endpoint;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import entity.Customer;
import javax.persistence.PersistenceContext;
import java.util.*;
@Stateless
@WebService
public class BankEndpointBean {
@PersistenceContext(unitName="BankService")
private...