tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Russ Leong" <r...@kikuze.com>
Subject Configuring JNDI for tomcat
Date Wed, 16 Jun 2004 04:23:48 GMT
Hi, I am trying to configure tomcat 5.025 on W2K to be accessible by other machines via JNDI.
I have tried using the registry method but am getting Connection refused. And when I try to
filesystem approach I get NameNotFoundException.

I am new to both Tomcat and JNDI and hope to get some pointers. 

The way I'm testing now(local machine first) is I run tomcat with my server resource which
I want to make accessible, then I try to "connect" by running my client code via the java
command on my command prompt.

The following is how I am trying with the registry approach -

(jndi.properties in C:\j2sdk1.4.2_04\jre\lib)
java.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory
java.naming.provider.url=rmi:localhost:1099

(iccs.xml in C:\jakarta-tomcat-5.0.25\conf\Catalina\localhost)
<Resource name="bean/Jndi" auth="Container" type="test.JndiBean"/> 
 <ResourceParams name="bean/Jndi"> 
   <parameter>
     <name>factory</name>
     <value>org.apache.naming.factory.BeanFactory</value> 
   </parameter> 
   <parameter> 
     <name>bar</name> 
     <value>23</value> 
   </parameter> 
</ResourceParams> 

(JndiBean class in C:\jakarta-tomcat-5.0.25\webapps\iccs\WEB-INF\classes\test)
package test;
public class JndiBean {
    private String foo = "Default Foo";
    public String getFoo()          { return (this.foo); }
    public void setFoo(String foo)  { this.foo = foo; }
    
    private int bar = 0;
    public int getBar()             { return (this.bar); }
    public void setBar(int bar)     { this.bar = bar; }
}

(JndiClient class in C:\jakarta-tomcat-5.0.25\webapps\iccs\WEB-INF\classes\test)
package test;
import javax.naming.*;

public class JndiClient {
    public static void main(String[] args) {
        try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            JndiBean bean = (JndiBean) envCtx.lookup("bean/Jndi");
            System.out.println("foo = " + bean.getFoo() + ", bar = " + bean.getBar());
        }
        catch( Exception e ) { e.printStackTrace(); }
    }
}

And here is the error that I get
C:\>java -classpath C:\jakarta-tomcat-5.0.25\webapps\iccs\WEB-INF\classes test.JndiClient
javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection
refused to host: local
host; nested exception is:
        java.net.ConnectException: Connection refused: connect]
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:92)
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:98)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at test.JndiClient.main(JndiClient.java:9)
Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception
is:
        java.net.ConnectException: Connection refused: connect
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
        at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:88)
        ... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
        at java.net.Socket.connect(Socket.java:452)
        at java.net.Socket.connect(Socket.java:402)
        at java.net.Socket.<init>(Socket.java:309)
        at java.net.Socket.<init>(Socket.java:124)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
        ... 8 more

Deeplyy appreciate any help from anyone. Thanks.
Russ
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message