Using EJBs with Axis - The Deployment Unit
(Page 4 of 5 )
Once the EJBs are written, you should deploy and test them before attempting to Web service–enable them. Typically, the EJBs might already exist. In some circumstances, the EJBs may not offer the right service interface, in which case a layer of stateless session beans can be implemented to offer a clean interface that can then be Web service enabled. The EJBs are packaged in an EJB JAR, which is then packaged in an Enterprise Application aRchive (EAR file) g.
The EJBs must have appropriate XML DDs. The tags containing the deployment information for each bean are shown in the following snippets. Here's the DD fragment for the entity bean:
<entity id="SkatesEntity">
<ejb-name>SkatesEntity</ejb-name>
<local-home>
com.skatestown.ejb.SkatesEntityLocalHome
</local-home>
<local>com.skatestown.ejb.
SkatesEntityLocal</local>
<ejb-class>
com.skatestown.ejb.SkatesEntityBean
</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>SKATES</abstract-schema-
name>
<cmp-field id="pc">
<field-name>productCode</field-name>
</cmp-field>
<cmp-field id="desc">
<field-name>description</field-name>
</cmp-field>
<cmp-field id="prc">
<field-name>price</field-name>
</cmp-field>
<primkey-field>productCode</primkey-field>
</entity>
And here's the session bean fragment from the DD:
<session id="SkatesService">
<ejb-name>SkatesService</ejb-name>
<home>com.skatestown.ejb.SkatesServiceHome</home>
<remote>com.skatestown.ejb.SkatesService</remote>
<ejb-class>
com.skatestown.ejb.SkatesServiceBean
</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref id="entref">
<description>
Reference to SkatesEntity
</description>
<ejb-ref-name>skateEnt</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>
com.skatestown.ejb.SkatesEntityLocalHome
</local-home>
<local>com.skatestown.ejb.
SkatesEntityLocal</local>
<ejb-link>SkatesEntity</ejb-link>
</ejb-local-ref>
</session>
As you'll see from looking at the session bean DD, it includes a reference from the session bean to the entity bean. This is the point at which the "java:comp/env/skateEnt" is defined.
The EJBs are now packaged into a JAR file together with the DD. The JAR contents are as follows:
>jar tf skatesejb.jar
META-INF/ejb-jar.xml
com/skatestown/ejb/Product.class
com/skatestown/ejb/SkatesEntityBean.class
com/skatestown/ejb/SkatesEntityLocal.class
com/skatestown/ejb/SkatesEntityLocalHome.class
com/skatestown/ejb/SkatesService.class
com/skatestown/ejb/SkatesServiceBean.class
com/skatestown/ejb/SkatesServiceHome.class
META-INF/MANIFEST.MF
Next: Exposing the EJBs via Axis >>
More Web Services Articles
More By Sams Publishing
|
This article is excerpted from chapter 7 of the book Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418). Check it out today at your favorite bookstore. Buy this book now.
|
|