Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Deploying an EJB Session Bean as a Web Service


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...