Enterprise Java Development@TOPIC@

JAX-RS EJB

Web-centric EJB deployment

Revision: v2013-08-19

Built on: 2014-03-07 00:33 EST

Abstract

This presentation contains introductory topics for packaging EJBs within the web tier and exposing thru RMI and JAX-RS interfaces.


Purpose
1. Goals
2. Objectives
1. EJB WAR Deployment
1.1. WAR Structure
1.1.1. Deploying External EJB JARs
1.1.2. Deploying Embedded EJBs
1.2. WAR Clients
1.2.1. Accessing HTTP Resources
2. Resources, URI, and Methods
2.1. Resources
2.2. URIs
2.3. Methods
2.4. Response Codes
2.5. JAX-RS Resource Class
2.5.1. JAX-RS Resource POST Method
2.5.2. JAX-RS GET Resource Method
2.5.3. JAX-RS PUT Resource Method
2.5.4. JAX-RS DELETE Resource Method
2.6. HTTP Request/Response
3. XML Representations
3.1. XML Payload
3.2. Defining JAXB DTOs
3.2.1. Defining JAXB Attributes
3.2.2. Defining JAXB Elements
3.2.3. Defining JAXB Collections/Sequences
3.3. JAXB Marshalling/Demarshalling
3.3.1. JAXB Marshalling
3.3.2. JAXB Demarshalling
3.4. Marshaling XML to/from Resource Methods
3.4.1. Marshaling XML Requests to Resource Methods
3.4.2. Marshaling XML Response from Resource Methods
  • Prior to JavaEE 6

    • EJB beans could only be deployed in EJB modules

    • EJB modules integrated with WARs using common EAR

  • Starting with JavaEE 6

    • EJB beans can be embedded within WAR

    • EJB modules can be deployed within WAR

|-- index.html                                                                                                                                                        
`-- WEB-INF                                                                                                                                                           
    ...
    |-- jboss-web.xml
    |-- lib
    `-- web.xml
        
	WEB-INF/lib/
	`-- webejbCustomerEJB-3.0.2012.2-SNAPSHOT.jar
WEB-INF
|-- beans.xml                                                                                                                                                     
|-- classes
|   |-- ejava
|   |   `-- examples
|   |       `-- ejbwar
|   |           `-- inventory
|   |               |-- bo
|   |               |   |-- Categories.class
|   |               |   |-- Category.class
|   |               |   |-- InventoryRepresentation.class
|   |               |   |-- Product.class
|   |               |   `-- Products.class
|   |               |-- client
|   |               |   |-- InventoryClient.class
|   |               |   `-- InventoryClientImpl.class
|   |               |-- dao
|   |               |   |-- InventoryDAO.class
|   |               |   `-- InventoryDAOImpl.class
|   |               |-- ejb
|   |               |   |-- InventoryMgmtEJB.class
|   |               |   `-- InventoryResources.class
|   |               |-- rmi
|   |               |   |-- InventoryMgmtRemote.class
|   |               |   `-- InventoryMgmtRMIEJB.class
|   |               `-- rs
|   |                   |-- Application.class
|   |                   |-- CategoriesResource.class
|   |                   |-- PrettyPrinter.class
|   |                   |-- ProductsResource.class
|   |                   |-- ResourceHelper.class
|   |                   `-- TxFilter.class
|   `-- META-INF
|       `-- persistence.xml
...
        


@Path("/products")
public class ProductsResource {
    private static final Log log = LogFactory.getLog(ProductsResource.class);
    @Inject
    private InventoryMgmtEJB ejb;
    @Context
    private Request request;
    @Context 
    private UriInfo uriInfo;
    ...


@XmlRootElement(name="catageory", namespace=InventoryRepresentation.NAMESPACE)
@XmlType(name="Category", namespace=InventoryRepresentation.NAMESPACE)
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Category extends InventoryRepresentation {
    private int id;
    private String name;
    private Integer productCount;
    private List<Product> products=new ArrayList<Product>();
    public Category() {}
    public Category(String name) {
        this.name=name;
    }
...    
}