Version 3

    EJB component clients

     

    The service client programming model for ejb components is about how to access a remote web service from any kind of

    ejb component. The web service client is deployed as a standard jar archive plus additional <service-ref> elements in the

    ejb-jar.xml deployment descriptor.

     

    Service Endpoint Interface

     

    The SEI declares the methods through which to access the remote web service.

    We use the same service endpoint interface as for the EJB service endpoint.

     

    Web Service Description Language

     

    Any web service client must have access to the wsdl that describes the remote webservice. The wsdl can be part of the ejb

    deployment or may be obtained at runtime before the ejb accesses the remote web service.

     

    JAX-RPC Mapping Files

     

    The web service client must have access to the same mapping information as described for the EJB service endpoint

    or the Java service endpoint. The jaxrpc mapping file must be part of the deployment, it cannot be

    obtained at runtime.

     

    Packaging the web service client

     

    The standard deployment descriptor for ejb components ejb-jar.xml, declares the service reference.

     

       <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:impl="http://com.underworld.crimeportal/ws4ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
         version="2.1">
       
         <enterprise-beans>
           <session>
             <ejb-name>OrganizationClientBean</ejb-name>
             <home>com.underworld.crimeportal.ejb.OrganizationClientHome</home>
             <remote>com.underworld.crimeportal.ejb.OrganizationClientRemote</remote>
             <ejb-class>com.underworld.crimeportal.ejb.OrganizationClientBean</ejb-class>
             <session-type>Stateless</session-type>
             <transaction-type>Container</transaction-type>
       
             <service-ref>
               <service-ref-name>service/OrganizationServiceEJB</service-ref-name>
               <service-interface>javax.xml.rpc.Service</service-interface>
               <wsdl-file>META-INF/wsdl/server-ejb.wsdl</wsdl-file>
               <jaxrpc-mapping-file>META-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
             </service-ref>
             
             <service-ref>
               <service-ref-name>service/OrganizationServiceJSE</service-ref-name>
               <service-interface>com.underworld.crimeportal.OrganizationEndpointService</service-interface>
               <wsdl-file>META-INF/wsdl/server-web.wsdl</wsdl-file>
               <jaxrpc-mapping-file>META-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
             </service-ref>
       
           </session>
         </enterprise-beans>
       
       </ejb-jar>
    

     

    Service Interface

     

    It is possible to provide a typed service interface to web service clients that extends the standard

    javax.xml.rpc.Service interface. In this way the client looks up a service from JNDI that already

    has application specific semantics.

     

       public interface OrganizationEndpointService extends javax.xml.rpc.Service
       {
          public OrganizationEndpoint getOrganizationPort() throws javax.xml.rpc.ServiceException;
       }
    

     

    Deploy the Web Service client to JBoss

     

    This follows the normal deployment procedure for ejb components in JBoss. There are no web service specific info

    messages.

     

    Accessing the remote web service

     

    Here is a simple Stateless Session Bean, that shows how an ejb does a lookup of the service interface, then obtains the

    desired port, and finally invokes getContactInfo on the service endpoint interface.

     

       public class OrganizationClientBean implements SessionBean
       {
          /** Get the contact info from the EJB service */
          public String getContactInfoEJB(String organization) throws RemoteException
          {
             try
             {
                InitialContext iniCtx = new InitialContext();
                Service service = (Service)iniCtx.lookup("java:/comp/env/service/OrganizationServiceEJB");
                OrganizationEndpoint endpoint = (OrganizationEndpoint)service.getPort(OrganizationEndpoint.class);
                String info = endpoint.getContactInfo(organization);
                return info;
             }
             catch (Exception e)
             {
                throw new EJBException("Cannot invoke webservice", e);
             }
          }
       
          /** Get the contact info from the JSE service */
          public String getContactInfoJSE(String organization) throws RemoteException
          {
             try
             {
                InitialContext iniCtx = new InitialContext();
                OrganizationEndpointService service = (OrganizationEndpointService)iniCtx.lookup("java:comp/env/service/OrganizationServiceJSE");
                OrganizationEndpoint endpoint = service.getOrganizationPort();
                String info = endpoint.getContactInfo(organization);
                return info;
             }
             catch (Exception e)
             {
                throw new EJBException("Cannot invoke webservice", e);
             }
          }
          
          // lifecycle methods not shown
       }