0

I run my EJB client together with the EJB in Glassfish 5.1 in the same Windows 10. It works fine. I am trying to port the glassfish to Ubuntu but find that it didn't work if client in Windows and EJB in Ubuntu (win->ubuntu, not ok). However, if client in Ubuntu and EJB in Windows, it works (ubuntu->win, ok). win->win, ok. ubuntu->ubuntu, ok. So I hope somebody here can help me.

For testing, instead of calling the EJBs, I use Context.list() to lookup all JNDI in glassfish, and at this end there are some strange result I'll mention at the end.

Here is my client:

package test;
public class TestJNDI {
    public static void main(String[] args) throws Exception {
        System.setProperty("org.omg.CORBA.ORBInitialHost", args[0]);
        Context c = new InitialContext();
        NamingEnumeration<NameClassPair> ne = c.list("");
        if (!ne.hasMore()) {
            System.out.println("c.list empty");
            return;
        }//end if
        while (ne.hasMore()) {
            NameClassPair ncp = ne.next();
            String name = ncp.getName();
            System.out.println(name+"="+ncp.getClassName());
        }//end while
    }//end main
}//end class

I've tried to include things like

System.setProperty("java.naming.factory.initial",
                "com.sun.enterprise.naming.SerialInitContextFactory");

and the others but none of them helps. The client is compiled in windows into testJNDI.jar and port to Ubuntu.

First off, I have glassfish running in both ubuntu and windows. Ubuntu EJBs use mappedName like @Singleton(mappedName = "StockFacade") . Windows has same set of EJBs but all names are prefixed with win. like @Singleton(mappedName = "win.StockFacade")

Then I run the client in command line. In Ubuntu

java -cp testJNDI.jar:/home/me/glassfish5-1/glassfish/lib/gf-client.jar test.TestJNDI win-ip

It listed out all EJB names in win glassfish, no prefix. So it works.

Then in windows

java -cp testJNDI.jar;d:\glassfish5-1\glassfish\lib\gf-client.jar test.TestJNDI ubu-ip

It said c.list empty. So it doesn't work.

When I replace win-ip and ubu-ip of the above with localhost, both command works, i.e. ubuntu list without prefix, windows list with prefix. What strange thing is, once I did this, and repeat the second command: windows to ubuntu command using ubu-ip, it gives me the windows EJB list instead (i.e. with prefix). only when I shutdown windows glassfish and repeat the command then it gives me c.list empty.

So there are two problems: (1) why client in Ubuntu works while same client in Windows doesn't?; (2) why once localhost is used in windows, the list seems to stay in some kind of buffer, further access to Ubuntu gives me the windows list? Please help.

EDIT: Further testing reveal 2 findings: (1) I found that if I use property java.naming.provider.url instead of org.omg.CORBA.ORBInitialHost and ....Port , it always give me the local glassfish's EJBs even if the host url is specified correctly, not work even in ubuntu->windows cases. (2) I add another ubuntu to my testing, also with same glassfish and same set of EJBs except names prefixed with test. This made me revise my result above. To sum up the new result (client->server=result): ubu1->ubu2 = ubu1 EJBs; ubu2->ubu1 = ubu2 EJBs; ubu-any->win = work ok; win->ubu-any = win EJBs. Any idea?

senderj
  • 400
  • 1
  • 9
  • Did you check the host file of Windows and Ubuntu? I have faced sometimes the problem that Ubuntu assigns the IP 127.0.1.1 to localhost resulting in all kinds of strange errors. Also (but I guess you checked before) is the Windows Firewall maybe blocking outbound traffic? – Christoph John Oct 09 '19 at 09:36
  • Also found this https://stackoverflow.com/questions/40045883/windows-client-and-linux-ubuntu-server but no real solution so far. – Christoph John Oct 09 '19 at 10:10
  • @Christoph, thanks for the reply. Hosts file setting is ok. Problem exists also when I use real ip. I've checked the firewall, all java.exe are allowed. The link has very similar problem as mine, but I did not use any VM. Both windows and ubuntu are real boxes. – senderj Oct 10 '19 at 09:07
  • I also used PowerShell command `Test Net-Connection ubu-ip -Port 3700` it returns `TcpTestSucceeded : True` . So I think the connection is ok. – senderj Oct 10 '19 at 09:15
  • I meant `Test-NetConnection` – senderj Oct 10 '19 at 09:16

1 Answers1

0

I only just saw that you do this:

System.setProperty("org.omg.CORBA.ORBInitialHost", args[0]);
Context c = new InitialContext();

I think you should pass those properties to the InitialContext constructor.

Properties props = new Properties();  
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);

Example taken from here: Obtaining initial context from remote client

At least that is what I was doing all the years (when I was still using remote EJBs).

Edit: I think this might also be the issue why it seems that entries are cached. IIRC that can happen when using the default InitialContext.

Christoph John
  • 3,003
  • 2
  • 13
  • 23