Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

java - Windows Client and Linux (Ubuntu) server

Update The problem appears to be related to the fact that the Ubuntu Operating System is virtualized i.e. I have used Vmware Workstation to create a host Operating system (Windows) and a guest operating system (Ubuntu).

When I deploy the EJB to Glassfish on the host (Windows); I can lookup the EJB using a servlet client on either the host (Windows) or the guest (Ubuntu). I can also specify the settings for either the host or the guest to find the EJB. I believe this is what the issue is i.e. the lookup is always done on the host regardless of whether the host settings or guest settings are supplied in the servlet. Does anyone have a similar experience and what did you do to resolve it.

Original Question

Please see the code below:

Properties props = new 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", "192.168.163.128");
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
        try
        {
        InitialContext ctx = new InitialContext(props);
        RemoteInterfaceRemote r = (RemoteInterfaceRemote) ctx.lookup("java:global/Course/RemoteInterface!com.w0051977.dao.RemoteInterfaceRemote");//!com.w0051977.dao.RemoteInterfaceRemote
        String greeting = r.Greeting("Ian");
        System.out.println("got here");
        } catch (NamingException n)
        {
           System.out.println(n.toString());
    }

The code is found inside a Servlet and works as expected i.g. the greeting variable contains: "Good Afternoon Ian". The Servlet runs on a Windows PC and connects to a Windows server were the enterprise bean is hosted.

However, when I move the bean to a Linux (Ubuntu) PC I have problems. The code above will run inside a Servlet on the Linux PC (the client and server are on the same pc in this case). However, I cannot get the code above to work inside a servlet on a Windows PC.

Is there anything special you have to do when a windows client (servlet) connects to a Linux (Ubuntu) server? I obviously change the IP address in the code above when moving server. The exception is:

Lookup failed for 'java:global/Course/RemoteInterface' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=ubuntu, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming 

The output from the Glassfish console (on Ubuntu) is:

[2016-10-14T08:57:16.824-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460636824] [levelValue: 800] [[
  visiting unvisited references]]
[2016-10-14T08:57:16.890-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460636890] [levelValue: 800] [[
  visiting unvisited references]]
[2016-10-14T08:57:17.238-0700] [glassfish 4.1] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637238] [levelValue: 800] [[
  Portable JNDI names for EJB RemoteInterface: [java:global/Course/RemoteInterface, java:global/Course/RemoteInterface!com.w0051977.dao.RemoteInterfaceRemote]]]
[2016-10-14T08:57:17.248-0700] [glassfish 4.1] [INFO] [AS-EJB-00055] [javax.enterprise.ejb.container] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637248] [levelValue: 800] [[
  Glassfish-specific (Non-portable) JNDI names for EJB RemoteInterface: [com.w0051977.dao.RemoteInterfaceRemote#com.w0051977.dao.RemoteInterfaceRemote, com.w0051977.dao.RemoteInterfaceRemote]]]
[2016-10-14T08:57:17.432-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637432] [levelValue: 900] [[
  WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2016-10-14T08:57:17.472-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637472] [levelValue: 900] [[
  WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2016-10-14T08:57:17.482-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637482] [levelValue: 900] [[
  WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2016-10-14T08:57:18.078-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460638078] [levelValue: 800] [[
  Course was successfully deployed in 1,282 milliseconds.]]

I have spent days looking into this. Please help.

The output of: sudo lsof -i:3700 is (note that I have noe changed the IP version to 4 as per @RCs comment:

enter image description here

There is a reply when Pinging the Ubuntu PC from the Windows PC.

Here is the JNDI tree on the Linux server:

enter image description here

What should the JNDI lookup name be on the remote server? Do I have to do any configuration on the local Glassfish PC (Windows PC)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It does sound like it might possibly be a firewall issue. Try telnet your Linux machine from the windows machine on port 3700. If that fails to connect, add firewall rules to allow incoming traffic on port 3700. This should allow for the EJB communication. But you might also want to allow your http / https incoming requests as well.

Hope that helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...