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 FUSE Services Framework JCA Connector when it starts and the FUSE Services Framework 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.
One advantage of using this approach is the ability to directly configure the FUSE Services Framework runtime.
FUSE Services Framework includes a working example of this scenario. You can find it in the
directory of your FUSE Services Framework installation.InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl
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 if you want to use the FUSE Services Framework JCA Connector to expose your J2EE application, defined in a WSDL file and implemented as a SLSB, as a Web service:
Set your environment using the fuse_env script, which is located in the
directory.InstallDir/bin
For more information on the fuse_env script, see
Setting Up Your Environment in
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.
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
Write a stateless session bean (SLSB) that implements the service that you want to expose. See, for instance,
GreeterBean.java located in
and shown in Example 2.8.InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/src/demo/ejb
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) {
}
}Write an EJB Local Home interface for your SLSB. See, for instance, GreeterLocalHome.java
located in
and shown in Example 2.9.InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/src/demo/ejb
Example 2.9. WSDL First—GreeterLocalHome.java
package demo.ejb;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
public interface GreeterLocalHome extends EJBLocalHome {
GreeterLocal create() throws CreateException;
}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
and shown in Example 2.10. It shows how you configure logging.InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/etc
For more information on how to configure FUSE Services Framework, see Configuring and Deploying Endpoints.
For information on how to configure FUSE Services Framework security, see Security Guide.
Example 2.10. cxf.xml—Configuring Logging
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
...
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
</beans>Write a deployment descriptor for your SLSB and ensure that it includes:
A message-driven element under the enterprise-beans
element that references to the generic MDB as follows:
The value of the ejb-class element is
org.apache.cxf.jca.inbound.DispatchMDBMessageListenerImpl
The value of the messaging-type element is
org.apache.cxf.jca.inbound.DispatchMDBMessageListener
An ejb-local-ref element, 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.xml file in
and shown in Example 2.11.InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl/etc
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.
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.
Build the FUSE Services Framework JCA Connector RAR file. It must have the following structure and contents:
META-INF directory — Contains the ra.xml,
located in
InstallDir/samples/integration/jca/inbound-mdb-dispatch-wsdl\etc
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).
Deploy the FUSE Services Framework JCA Connector RAR file and your EJB JAR file to your J2EE application server. For details, see Deploying FUSE Services Framework JCA Connector.