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?