0 Replies Latest reply on Oct 13, 2003 4:52 PM by akperry

    JNDI From Tomcat

    akperry

      Hi,

      I am trying to get a JNDI Context to a JBoss 3.0.8 (Jetty) instance from a separate instance of Tomcat 4.1.27 (both running on the same machine). The following code works fine from a stand-alone jar file (with the following jars added to the class path: xercesImpl.jar, xmlParserAPIs.jar, jboss-client.jar, jboss-common-client.jar, jboss-j2ee.jar, jbosssx-client.jar, jnp-client.jar, log4j.jar). However, when I envoke the Lookup.test() method from a servlet I get a naming exception whose getMessage() method returns null. Any ideas why? (Yes, 1098 is correct, I tried using 1099 in the code and the JBoss instance with the same result).

      public class Lookup {

      public InitialContext getInitialContext() throws NamingException {
      Hashtable props = new Hashtable();
      InitialContext initial = null;

      props.put(
      Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");

      props.put(Context.PROVIDER_URL, "jnp://localhost:1098");

      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

      initial = new InitialContext(props);

      return (initial);
      }

      public String test() {
      BillsServiceHome billsServiceHome = null;
      BillsService service = null;
      InitialContext initial = null;
      Collection results = null;
      Object[] array = null;
      StringBuffer result = new StringBuffer();

      try {
      initial = getInitialContext();

      // Locate the home interfaces.
      billsServiceHome =
      (BillsServiceHome) initial.lookup("BillsService");

      service = billsServiceHome.create();

      // Retrieve the list of bills.
      results = service.getUserList();

      array = results.toArray();

      for (int i = 0; i < array.length; i++) {
      result.append(array);
      }

      } catch (NamingException ne) {
      System.out.println("Lookup: NamingException\n" + ne.getMessage());
      } catch (RemoteException re) {
      System.out.println("Lookup: \n" + re.getMessage());
      } catch (CreateException ce) {
      System.out.println("Lookup: \n" + ce.getMessage());
      }

      return (result.toString());
      }

      public static void main(String[] args) {
      String data = null;
      Lookup lookup = new Lookup();

      data = lookup.test();

      System.out.println(data);
      }