Nino DELCEY
Nino DELCEY

Reputation: 678

Can't contact EJB from remote machine

As title says, I can't contact my EJB from a distant machine. The client trying to contact the EJB-hosting machine works perfectly when used locally.

The remote machine is on Windows XP SP3 (32 bits) with Java JRE 7_71. It's connected to the same network as the machine running the EJB on a Glasshfish server.

The second machine (which is running the Glasshfish server) runs on Win7 x64. Are installed JDK 1.7_75, JDK 1.8_25, jre1.8.0_25 and JRE 7_71.

All firewalls are disabled. No proxies used. Just 2 machines behind a router connected to internet.

I'm programming with NetBeans 8.0.2, with a Glasshfish server 4.1.

Here's what it looks like : https://i.sstatic.net/XLHk9.jpg

"ABEJB" is my EJB. In Properties > Sources, the "Source / Binary Format is JDK 7. In Properties > Libraries, I added the JDBC driver (works well) and set the Java Platform to "JDK 1.7". Note : When I'm deploying my EJB on Glassfish, I got these infos :

Infos:   Portable JNDI names for EJB AJoyfulBean: [java:global/ABEJB/AJoyfulBean!EJB.NewSessionBeanRemote, java:global/ABEJB/AJoyfulBean]
Infos:   Glassfish-specific (Non-portable) JNDI names for EJB AJoyfulBean: [ABS/AJoyfulBean#EJB.NewSessionBeanRemote, ABS/AJoyfulBean]

NewSessionBean.java :

@Stateless(name = "AJoyfulBean")
public class NewSessionBean implements NewSessionBeanRemote
{

    @Override
    public String testConnexion()
    {
        String retour = "Connected to : " + System.getenv("COMPUTERNAME");

        try
        {
            retour += " / " + InetAddress.getLocalHost();
        }
        catch (UnknownHostException ex)
        {
            retour += "unknown IP ! :(";
        }

        return retour;
    }
}

NewSessionBeanRemote.java

@Remote
public interface NewSessionBeanRemote
{

    String testConnexion();
}

sun-ejb-jar.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>AJoyfulBean</ejb-name>
            <jndi-name>ABS/AJoyfulBean</jndi-name>
        </ejb>
    </enterprise-beans>
</sun-ejb-jar>

"A Better Stock" is my Java application on a remote machine. In Properties > Sources, the "Source / Binary Format is JDK 7. In Properties > Libraries, I added the "Java EE from GlassFish" libraries from NetBeans and the "gf-client.jar" from the Glassfish installation repertory. The Java Platform is set to "JDK 1.7". The EJB interface is the same as my EJB (I don't get a Marchal exception anyway).

Inside a static method on my main class :

try
{
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
    props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.164"); // the IP of the machine hosting the glassfish server
    props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    InitialContext ctx = new InitialContext(props);

    NewSessionBeanRemote myEJB = (NewSessionBeanRemote) ctx.lookup("java:global/ABEJB/AJoyfulBean!EJB.NewSessionBeanRemote"); // Tried "ABS/AJoyfulBean#EJB.NewSessionBeanRemote" too

    jTextAreaInformations.setText(jTextAreaInformations.getText() + "\n" + myEJB.testConnexion());
}
catch (Exception ex)
{
    jTextAreaInformations.setText(jTextAreaInformations.getText() + "\n" + ex.toString());
}

MANIFEST.MF :

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_25-b18 (Oracle Corporation)
Class-Path: lib/javax.annotation-api.jar lib/jaxb-api.jar lib/webservi
 ces-api-osgi.jar lib/bean-validator.jar lib/javax.batch-api.jar lib/j
 avax.ejb-api.jar lib/javax.el.jar lib/javax.enterprise.concurrent-api
 .jar lib/javax.enterprise.concurrent.jar lib/javax.enterprise.deploy-
 api.jar lib/javax.faces.jar lib/javax.inject.jar lib/javax.intercepto
 r-api.jar lib/javax.jms-api.jar lib/javax.json.jar lib/javax.mail.jar
  lib/javax.management.j2ee-api.jar lib/javax.persistence.jar lib/java
 x.resource-api.jar lib/javax.security.auth.message-api.jar lib/javax.
 security.jacc-api.jar lib/javax.servlet-api.jar lib/javax.servlet.jsp
 -api.jar lib/javax.servlet.jsp.jar lib/javax.servlet.jsp.jstl-api.jar
  lib/javax.servlet.jsp.jstl.jar lib/javax.transaction-api.jar lib/jav
 ax.websocket-api.jar lib/javax.ws.rs-api.jar lib/javax.xml.registry-a
 pi.jar lib/javax.xml.rpc-api.jar lib/jaxb-osgi.jar lib/webservices-os
 gi.jar lib/weld-osgi-bundle.jar lib/jaxm-api.jar lib/gf-client.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: a.better.stock.UI.Accueil

When I'm running the .jar file of my client (with the /lib folder) on the machine hosting the glassfish server, my EJB is contacted and correctly do the tasks required (updating SQL tables). But when I copy the .jar file and /lib folder to the distant machine and execute it, it get this exception :

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory 
[Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]

So basically, why am I getting this exception ? I'm giving the context. And anyway, it works on local but not on remote client. Weird.

Upvotes: 2

Views: 623

Answers (2)

cilap
cilap

Reputation: 2333

please check if your container (glassfish) is listening on port 3700. on windows http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/netstat.mspx?mfr=true

netstat -a -n -o

if it is running, try a telnet to the port

telnet <yourglassfishIP> 3700

If you can type anything and the telnet does not terminate immediately your port is open.

In case of open port, check if you have configured glassfish to accept remote EJB calls.

Upvotes: 0

StefanHeimberg
StefanHeimberg

Reputation: 1465

how do you start your client? from which directory? the same as on your local directory? perhaps it could be that your class path of your client is not correct? or even incomplete?

i think it could be that some jar files from lib/ folder require other jars in the correct folder structure. you can see that for example in the appserv-rt.jar/META-INF/MANIFEST.MF. there you can find the "Class-Path: ../lib/gf-client.jar" entry. the solution could be that you run your client from within the lib/ folder or from within the bin/ directory as glass fish does..

Upvotes: 1

Related Questions