1 Reply Latest reply: Sep 23, 2011 9:27 PM by EJP RSS

    Basic problem in JNDI file system service provider

    861116
      Hi All,

      I knew this is trivial problem to all. I'm missing some minor setup to clear this error message.
      "javax.naming.OperationNotSupportedException : can only bind References or Referanceable objects"

      I'm somewhat newbie to the JNDI world. I have downloaded basic smaple code from internet and downloaded fscontext.jar and providerurl.jar and jndi.jar files and set in the classpath. Pls note i'm not using any other app server here.

      <<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import java.util.Hashtable;
      public Fruit {
      Fruit(String f) { System.out.println("C-tor " + f);
      }
      public class Resolve {
      public static void main(String argv[]) {
      // The user should provide a file to lookup
      if (argv.length != 1) {
      System.err.println("Usage: java Resolve ");
      System.exit(-1);
      }

      String name = argv[0];

      // Here we use the file system service provider
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
      env.put(Context.PROVIDER_URL,"file:///tmp");
      try {
      Context ctx = new InitialContext(env);
      Fruit f = new Fruit(name);
      ctx.rebind(name, f);
      Fruit ff = (Fruit)ctx.lookup(name);
      System.out.println(name + " is bound to: " + ff);
      ctx.close();
      } catch (NamingException e) {
      System.err.println("Problem " + name + ": " + e);
      }
      }
      }


      <<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>
        • 1. Re: Basic problem in JNDI file system service provider
          EJP
          javax.naming.OperationNotSupportedException : can only bind References or Referanceable object
          The message is pretty clear. You can't bind arbitrary objects, you have to wrap them in something the provider will accept: in this case, a Reference or Referenceable. See the JNDI API.

          But I wouldn't spend any more time with the JNDI FS provider. It's really just a toy, not intended to be taken seriously. It might be useful as a pretend LDAP server until you get one, but really, just get one.