Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using EJB with OAS

Posted on 2001-07-04
2
Medium Priority
?
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
userquin earned 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

636 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