In this scenario you implement your service as a Stateless Session Bean (SLSB). Fuse Services Framework provides a generic MDB implementation that notifies the Apache CXF JCA Connector when it starts. The Apache CXF JCA Connector then activates the Fuse Services Framework service endpoint facade, which dispatches client requests to the generic MDB. The MDB dispatches incoming requests to your SLSB, using the SLSB's EJB local reference (as implemented in its Local Home interface).
The advantage of this approach is that you do not have to edit the Apache CXF JCA Connector deployment descriptor.
In addition, there is no need for a service WSDL file. Fuse Services Framework uses the service endpoint interface to build a service
model as it is defined in the activation specification serviceInterfaceClass property in your application's
deployment descriptor file, ejb-jar.xml.
The disadvantage of this approach is that it may not preform as fast as the approach described in Service Implemented as a Message Driven Bean.
Fuse Services Framework includes a working example of this scenario. You can find it in the
samples/integration/jca/inbound-mdb-dispatch directory of your Fuse Services Framework
installation.
If you want to build and run this sample, please follow the instructions outlined in the README.txt
file located in this directory. The example code shown in this section is taken from this sample application.
Complete the following steps to expose your J2EE application, implemented as a SLSB, as a Web service using the Apache CXF JCA Connector:
Write a SLSB that implements the service that you want to expose. See, for instance,
GreeterBean.javalocated inand shown in Example 2.5.InstallDir/samples/integration/jca/inbound-mdb-dispatch/src/demo/ejbExample 2.5. Stateless Session Bean—GreeterBean.java
package demo.ejb; import javax.ejb.CreateException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class GreeterBean implements SessionBean { //------------- Business Methods public String sayHi() { System.out.println("sayHi invoked"); return "Hi from an EJB"; } public String greetMe(String user) { System.out.println("greetMe invoked user:" + user); return "Hi " + user + " from an EJB"; } //------------- EJB Methods public void ejbActivate() { } public void ejbRemove() { } public void ejbPassivate() { } public void ejbCreate() throws CreateException { } public void setSessionContext(SessionContext con) { } }Write an EJB Local Home interface for your SLSB. See, for instance,
GreeterLocalHome.javalocated inand shown in Example 2.6.InstallDir/samples/integration/jca/inbound-mdb-dispatch/src/demo/ejbExample 2.6. GreeterLocalHome.java
package demo.ejb; import javax.ejb.CreateException; import javax.ejb.EJBLocalHome; public interface GreeterLocalHome extends EJBLocalHome { GreeterLocal create() throws CreateException; }Write a deployment descriptor for your SLSB and ensure that it includes:
A
message-drivenelement under theenterprise-beanselement that references to the generic MDB as follows:The value of
ejb-classisorg.apache.cxf.jca.inbound.DispatchMDBMessageListenerImplThe value of
messaging-typeisorg.apache.cxf.jca.inbound.DispatchMDBMessageListener
An
ejb-local-refelement, which is required by the MDB so it can look up the local EJB object reference for your SLSB.
See, for instance, the
ejb-jar.xmllocated inand shown in Example 2.7.InstallDir/samples/integration/jca/inbound-mdb-dispatch/etcExample 2.7. Stateless Session Bean 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>DispatchedGreeterBean</ejb-name> <home>demo.ejb.GreeterHome</home> <remote>demo.ejb.GreeterRemote</remote> <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> <!-- display name--> <activation-config-property> <activation-config-property-name> DisplayName </activation-config-property-name> <activation-config-property-value> DispatchedGreeterEndpoint </activation-config-property-value> </activation-config-property> <!-- service endpoint interface --> <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:9999/GreeterBean </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/DispatchedGreeterLocalHome </activation-config-property-value> </activation-config-property> </activation-config> <ejb-local-ref> <ejb-ref-name>DispatchedGreeterLocalHome</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>demo.ejb.GreeterLocalHome</local-home> <local>demo.ejb.GreeterLocal</local> <ejb-link>DispatchedGreeterBean</ejb-link> </ejb-local-ref> </message-driven> </enterprise-beans> </ejb-jar>
For more information about the supported activation configuration properties, see Inbound Activation Configuration.
If you are using EJB 3.0, the only change you need to make to the deployment descriptor is in the opening
ejb-jarelement. For EJB 3.0 it should read as shown in Example 2.3.Package your application in an EJB JAR file.
Build the Apache CXF JCA Connector RAR file. It must have the following structure and contents:
META-INFdirectory — Must contain thera.xml, located in.InstallDir/samples/integration/jca/inbound-mdb-dispatch/etcRootdirectory — Must contain the JAR files listed underRootin Table 2.1.
The sample application's
build.xmlfile includes a generate.rar target that you can use to build the RAR file (see Example 2.4).Note that the
ra.xmlfileactivation specis set toorg.apache.cxf.jca.inbound.DispatchMDBActivationSpec, which includes atargetBeanJndiNameconfiguration property that enables you to specify your SLSB's JNDI name.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.








