3 Replies Latest reply on Sep 4, 2001 1:11 PM by 3004

    Calling an EJB deployed in OC4J from Java Stored Proc in Oracle

    3004
      Hello!
      Trying to make a call to an EJB deployed in OCJ4 from a oracle java stored proc. After loaded orion.jar and crimson.jar lib into SCOTT schema, I can't get the JNDI Context working because of this error:

      ============================================
      javax.naming.NoInitialContextException: Cannot instantiate class:
      com.evermind.server.ApplicationClientInitialContextFactory. Root exception is
      java.lang.ClassNotFoundException:
      com/evermind/server/ApplicationClientInitialContextFactory
      at java.lang.Class.forName0(Class.java)
      at java.lang.Class.forName(Class.java)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:45)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java)
      at javax.naming.InitialContext.init(InitialContext.java)
      at javax.naming.InitialContext.<init>(InitialContext.java)
      ===============================

      I did load the java with "loadjava" with on time with the "resolve" option and time time no option and still no working.

      Here is the EJB client code:
      =======================================

      import java.sql.*;
      import java.util.*;
      import javax.naming.*;
      import com.evermind.server.ApplicationClientInitialContextFactory;

      class EmpRemoteCall {

      public static void main(String[] args) {
      System.out.println(getEmpName());
      }


      public static String getEmpName() {


      String ejbUrl = "java:comp/env/ejb/Emp";
      String username = "admin";
      String password = "admin";
      Hashtable environment = new Hashtable();

      environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationClientInitialContextFactory");
      environment.put(Context.PROVIDER_URL, "ormi://127.0.0.1/testemp");
      environment.put(Context.SECURITY_PRINCIPAL, username);
      environment.put(Context.SECURITY_CREDENTIALS, password);

      //environment.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
      //environment.put(javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");

      com.kboum.sertir.essais.EmpHome homeInterface = null;
      try {
      Class.forName("com.evermind.server.ApplicationClientInitialContextFactory", true, ClassLoader.getSystemClassLoader());
      System.out.println("Creating an initial context");
      Context ic = new InitialContext(environment);
      System.out.println("Looking for the EJB published as 'java:comp/env/ejb/Emp'");
      homeInterface = (com.kboum.sertir.essais.EmpHome) ic.lookup(ejbUrl);
      }
      catch (CommunicationException e) {
      System.out.println("Unable to connect: " + ejbUrl);
      e.printStackTrace();
      //System.exit(1);
      }
      catch (NamingException e) {
      System.out.println("Exception occurred!");
      System.out.println("Cause: This may be an unknown URL, or some" +
      " classes required by the EJB are missing from your classpath.");
      System.out.println("Suggestion: Check the components of the URL," +
      " and make sure your project includes a library containing the" +
      " EJB .jar files generated by the deployment utility.");
      e.printStackTrace();
      //System.exit(1);
      }
      catch (ClassNotFoundException e) {
      System.out.println("Unable to connect: " + ejbUrl);
      e.printStackTrace();
      //System.exit(1);
      }
      try {
      System.out.println("Creating a new EJB instance");
      com.kboum.sertir.essais.Emp remoteInterface = homeInterface.findByPrimaryKey(Integer.valueOf("7369"));
      System.out.println(remoteInterface.getENAME());
      System.out.println(remoteInterface.getSAL());
      remoteInterface.setSAL(2);
      System.out.println(remoteInterface.getSAL());

      return remoteInterface.getENAME();


      }
      catch (Exception e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      }

      return "error";
      }

      }

      null