This is a continuation of Calling EJB 3 from JRuby client and Calling JBoss EJB 3 from JRuby client. This post will show how to do it with Weblogic application server 10.
1. project directory structure:
Note that the jndi name I'm using below is not user-friendly, but I found this is the one that always worked. I also tried using the default jndi name for weblogic EJB3 but didn't find any in admin console's View JNDI Tree. Weblogic doesn't seem to fully honor
Alternatively, you can deploy and start the ejb app with weblogic.Deployer class:
9. run JRuby client. Before running the script, we need to set the environment variable CLASSPATH, which is of course different from the one for glassfish and JBoss.
1. project directory structure:
C:\simple-ejb3> tree /A /F2. create EJB remote business interface and bean class under src\foo:
+---classes
| \---foo
\---src
\---foo
Client.java
FooBean.java
FooRemote.java
package foo;
import javax.ejb.*;
@Remote
public interface FooRemote {
public String echo(String s);
}
3 createJRuby script (
package foo;
import javax.ejb.*;
@Stateless
public class FooBean implements FooRemote {
public String echo(String s) {
return s;
}
}
testEJBWeblogic.rb
) or java client, which is almost identical to the one for glassfish and JBoss, except the default jndi name. Note that the jndi name I'm using below is not user-friendly, but I found this is the one that always worked. I also tried using the default jndi name for weblogic EJB3 but didn't find any in admin console's View JNDI Tree. Weblogic doesn't seem to fully honor
mappedName
either. When I specified mappedName="FooBean", the actual jndi name after deployment is FooBean/foo.FooRemote, with the remote business interface name appended to mappedName value.package foo;==== testEJBWeblogic.rb ====
import javax.ejb.*;
import javax.naming.*;
public class Client {
public static void main(String[] args) throws Exception {
Context ic = new InitialContext();
Object obj = ic.lookup("_appsdir_foo-ejb_jarfoo-ejb_jarFooBean_FooRemote");
//the above jndi name is the default one used by weblogic server.
//You can check ejb jndi-name in
//admin console | environment | servers | MedRecServer(admin) | view JNDI tree
//You can also customize the jndi name with @Stateless(mappedName="myname")
FooRemote foo = (FooRemote) obj;
String s = foo.echo("Hello Foo!");
System.out.println(foo + " echo returned " + s);
}
}
4. compile java src. An environment variable WL_HOME is set for convenience but it's not required.
require 'java'
include_class 'javax.naming.InitialContext'
ic = InitialContext.new
foo = ic.lookup("_appsdir_foo-ejb_jarfoo-ejb_jarFooBean_FooRemote")
result = foo.echo("This is foo!")
puts "Calling the EJB 3 : #{foo} returned #{result}"
C:\simple-ejb3\classes> set WL_HOME=C:\bea\wlserver_10.05. start Weblogic server. I will use the sample medrec server to deploy the EJB:
C:\simple-ejb3\classes> javac -d . -classpath %WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\api.jar;. ..\src\foo\*.java
%WL_HOME%\samples\domains\medrec\startWebLogic6. package and autodeploy ejb-jar. We can combine the 2 steps in 1 by using %WL_HOME%\samples\domains\medrec\autodeploy as the destdir:
C:\simple-ejb3\classes>7. start the EJB3 in the admin console http://localhost:7011/console, login with username "weblogic" and password "weblogic". Select Deployments on the left, then _appsdir_foo-ejb_jar (autodeployed) on the right, and click start button.
jar cvf %WL_HOME%\samples\domains\medrec\autodeploy\foo-ejb.jar
foo\FooBean.class foo\FooRemote.class
Alternatively, you can deploy and start the ejb app with weblogic.Deployer class:
java -cp %WL_HOME%\server\lib\weblogic.jar weblogic.Deployer -adminurl t3://localhost:7011 -username weblogic -password weblogic -deploy foo-ejb.jar8. prepare jndi.properties somewhere in client classpath, e.g., simple-ejb3\classes directory:
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactoryNote that weblogic server listens on port 7011 for iiop, t3 and http protocols. So using t3://localhost:7011 works as well. If you use the sample wl_server instead of medrec server, the default port is 7001.
java.naming.provider.url=iiop://localhost:7011
9. run JRuby client. Before running the script, we need to set the environment variable CLASSPATH, which is of course different from the one for glassfish and JBoss.
set CLASSPATH=%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\api.jar;C:\simple-ejb3\classesThe test output:
jruby testEJB.rb
Calling the EJB 3 : Delegate(602878) [weblogic.iiop.IOR[RMI:foo.FooBean_my4bwg_FooRemoteIntf:0000000000000000] @localhost:7011, <337, null>] returned This is foo!The command to run java client (no -cp nor -classpath is needed since we already set CLASSPATH:
java foo.ClientTechnorati Tags: EJB3, weblogic, JRuby