• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

Using EJB with OAS

How do you get the initial context using an Oracle Application Server. The documentation is as below, but I get an error:
'javax.naming.NoInitialContextException: Cannot instantiate class: oracle.oas.naming.jndi.RemoteInitCtxFactory [Root exception is java.lang.ClassNotFoundException: oracle.oas.naming.jndi.RemoteInitCtxFactory]'


Documentation Example

Hashtable env = new Hashtable();
LookupHome lookupHome = null;

env.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.oas.naming.jndi.RemoteInitCtxFactory");
env.put(Context.PROVIDER_URL,"oas://SFP1BET09:8888/ejb/Lookup/LookupHome");

try
{
     Context ctx = new InitialContext(env);
     lookupHome = (LookupHome) ctx.lookup              ("oas://SFP1BET09:8888/Lookup/LookupHome");          
}
0
LeeShaw
Asked:
LeeShaw
1 Solution
 
userquinCommented:
Hi:

If you download JDeveloper 3.1 or later (3.2.3 is better) you have a snippet wizard to
do this simplifying this work very much.

This is the descriptor file AlarmasEJBRemote.dd for my EJB.

SessionBean com.fi2net.intereconomia.alarmas.ejb.AlarmasEJBClass
{
  BeanHomeName = AlarmasEJBRemote;
  HomeInterfaceClassName = com.fi2net.intereconomia.alarmas.ejb.AlarmasEJBHome;
  RemoteInterfaceClassName = com.fi2net.intereconomia.alarmas.ejb.AlarmasEJBRemote;

  SessionTimeout = 0;
  StateManagementType = STATELESS_SESSION;
  TransactionAttribute = TX_SUPPORTS;

  EnvironmentProperties
  {
    dblogin=an_user;
    dbpasswd=a_password;
    dbsid=intereco;
    dbport=1521;
    dbhost=cleptus.fi2net.com;
    driver=thin;
    sql_trace=false;
  }
}
 
This is a bean wrapper to an EJB.

// Copyright (c) 2000 FI2
package com.fi2net.intereconomia.alarmas.beans;

import javax.naming.*;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletConfig;

import java.util.*;

import com.fi2net.intereconomia.alarmas.ejb.*;
import com.fi2net.intereconomia.alarmas.comun.*;

/**
 * Clase proxy sobre el EJB de alarmas.
 * @author Dpto. Desarrollo Internet de FI2.
 * @version 1.0.
 */
public class BeanAlarmas {

  /**
   * Referencia al interfaz remoto del EJB.
   */
  private AlarmasEJBRemote remote = null;

  /**
   * Constructor por defecto de la clase.
   */
  public BeanAlarmas() {

    super();

    try {
      create();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * Levanta el EJB.
   * @exception javax.naming.NamingException Si no se encuentra el EJB por el nombre.
   * @exception javax.ejb.CreateException Si se produce un error en el OAS.
   * @exception java.rmi.RemoteException Si se produce un error en el OAS.
   */
  private void create() throws NamingException, CreateException, RemoteException {

    String ejbUrl = "oas://psyduck.fi2net.com:8080/Alarmas/AlarmasEJBRemote";
    //String ejbUrl = "oas://nidorina.fi2net.com:80/Foros1/ForosVotosEJBRemote";

    // Setup the environment
    Hashtable environment = new Hashtable();

    // Turn JNDI on to OAS
    environment.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "oracle.oas.naming.jndi.RemoteInitCtxFactory");

    Context ctx = new InitialContext(environment);
    // Lookup the URL
    AlarmasEJBHome homeInterface = (AlarmasEJBHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup(ejbUrl), AlarmasEJBHome.class);
    //FinanciacionEJBHome home = (FinanciacionEJBHome)javax.rmi.PortableRemoteObject.narrow(ic.lookup(ejbUrl), FinanciacionEJBHome.class);

    //System.out.println("Create...");
    remote = homeInterface.create();
  }

  /**
   * Constructor por defecto de la clase.
   */
  public BeanAlarmas(ServletConfig config) {

    super();

    try {
      create(config);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Levanta el EJB.
   * @exception javax.naming.NamingException Si no se encuentra el EJB por el nombre.
   * @exception javax.ejb.CreateException Si se produce un error en el OAS.
   * @exception java.rmi.RemoteException Si se produce un error en el OAS.
   */
  private void create(ServletConfig config) throws NamingException, CreateException, RemoteException {

            String ejb_host = config.getInitParameter("ejbHost");
            String ejb_port = config.getInitParameter("ejbPort");
        //String ejb_application_name = config.getInitParameter("ejb_application_name");
            //String ejb_name = config.getInitParameter("ejb_name");

    if(ejb_host == null || ejb_port == null)
      throw new CreateException("Error al acceder a los par?metros de configuraci?n");

    String ejbUrl = "oas://"+ejb_host+":"+ejb_port+"/Alarmas/AlarmasEJBRemote";

    // Setup the environment
    Hashtable environment = new Hashtable();

    // Turn JNDI on to OAS
    environment.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "oracle.oas.naming.jndi.RemoteInitCtxFactory");

    Context ctx = new InitialContext(environment);
    // Lookup the URL
    AlarmasEJBHome homeInterface = (AlarmasEJBHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup(ejbUrl), AlarmasEJBHome.class);
    //FinanciacionEJBHome home = (FinanciacionEJBHome)javax.rmi.PortableRemoteObject.narrow(ic.lookup(ejbUrl), FinanciacionEJBHome.class);

    //System.out.println("Create...");
    remote = homeInterface.create();
  }
 
  // Here you put the wrapper methods to EJB.
  ...
  ...
  ...
}

Bye.

J.
0
 
sudhakar_koundinyaCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to userquin]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now