Pre:
1) JBoss 4.2.3 deployed on a separate IP/process/machine (lets assume its deployed on IP 10.0.21.100)
2) JBoss 4.2.3 has a @Stateless bean com.app.impl.TheServiceImpl deployed in an enterprise application "app".
3) This bean implements @Remote interface com.app.api.TheService which contains a method public String theMethod( String arg ).
4) The service/bean gets a binding with name "app/TheServiceImpl/remote" inside JBoss 4.2.3
How to call the theMethod() remote method from a JBoss 7.2 ?
1) JBoss 7.2 must have a module defined as follows:
- create dir JBOSS_HOME/modules/org/jboss/client/legacy/main
- put the following module.xml file into that directory:
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.jboss.client.legacy"> <resources> <resource-root path="jbossall-client.jar" /> <resource-root path="theLegacy.jar" /> </resources> <dependencies> <module name="javax.api" /> </dependencies> </module>
- copy to that folder as well jbossall-client.jar file from the JBOSS_4_2_3_HOME/client directory
- jar theLegacy.jar must contain the com.app.api.TheService and the class that makes the remote call (see 2)
2) The class com.app.legacy.LegacyProxy is created and added to the theLegacy.jar file as follows:
package com.app.legacy; public class LegacyProxy { public static String callTheMethod( String arg ) { try { final Hashtable environment = new Hashtable(); environment.put( javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" ); environment.put( javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" ); environment.put( javax.naming.Context.PROVIDER_URL, "jnp://10.0.21.100:1099" ); // remote machine IP final javax.naming.InitialContext context = new javax.naming.InitialContext( environment ); com.app.TheService remoteO = (com.app.TheService) context.lookup( "app/TheServiceImpl/remote" ); // ejb-name return remoteO.theMethod( arg ); } catch ( NamingException e ) { throw new RuntimeException( "Failed to lookup remote ejb", e ); } } }
3) Now in the application that needs the remote method to be called we need to declare the org.jboss.client.legacy module dependency inside jboss-deployment-structure.xml file as follows:
<dependencies> .. <module name="org.jboss.client.legacy" /> </dependencies>
(Of course the same can be achieved by adding "Dependencies: com.ek.legacy" to the MANIFEST.MF file in deployment)
4) Now inside the above application it shall be possible to call com.app.legacy.LegacyProxy.callTheMethod( "x" ) without any problems.
Comments