EJB Lookup, Connection Refused.
troyrudolph Apr 3, 2002 11:47 AMI could use a little help, please. When I try to connect to a JBoss running on a remote system, I always get "connection refused" when connecting to JBoss. It works fine when I run the program on the same machine as JBoss. I'm sure I'm missing something obvious. Thanks in advance for any help.
I have JBoss 2.4.4 with J2SDK 1.4.0 running on RedHat 6.2. I have a simple client program (see below) running on a Win2K with J2SDK 1.4.0.
Here's the exception information. Note the reference to 127.0.0.1 even though the client specified 130.200.138.11, the remote machine.
F:\dev\EJBClient>java EJBClient
locating Calculator
javax.naming.CommunicationException. Root exception is java.rmi.ConnectExceptio
n: Connection refused to host: 127.0.0.1; 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.invoke(UnicastRef.java:101)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at EJBClient.main(EJBClient.java:22)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:295)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.(Socket.java:290)
at java.net.Socket.(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:122)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
... 8 more
Here's the client program - no rocket science.
public class EJBClient
{
public static void main(String [] args)
{
try
{
Context jndiContext = getInitialContext();
System.out.println("locating Calculator" );
Object obj = jndiContext.lookup("Calculator");
System.out.println("getting the home interface" );
CalculatorHome home =
(CalculatorHome) javax.rmi.PortableRemoteObject.narrow(obj, CalculatorHome.class);
Calculator calc = home.create();
System.out.println("created it!");
int i = calc.add( 2, 2 );
System.out.println( "2 + 2 = " + i );
}
catch (Exception ex){ex.printStackTrace();}
}
public static Context getInitialContext()
throws javax.naming.NamingException
{
Properties p = new Properties();
// JBoss
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "jnp://130.200.138.11:1099");
return new InitialContext(p);
}
}
Please let me know what I have done wrong. Thanks.