Solved

Using EJB with OAS

Posted on 2001-07-04
2
341 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
ID: 6252639
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
ID: 9017856
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 video teaches viewers about errors in exception handling.

808 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