LibraryToggle FramesPrintFeedback

In this scenario your service is defined in a WSDL file. You use the wsdl2java tool to generate starting point JAX-WS compliant Java code from which you implement your service as a Stateless Session Bean (SLSB).

It is similar to the scenario described in Service Implemented as a Stateless Session Bean. Again you make use of the generic MDB implementation provided by Fuse Services Framework. It notifies the Apache CXF JCA Connector when it starts and the Apache CXF JCA Connector then activates the Fuse Services Framework service endpoint facade. The service endpoint facade dispatches client requests to the generic MDB. The MDB performs a JNDI lookup to obtain a reference to your SLSB and dispatches incoming requests to it.

The primary differences between this approach and the approach described in Service Implemented as a Stateless Session Bean is that:

  • You can configure the Fuse Services Framework runtime directly by including a cxf.xml configuration file in your EJB JAR file.

  • Fuse Services Framework creates a service bean based on the service WSDL file and you must include the WSDL file in the EJB JAR file.

  • Your EJB deployment descriptor must contain additional activation configuration properties, including:

    • busConfigLocation — Specifies the location of the configuration file.

    • wsdlLocation — Specifies the location of the service's WSDL file.

    • endpointName — Specifies the service's portType element's QName.

    • serviceName — Specifies the service's service element's QName.

    For more information on activation configuration properties, see Inbound Activation Configuration.

Complete the following steps if you want to use the Apache CXF JCA Connector to expose your J2EE application, defined in a WSDL file and implemented as a SLSB, as a Web service:

  1. Set your environment using the fuse_env script, which is located in the InstallDir/bin directory.

    For more information on the fuse_env script, see Setting Up Your Environment in Configuring and Deploying Web Service Endpoints.

  2. Obtain a copy of, or details of the location of, the WSDL file that defines the Web service that your application implements.

    This step assumes that the WSDL file already exists. If you need to develop a WSDL file, see Writing WSDL Contracts.

  3. Map the WSDL file to Java to obtain starting point JAX-WS compliant Java code. Fuse Services Framework provides a wsdl2java tool that does this for you.

    For more information on the wsdl2java tool, see wsdl2java in Tool Reference.

  4. Write a stateless session bean (SLSB) that implements the service that you want to expose. See, for instance, GreeterBean.java located in InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/src/demo/ejb and shown in Example 2.8.

    Example 2.8. WSDL First SLSB—GreeterBean.java

    package demo.ejb;
                                
    import java.util.logging.Logger;
    import javax.ejb.CreateException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
                                
    import org.apache.hello_world_soap_http.Greeter;
    import org.apache.hello_world_soap_http.PingMeFault;
    import org.apache.hello_world_soap_http.types.FaultDetail;
                                
    public class GreeterBean implements SessionBean, Greeter {
                                
          private static final Logger LOG = 
                Logger.getLogger(GreeterBean.class.getPackage().getName());
                                
           //------------- Business Methods 
           // (copied from wsdl_first sample)
                                
           public String greetMe(String me) {
                 LOG.info("Executing operation greetMe");
                 System.out.println("Executing operation greetMe");
                 System.out.println("Message received: " + me + "\n");
                 return "Hello " + me;
           }
                                
           public void greetMeOneWay(String me) {
                 LOG.info("Executing operation greetMeOneWay");
                 System.out.println("Executing operation greetMeOneWay\n");
                 System.out.println("Hello there " + me);
           }
                                
           public String sayHi() {
                 LOG.info("Executing operation sayHi");
                 System.out.println("Executing operation sayHi\n");
                 return "Bonjour";
           }
                                
           public void pingMe() throws PingMeFault {
                 FaultDetail faultDetail = new FaultDetail();
                 faultDetail.setMajor((short)2);
                 faultDetail.setMinor((short)1);
                 LOG.info("Executing operation pingMe, throwing PingMeFault exception");
                 System.out.println("Executing operation pingMe, throwing PingMeFault 
                 exception\n");
                 throw new PingMeFault("PingMeFault raised by server", faultDetail);
           }
                                
           //------------- EJB Methods
           public void ejbActivate() {
           }
                                
           public void ejbRemove() {
           }
                                
           public void ejbPassivate() {
           }
                                
           public void ejbCreate() throws CreateException {
           }
    
           public void setSessionContext(SessionContext con) {
           }
    
    }

  5. Write an EJB Local Home interface for your SLSB. See, for instance, GreeterLocalHome.java located in InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/src/demo/ejb and shown in Example 2.9.


  6. Write a Fuse Services Framework configuration file if you want to configure the runtime directly. See, for instance, the cxf.xml configuration file located in InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/etc and shown in Example 2.10. It shows how you configure logging.

    For more information on how to configure Fuse Services Framework, see Configuring and Deploying Web Service Endpoints.

    For information on how to configure Fuse Services Framework security, see Security Guide.


  7. Write a deployment descriptor for your SLSB and ensure that it includes:

    See, for instance, the ejb-jar.xml file in InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/etc and shown in Example 2.11.

    Example 2.11. WSDL First SLSB Deployment Descriptor—ejb-jar.xml

    <?xml version="1.0"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
                    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>GreeterWithWsdlBean</ejb-name>
               <local-home>demo.ejb.GreeterLocalHome</local-home>
               <local>demo.ejb.GreeterLocal</local>
               <ejb-class>demo.ejb.GreeterBean</ejb-class>
               <session-type>Stateless</session-type>
               <transaction-type>Container</transaction-type>
            </session>
                        
            <message-driven>
               <ejb-name>GreeterEndpointActivator</ejb-name>
               <ejb-class>org.apache.cxf.jca.inbound.DispatchMDBMessageListenerImpl
               </ejb-class>
               <messaging-type>org.apache.cxf.jca.inbound.DispatchMDBMessageListener
               </messaging-type>
               <transaction-type>Bean</transaction-type>
                            
               <activation-config>
                  <!-- bus configuration location -->
                  <activation-config-property>
                     <activation-config-property-name>
                        busConfigLocation
                    </activation-config-property-name>
                    <activation-config-property-value>
                       etc/cxf.xml
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- wsdl location -->
                 <activation-config-property>
                    <activation-config-property-name>
                       wsdlLocation
                    </activation-config-property-name>
                    <activation-config-property-value>
                       wsdl/hello_world.wsdl
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- service name -->
                 <activation-config-property>
                    <activation-config-property-name>
                       serviceName
                    </activation-config-property-name>
                    <activation-config-property-value>
                       {http://apache.org/hello_world_soap_http}SOAPService
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- endpoint name -->
                 <activation-config-property>
                    <activation-config-property-name>
                       endpointName
                    </activation-config-property-name>
                    <activation-config-property-value>
                       {http://apache.org/hello_world_soap_http}SoapPort
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- service interface class -->
                 <activation-config-property>
                    <activation-config-property-name>
                       serviceInterfaceClass
                    </activation-config-property-name>
                    <activation-config-property-value>
                       org.apache.hello_world_soap_http.Greeter
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- address -->
                 <activation-config-property>
                    <activation-config-property-name>
                       address
                    </activation-config-property-name>
                    <activation-config-property-value>
                       http://localhost:9000/SoapContext/SoapPort
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- display name-->
                 <activation-config-property>
                    <activation-config-property-name>
                       displayName
                    </activation-config-property-name>
                    <activation-config-property-value>
                       GreeterWithWsdlEndpoint
                    </activation-config-property-value>
                 </activation-config-property>
                 <!-- targetBeanJndiName -->
                 <activation-config-property>
                    <activation-config-property-name>
                       targetBeanJndiName
                    </activation-config-property-name>
                    <activation-config-property-value>
                       java:comp/env/GreeterWithWsdlLocalHome
                    </activation-config-property-value>
                 </activation-config-property>
              </activation-config>
                            
              <ejb-local-ref>
                 <ejb-ref-name>GreeterWithWsdlLocalHome</ejb-ref-name>
                 <ejb-ref-type>Session</ejb-ref-type>
                 <local-home>demo.ejb.GreeterLocalHome</local-home>
                 <local>demo.ejb.GreeterLocal</local>
                 <ejb-link>GreeterWithWsdlBean</ejb-link>
              </ejb-local-ref>
           </message-driven>
                        
        </enterprise-beans>
    </ejb-jar>

    The ejb-jar.xml file in this scenario includes additional activation configuration properties. These properties are used during endpoint activation and point to:

    • The configuration file: busConfigLocation

    • The service WSDL file: wsdlLocation

    • The service name QName as defined in the WSDL file: serviceName

    • The portType element's QName as defined in the WSDL file: endpointName

    If you are using EJB 3.0, the only change you need to make to the deployment descriptor is in the opening ejb-jar element. For EJB 3.0 it should read as shown in Example 2.3.

  8. Build your EJB JAR file and remember to include the service WSDL file in a wsdl directory and the Fuse Services Framework configuration file, if you have one, in an etc directory.

  9. Build the Apache CXF JCA Connector RAR file. It must have the following structure and contents:

    1. META-INF directory — Contains the ra.xml, located in InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl\etc

    2. Root directory — Contains the JAR files listed under Root in Table 2.1.

    The sample application build.xml file includes a generate.rar target that you can use to build the RAR file (see Example 2.4).

  10. Deploy the Apache CXF JCA Connector RAR file and your EJB JAR file to your J2EE application server. For details, see Deploying Apache CXF JCA Connector.

Comments powered by Disqus