Guide To Use EJB With Axis2
Guide To Use EJB With Axis2
Guide To Use EJB With Axis2
http://axis.apache.org/axis2/java/core/docs/ejb-provider.html
public String sayHello(String name) { return "Hello " + name + ", Have a nice day!"; } }
1 of 3
02-01-2012 22:56
http://axis.apache.org/axis2/java/core/docs/ejb-provider.html
Now we have to write application server specific deployment descriptor(s) for the Hello EJB. The following listing shows an example Geronimo/OpenEJB deployment descriptor (openejb-jar.xml)
<?xml version="1.0" encoding="UTF-8"?> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1" xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1" xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"> <enterprise-beans> <session> <ejb-name>Hello</ejb-name> <jndi-name>my/ejb/HelloBean</jndi-name> </session> </enterprise-beans> </openejb-jar>
If you want to test on JBoss, use the following JBoss deployment descriptor (jboss.xml)
<?xml version="1.0"?> <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"> <jboss> <enterprise-beans> <session> <ejb-name>Hello</ejb-name> <jndi-name>my/ejb/HelloBean</jndi-name> </session> </enterprise-beans> </jboss>
Compile the above java classes and bundle the compiled classes and the XML files into a jar file (HelloEJB.jar) as shown below.
HelloEJB.jar | +--META-INF | +--ejb-jar.xml | +--jboss.xml [If you want to deploy on Jboss] | +--openejb-jar.xml [If you want to deploy on Geronimo/Openejb] | +--my +--ejb | +--Hello.class +--HelloBean.class +--HelloBusiness.class +--HelloHome.class
Next, deploy the HelloEJB.jar file onto the appropriate J2EE application server.
2 of 3
02-01-2012 22:56
http://axis.apache.org/axis2/java/core/docs/ejb-provider.html
In the above services.xml file, replace the [URL] and [Context Factory Class Name] with valid values as follows: i.e. If the EJB is deployed on Geronimo: Replace [URL] by 127.0.0.1:4201 Replace [Context Factory Class Name] by org.openejb.client.JNDIContext For Jboss: Replace [URL] by jnp://localhost:1099 Replace [Context Factory Class Name] by org.jnp.interfaces.NamingContextFactory Bundle the HelloBeanService.wsdl, services.xml, remote interface class and home interface class as illustrated below:
HelloBeanService.aar | +--META-INF | +--services.xml | +--lib | +--[jars used by the ejb client eg.initial context factory classes] | +--my +--ejb +--Hello.class +--HelloBusiness.class +--HelloHome.class
The lib directory of HelloBeanService.aar must contain all the libraries needed to access the EJB. If the EJB is deployed on Geronimo, add the following jar files to the lib directory. cglib-nodep-2.1_3.jar geronimo-ejb_2.1_spec-1.0.1.jar geronimo-j2ee-jacc_1.0_spec-1.0.1.jar geronimo-kernel-1.1.jar geronimo-security-1.1.jar openejb-core-2.1.jar For JBoss add the following jar files. jnp-client.jar jboss-client.jar jboss-common-client.jar jboss-remoting.jar jboss-serialization.jar jboss-transaction-client.jar concurrent.jar jbosssx-client.jar jboss-j2ee.jar Deploy HelloBeanService.aar on an Axis2 server. Now you can access the Hello EJB through Web services. Since our EJB message receivers extend RPC message receivers, org.apache.axis2.rpc.client.RPCServiceClient can be used to invoke the service as illustrated in the following code fragment.
... RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/HelloBeanService"); options.setTo(targetEPR); QName hello = new QName("http://ejb.my/xsd", "sayHello"); Object[] helloArgs = new Object[] {"John"}; System.out.println(serviceClient.invokeBlocking(hello, helloArgs).getFirstElement().getText()); ...
3 of 3
02-01-2012 22:56