Hi everbody!
First, sorry for my english.
I have a problem that I trying to solve on last 5 days, but I don't found the anwser in anywhere of Internet. Yes, I read many tutorials, forums and Oracle Documentation, I understood the mechanism used in the examples and it works when the client and the EJB are in the same machine, therefore when I put the EJB project in different machine (a server), the problem came.
In my client application, I included all of .jar files that are in GLASSFISH_HOME/glassfish/modules/ and I don't forgot the GLASSFISH_HOME/glassfish/lib/gf-client.jar that are included too.
The command "telnet www.myremotehost.com 3700" works fine, I obtain a connection, so I concluded the host and port are able to receive connections.
This is my EJB code which just get the IP address from the server:
//TestEJBRemote.java
package com.test;
public interface TestEJBRemote {
public String message();
}
//TestEJB.java
package com.test;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.ejb.Remote;
@Stateless(name="TesteEJB", mappedName="ejb/TesteEJB")
@Remote(TestEJBRemote.class)
public class TestEJB implements TestEJBRemote {
@Override
public String message() {
String msg = "IP: ";
try {
msg += InetAddress.getLocalHost().getHostAddress() + " / " + InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
Logger.getLogger(TestEJB.class.getName()).log(Level.SEVERE, null, ex);
}
return msg;
}
}
And here it's my client code:
package test.client;
import com.test.TestEJBRemote;
import javax.naming.InitialContext;
public class Main {
public static void main(String[] args) {
try {
InitialContext ctx = new InitialContext();
TestEJBRemote remote = (TestEJBRemote) ctx.lookup( "java:global/teste-ejb/TesteEJB" );
System.out.println( remote.message() );
} catch (Exception e) {
e.printStackTrace();
}
}
}
When I execute the client application I use the following parameters
-Dorg.omg.CORBA.ORBInitialHost=www.myremotehost.com
-Dorg.omg.CORBA.ORBInitialPort=3700
but nothing occur, it's like the program ignores the parameter and try to connect the localhost again, it doesn't try to connect the server.
Just for information, I tried many JNDI names to ctx.lookup(name), and I used the
InitialContext ctx = new InitialContext();
without props because it is recomended in Glassfish FAQ.
How can I told to program to try a remote connection?