1 Reply Latest reply on Feb 12, 2006 5:21 AM by shaobz

    ????Why can?t I lookup the complex object in JBOSS? ????

    shaobz

      I have code one small program. It can run successfully in main() method. Then I want to access it through servlet/jsp, but it always throw the Exception:

      javax.naming.CommunicationException [Root exception is java.net.MalformedURLException: no protocol: Files/Apache]

      the server which I use is ?jboss-4.0.3SP1?

      the BEAN which I define is :

      package com.mycompany;
      import java.io.Serializable;
      import java.rmi.Remote;
      import java.util.Hashtable;
      import javax.naming.InitialContext;

      public class MyBean implements Serializable,Remote{

      private static String foo ="";
      private static int bar=100000;

      public String getFoo() {
      return (this.foo);
      }

      public void setFoo(String foo) {
      this.foo = foo;
      }

      public int getBar() {
      return (this.bar);
      }

      public void setBar(int bar) {
      this.bar = bar;
      }

      public static void main(String[] args) {
      try {

      Hashtable ht = new Hashtable();
      ht.put("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      ht.put("java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");
      ht.put("java.naming.provider.url", "jnp://localhost:1099");
      InitialContext ic = new InitialContext(ht);

      ic.bind("jndiname", "----hello--jndi----");
      String obj = (String) ic.lookup("jndiname");
      System.out.println("-----------------212-the result of lookup is--:" + obj+"");
      ic.unbind("jndiname");

      MyBean mybean=new MyBean();
      ic.bind("jndiname2", mybean);
      MyBean bean=(MyBean)ic.lookup("jndiname2");
      System.out.println("------11------the result of lookup is--:" + bean.getBar()+"");
      ic.unbind("jndiname2");

      } catch (Exception e) {
      e.printStackTrace();
      }
      }


      }

      It can run very well in this main() method, but can not run in the servlet, the servlet code is:

      try {

      Hashtable ht = new Hashtable();
      ht.put("java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      ht.put("java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");
      ht.put("java.naming.provider.url", "jnp://localhost:1099");
      InitialContext ic = new InitialContext(ht);

      ic.bind("jndiname", "----hello--jndi----");
      String obj = (String) ic.lookup("jndiname");
      out.println("-----------------212-the result of lookup is--:" + obj+"");
      ic.unbind("jndiname");

      MyBean mybean=new MyBean();
      ic.bind("jndiname2", mybean);
      MyBean bean=(MyBean)ic.lookup("jndiname2");
      out.println("------11------the result of lookup is--:" + bean.getBar()+"");
      ic.unbind("jndiname2");

      } catch (Exception e) {
      e.printStackTrace();
      }