Naming.list(
thoste Nov 9, 2004 2:48 PMJNDI show exceptions as well:
Source code:
try {
Hashtable hashtable = new Hashtable(2);
hashtable.put (Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
hashtable.put (Context.PROVIDER_URL, "rmi://localhost:1099");
InitialContext ictx = new InitialContext(hashtable);
NamingEnumeration children = ictx.list("");
System.out.println(" Available RMI objects:");
int i = 0;
while (children.hasMore()) {
NameClassPair nc = (NameClassPair) children.next();
System.out.println(" - Object[" + i + "]=" + nc.getName() + " " + nc.getClassName()); }
..... }
yields:
MyClient exception: null
javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketException: Software caused connection abort: recv failed]
at com.sun.jndi.rmi.registry.RegistryContext.list(RegistryContext.java:181)
at com.sun.jndi.rmi.registry.RegistryContext.list(RegistryContext.java:186)
at javax.naming.InitialContext.list(InitialContext.java:387)
at test.rmi.simple.MyClient.main(MyClient.java:37)
if I replace
hashtable.put (Context.PROVIDER_URL, "rmi://localhost:1099");
by
hashtable.put (Context.PROVIDER_URL, "jnp://localhost:1099");
as suggested then I got:
MyClient exception: rmiURLContext: name is not an RMI URL: jnp://localhost:1099
java.lang.IllegalArgumentException: rmiURLContext: name is not an RMI URL: jnp://localhost:1099
at com.sun.jndi.url.rmi.rmiURLContext.getRootURLContext(rmiURLContext.java:50)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:182)
at com.sun.jndi.url.rmi.rmiURLContextFactory.getUsingURL(rmiURLContextFactory.java:54)
at com.sun.jndi.url.rmi.rmiURLContextFactory.getObjectInstance(rmiURLContextFactory.java:39)
at com.sun.jndi.rmi.registry.RegistryContextFactory.URLToContext(RegistryContextFactory.java:85)
at com.sun.jndi.rmi.registry.RegistryContextFactory.getInitialContext(RegistryContextFactory.java:52)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.(InitialContext.java:195)
at test.rmi.simple.MyClient.main(MyClient.java:30)