Hand-Coding Dynamic Discovery of EJB-Deployed AppModule

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:24:57 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Hand-Coding Dynamic Discovery of EJB-Deployed AppModule

When your remote JClient application needs to establish a connection to its server-side, EJB-deployed application module, normally we handle all of the details of the "Service Locator" J2EE design pattern for you. However, through JDeveloper 10g, we only support looking up the EJB Home for your application module using a fixed ORMI port number (which is "baked" into the client-side configuration. If you are connecting to an Oracle AS machine that has a cluster setup, you will likely want to perform dynamic discovery of the server-side EJB.

At the OC4J/RMI level, this boils down to using an ORMI URL with the prefix "lookup:" prepended to the front. However at the moment at the BC4J level, it's not quite as straightforward as just adding the "lookup:" because our customized JNDI context implementation does not yet support this. A little hand-coding is necessary to use the com.evermind.server.rmi.RMIInitialContextFactory initial context factory instead (which does support the dynamic lookup).

Using some helper code like this, we can customize the service-locator implementation that is normally something we don't need to understand that BC4J does for us automatically.

package test;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jbo.ApplicationModule;
import oracle.jbo.client.remote.ejb.ApplicationModuleProxy;
import test.common.ejb.beanmanaged.TestModuleHome;
public class TestClient {
private static final String EJB_BEAN_NAME = "TestModuleBMBean";
  public static ApplicationModule getAppModule() {
    try {
      Context ctx = getContext();
      TestModuleHome home = (TestModuleHome) ctx.lookup(EJB_BEAN_NAME);
      ApplicationModule am = ApplicationModuleProxy.create(home,
          null /* or some client props */);
      am.getTransaction().connectToDataSource(null, "jdbc/shuttleDS", false);
      return am;
    }
    catch (NamingException nex) {
      return null;
    }
  }
  private static InitialContext getContext() {
    try {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,
        "com.evermind.server.rmi.RMIInitialContextFactory");
      env.put(Context.SECURITY_PRINCIPAL, "admin");
      env.put(Context.SECURITY_CREDENTIALS, "welcome");
      /*
      * PUT YOUR CUSTOM lookup: URL HERE
      */
      env.put(Context.PROVIDER_URL, "ormi://localhost/Project1EJB");
      return new InitialContext(env);
    }
    catch (NamingException e) {
      return null;
    }
  }
}

The lookup:ormi:// URL goes where the code above sets the PROVIDER_URL property.

In order for a JClient application to then construct its JUApplication object using the application module returned using this customized approach above, you would just replace the standard JUApplication constructor line in your main form, to look something like this:

JUApplication app = new JUApplication(TestClient.getAppModule());

NOTE: You'll need to pass the set of parameters in a hashtable to the ApplicationModuleProxy create() method that normally would be read automatically from your configuration in your bc4j.xcfg file.



© Copyright 2008 Steve Muench. Click here to send an email to the editor of this weblog.
Last update: 2/3/2008; 9:24:57 PM.