6
votes

An application (e.g app.EAR) is deployed to a JBoss in my own machine and works fine. When I deploy it to a remote JBoss it is deployed, but when I try to access a functionality that needs a JNDI lookup to a remote EJB I get NameNotFoundException. So, it seems that it was unable to find the requested service. How come? If it works locally?

The dependency with the remote EJB interface is in the lib folder inside the EAR and of course is annotated with @Remote. The JBoss is exactly the same as the production one (I copied the whole JBoss from production to my machine to check if there is any configuration missing).

My lookup code is like this:

private Object lookup(String resourceName, String loginData) {
        if (isPropagateUserCredentials() && (loginData == null || loginData.trim().equals(""))) {
            throw new MyInfraConfigException("somemessage");
        }
        Properties envProperties = new Properties();
        envProperties.putAll(this.jndiProperties);
        if (loginData != null && !loginData.equals("")) {
            envProperties.put(Context.SECURITY_PRINCIPAL, loginData);           
            envProperties.remove(Context.SECURITY_CREDENTIALS);
        }
        Context context = null;
        try {
            context = new InitialContext(envProperties);
            return context.lookup(resourceName);            
        } catch (NameNotFoundException e){
            String message = "Resource "+resourceName+" not found.";
            LoggerFactory.getInstance(this.getClass().getName()).error(message, e);
            throw new com.mypackage.NameNotFoundException(message, e);
        } catch (NamingException e) {
            String message = "Failed to find resource with JNDI: "+e.getMessage();
            LoggerFactory.getInstance(this.getClass().getName()).error(message, e);
            throw new com.mypackage.NamingException(message, e);
        } finally{
            if(context!=null){
                try {
                    context.close();
                } catch (NamingException e) {
                    e.printStackTrace();
                }
            }
        }
    }

The resourceName is ExternalResource.

The stacktrace is below:

29/06/2015 10:30:43 oracle.j2ee.clustering.ClusteringMessages warningInOpmnGetServers
AVISO: Error in obtaining server list from OPMN on host XX.XXX.XXX.XXX:XXXX.  Please verify that OPMN is running.
javax.naming.NameNotFoundException: ExternalResource not found
    at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:60)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at br.teste.TestaJNDI.main(TestaJNDI.java:33)

Any clues?

UPDATE Made an external simple java application in order to try to connect to the server and understand the cause of the problem. In fact, the problem is that I am getting a connection timeout:

javax.naming.CommunicationException: Connection timed out [Root exception is java.net.ConnectException: Connection timed out]
        at com.evermind.server.rmi.RMIClient.lookup(RMIClient.java:311)
        at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:59)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at br.teste.TestaJNDI.listaUFs(TestaJNDI.java:55)
        at br.teste.TestaJNDI.main(TestaJNDI.java:37)
Caused by: java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at com.evermind.server.rmi.RMIClientConnection.createSocket(RMIClientConnection.java:802)
        at oracle.oc4j.rmi.ClientSocketRmiTransport.createNetworkConnection(ClientSocketRmiTransport.java:59)
        at oracle.oc4j.rmi.ClientRmiTransport.connectToServer(ClientRmiTransport.java:75)
        at oracle.oc4j.rmi.ClientSocketRmiTransport.connectToServer(ClientSocketRmiTransport.java:69)
        at com.evermind.server.rmi.RMIClientConnection.connect(RMIClientConnection.java:765)
        at com.evermind.server.rmi.RMIClientConnection.sendLookupRequest(RMIClientConnection.java:247)
        at com.evermind.server.rmi.RMIClientConnection.lookup(RMIClientConnection.java:231)
        at com.evermind.server.rmi.RMIClient.lookup(RMIClient.java:302)
        ... 4 more
1
Please show the stack trace that you get from the failed lookup - Steve C
please show the boot log + exception and also, which jboss version are you using? - Paizo
@SteveC the stacktrace is very simple: 29/06/2015 10:30:43 oracle.j2ee.clustering.ClusteringMessages warningInOpmnGetServers AVISO: Error in obtaining server list from OPMN on host 10.0.225.75:6003. Please verify that OPMN is running. javax.naming.NameNotFoundException: XXXService not found at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:60) at javax.naming.InitialContext.lookup(InitialContext.java:392) at br.teste.TestaJNDI.main(TestaJNDI.java:33) - jguilhermemv
@Paizo see my comment above, please. - jguilhermemv
what jboss version are you using in prodocution/your dev machine? Also what jndi properties are you using? the ExternalResource could have been registered with a different JNDI, you should be able to see the corresponding JNDI names on the server start's logs and usually has a format as: "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName - Paizo

1 Answers

1
votes

This might be a network communication issue. I would check if the server does allow for communication on the remoting ports. Try telnet the server, if its configured to accept these requests:

telnet <server> <port>

If using default ports, I think this should be 4447. If this connection fails then answer the following: 1. Is there no firewall that might be blocking this communication. 2. Are you using the correct port as configured by your production server.

There could really be other reasons for the fail, but that would be a starting point.