Solved

Using EJB with OAS

Posted on 2001-07-04
2
334 Views
Last Modified: 2013-11-24
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
Comment
Question by:LeeShaw
2 Comments
 
LVL 2

Accepted Solution

by:
userquin earned 50 total points
Comment Utility
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
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now