GlassFish v3 calling Weblogic 11g

Markus Eisele
3
I was playing around with interoperability problems lately. The question was: How to call an EJB deployed on Weblogic 11g (WLS 10.3.2.0) from GlassFish v3? What looks simple on the first hand, is not too easy.
Here are the steps to take.

First of all, it is not handy to put any wls libraries into GF's classloader. Therefore you should stick to the most basic communication method available. This is RMI-IIOP. Ok. Let's start.

You need an EJB to deploy to WLS. Of course, this has to be a EJB 3.0. I wrote a quite simple one called Logger. It has one business method void logString(String message) which gets a string and puts it to stdout.
If you are going to use RMI-IIOP, you have to have EJB 2.x style remote interfaces.
That should look similar to this:


@Stateless(mappedName = "Logger")
@Remote(LoggerRemote.class)
@RemoteHome(LoggerRemoteHome.class)
public class Logger implements LoggerRemote


LoggerRemote is the EJB 3.x business interface. LoggerRemoteHome is the EJB 2.x EJBHome which creates the LoggerRemoteObject EJBObject. Put all interfaces into a separate client project (ejb-client-jar).
If everything is ready, deploy the ejb. Now it is time to compile the Stubs and Skeletons for your ejb-client-jar.
Take your jar or ear and put it in weblogic.appc compiler.

java weblogic.appc ejbinteropEAR.ear

This will generate the ejbinteropClient.jar with all needed additional classes. Start your favorite IDE for your GF projects and setup a client project. I badly needed to try some Servlet 3.0 features and wrote a small
@WebServlet(name = "InterobTest", urlPatterns = {"/InterobTest"}) servlet for that.
The ejbinteropClient.jar needs to be in your projects classpath.
First thing to do is, to build an InitialContext.

// Build Properties Object
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
h.put(Context.PROVIDER_URL,
"iiop://localhost:7001");
h.setProperty("org.omg.CORBA.ORBInitialHost",
"localhost");
h.setProperty("org.omg.CORBA.ORBInitialPort",
"7001");
// Get InitialContext with Properties
InitialContext ic = new InitialContext(h);

Now you are half way through. Now lookup your remote object

Object home = ctx.lookup(JNDI_NAME);

This took some time. Ok, not having the java.net forums online since a few days did realy not speed this up.
Anyway, the magic in this is the JNDI_NAME.
It is constructed out of several parts:


String JNDI_NAME =
"corbaname:iiop:localhost:7001#"+
"Logger#ejbinterop.LoggerRemoteHome";


First part is the static part containing your host and port of the target WLS instance. Second is the binding name for your RemoteHome interface in Weblogic Server's JNDI tree.



The only thing left to do is to narrow your RemoteHome from the stubclass


LoggerRemoteHome home =(LoggerRemoteHome)
PortableRemoteObject
.narrow(home,
LoggerRemoteHome.class);


and create your LoggerRemoteObject on which to call your business method on.


LoggerRemoteObject obj= home.create();
obj.logString("Testlog");


Now you are done! A few simple lines of code, which could cause you to get grey hair if you are missing any part.
For me it was quite helpfull, to turn on all related debug settings in WebLogic server. Go to Environment / Servers / Your Server / Debug and enable all needed scopes and attributes. If the call is successfull, you see some detailed debug information on the stdout (don't forget to change the log level!).

Post a Comment

3Comments

  1. Can you please provide the complete source code of the Logger bean anlong with the interfaces?
    Thanks.

    ReplyDelete
  2. Did you try the other way round? I mean "How to call an EJB deployed on GlassFish v2.1 from WLS 10"

    ReplyDelete
  3. Please check the next post in this month:
    http://blog.eisele.net/2009/12/weblogic-11g-calling-glassfish-v3.html
    Thanks,
    M

    ReplyDelete
Post a Comment