Skip to main content

Look up the remote EJB 3.1 on glassfish 3.1.2.2 with a client application (another machine)

3 replies [Last post]
leandrobortolotto
Offline
Joined: 2010-05-26
Points: 0

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?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
guojun.shan
Offline
Joined: 2012-10-26
Points: 0

I try it with Glassfish 3.1.2.2, it works fine.
Could you try to add this two line of code to verify your parameters are correctly provided?

String mValue=System.getProperty("org.omg.CORBA.ORBInitialHost");
System.out.println("org.omg.CORBA.ORBInitialHost : "+mValue);

leandrobortolotto
Offline
Joined: 2010-05-26
Points: 0

I executed the client application just with the parameter:

-Dcom.sun.appserv.iiop.endpoints=www.zerofila.com.br:3700

and I monitored the port 3700 using "tcpdump port 3700 -vv" linux command, and I could see communication between the client machine and the server when this line is executed:

InitialContext ctx = new InitialContext();

but the look up doesn't work yet.

My client application connected to the server, but the look up doesn't work.

Any suggestion?

leandrobortolotto
Offline
Joined: 2010-05-26
Points: 0

I solved my problem, I migrate to JBoss 7.1.1, read the tutorial https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI and in my first test all worked fine, in the way that I desired but using JBoss instead Glassfish.