12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 7 ■ SESSION BEANS AND THE TIMER SERVICE@Stateless@Remote (ItemRemote.class)@Local (ItemLocal.class)public class ItemEJB implements ItemLocal, ItemRemote {...}Web Services InterfaceIn addition to remote invocation through RMI, stateless beans can also be invoked remotely as SOAPweb services or RESTful web services. Chapters 14 and 15 are dedicated to web services, so I won’tdescribe them here. I just want to show you how a stateless session bean can be accessed in variousforms just by implementing different annotated interfaces. Listing 7-11 shows a stateless bean <strong>with</strong> alocal interface, a SOAP web services endpoint (@WebService), and a RESTful web service endpoint(@Path). Note that these annotations come respectively from JAX-WS and JAX-RS and are not part of EJB.Listing 7-11. A Stateless Session Bean Implementing Several Interfaces@Localpublic interface ItemLocal {List findBooks();List findCDs();}@WebServicepublic interface ItemSOAP {List findBooks();List findCDs();Book createBook(Book book);CD createCD(CD cd);}@Path(/items)public interface ItemRest {List findBooks();}@Statelesspublic class ItemEJB implements ItemLocal, ItemSOAP, ItemRest {...}Bean ClassA session bean class is any standard <strong>Java</strong> class that implements business logic. The requirements todevelop a session bean class are as follows:217

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!