0

For two Java SE clients connecting to Glassfish on localhost, only the ACC client example, very similar to the Netbeans Creating and Running an Application Client on the GlassFish Server tutorial, connects. RemoteJNDI, which connects via CORBA, with explicit JNDI connection parameters, gets a NamingException. How can RemoteJNDI connect to Netbeans on localhost, lookup the bean correctly, and execute the bean?

RemoteJNDI is run from Glassfish appclient. Glassfish shows:

thufir@dur:~/NetBeansProjects/HelloClient$ 
thufir@dur:~/NetBeansProjects/HelloClient$ /home/thufir/glassfish-4.1/glassfish/bin/asadmin list-applications
HelloEJB     <ejb>        
Command list-applications executed successfully.
thufir@dur:~/NetBeansProjects/HelloClient$ 

running ant clean;ant run on the ACC client example gives good output:

-run:
     [java] hello world

run:

BUILD SUCCESSFUL
Total time: 26 seconds
thufir@dur:~/NetBeansProjects/HelloClient$ 

(This also deploys HelloClient to Glassfish.)

however, trying to replicate that output with appclient and JNDI lookup results in NamingException: Lookup failed for 'hello.HelloBean' while the ACC client was able to lookup that bean through the ACC. Why can't RemoteJNDI lookup the bean? Stacktrace:

thufir@dur:~/NetBeansProjects/HelloClient$ /home/thufir/glassfish-4.1/glassfish/bin/appclient -client /home/thufir/NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar 
Sep 20, 2014 8:05:12 AM net.bounceme.dur.jndi.RemoteJNDI main
INFO: {org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1}
org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort  vmcid: OMG  minor code: 8 completed: Maybe
    at com.sun.proxy.$Proxy35.connectionAbort(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1288)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doWork(ConnectionImpl.java:846)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410011: IOException received when reading from connection SocketOrChannelConnectionImpl[ java.nio.channels.SocketChannel[connected local=/127.0.0.1:59218 remote=localhost/127.0.0.1:4848] ESTABLISHED true true]  vmcid: OMG  minor code: 11  completed: No
    at com.sun.proxy.$Proxy35.ioexceptionWhenReadingConnection(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1475)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1242)
    ... 3 more
Caused by: java.io.IOException: End-of-stream
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1468)
    ... 4 more
Sep 20, 2014 8:05:46 AM net.bounceme.dur.jndi.RemoteJNDI main
SEVERE: null
javax.naming.NamingException: Lookup failed for 'hello.HelloBean' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort  vmcid: OMG  minor code: 8 completed: Maybe]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at net.bounceme.dur.jndi.RemoteJNDI.main(RemoteJNDI.java:17)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort  vmcid: OMG  minor code: 8 completed: Maybe]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:334)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477)
    ... 3 more
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort  vmcid: OMG  minor code: 8 completed: Maybe
    at com.sun.proxy.$Proxy35.connectionAbort(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1288)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doWork(ConnectionImpl.java:846)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410011: IOException received when reading from connection SocketOrChannelConnectionImpl[ java.nio.channels.SocketChannel[connected local=/127.0.0.1:59218 remote=localhost/127.0.0.1:4848] ESTABLISHED true true]  vmcid: OMG  minor code: 11  completed: No
    at com.sun.proxy.$Proxy35.ioexceptionWhenReadingConnection(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1475)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1242)
    ... 3 more
Caused by: java.io.IOException: End-of-stream
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1468)
    ... 4 more

thufir@dur:~/NetBeansProjects/HelloClient$ 

The ACC client code:

package helloclient;

import hello.HelloBeanRemote;
import javax.ejb.EJB;

public class Main {
    @EJB
    private static HelloBeanRemote helloBean;

    public static void main(String... args) {
        System.out.println(helloBean.Hi());
    }

}

The interface:

package hello;

import javax.ejb.Remote;

@Remote
public interface HelloBeanRemote {

    public String Hi();

    public String Bye();
}

The EJB:

package hello;

import javax.ejb.Stateless;

@Stateless
public class HelloBean implements HelloBeanRemote {

    @Override
    public String Hi() {
        return "hello world";
    }

    @Override
    public String Bye() {
        return "goodbye";
    }

}

RemoteJNDI should explicitly have the same configuration which HelloClient, the ACC client, implicitly has. Why is the ACC client able to execute the bean, whileRemoteJNDI` cannot?

Code for RemoteJNDI:

package net.bounceme.dur.jndi;

import hello.HelloBean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class RemoteJNDI {

    private static final Logger log = Logger.getLogger(RemoteJNDI.class.getName());

    public static void main(String[] args) {
        try {
            InitialContext ctx = new InitialContext();
            log.info(ctx.getEnvironment().toString());
            HelloBean bean = (HelloBean) ctx.lookup("hello.HelloBean");
            log.info(bean.Hi());
        } catch (NamingException ex) {
            Logger.getLogger(RemoteJNDI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

Are the connection parameters correct for Glassfish running on localhost?

thufir@dur:~/NetBeansProjects/HelloClient$ 
thufir@dur:~/NetBeansProjects/HelloClient$ /home/thufir/glassfish-4.1/glassfish/bin/appclient -client /home/thufir/NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar 
Sep 20, 2014 8:05:12 AM net.bounceme.dur.jndi.RemoteJNDI main
INFO: {org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1}

------------------------------------------------------edit-----------------------------

trace:

thufir@dur:~$ 
thufir@dur:~$ /home/thufir/glassfish-4.1/glassfish/bin/appclient -client /home/thufir/NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar 
javax.naming.NamingException: Lookup failed for 'HelloBeanRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is javax.naming.NameNotFoundException: HelloBeanRemote not found]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at net.bounceme.dur.jndi.RemoteJNDI.main(RemoteJNDI.java:18)
Caused by: javax.naming.NameNotFoundException: HelloBeanRemote not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
    at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
    at sun.reflect.GeneratedMethodAccessor113.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
thufir@dur:~$ 
thufir@dur:~$ 

ex.printstacktrace;

package net.bounceme.dur.jndi;

import hello.HelloBean;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class RemoteJNDI {

    private static final Logger log = Logger.getLogger(RemoteJNDI.class.getName());

    public static void main(String... args) {
        try {
            InitialContext ctx = new InitialContext();
            log.fine(ctx.getEnvironment().toString());
            Object obj = ctx.lookup("HelloBeanRemote");
            HelloBean bean = (HelloBean) PortableRemoteObject.narrow(obj, HelloBean.class);
            log.info(bean.Hi());
        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }

}

----------------------------------------edit--------------------------------------

Community
  • 1
  • 1
Thufir
  • 8,216
  • 28
  • 125
  • 273
  • just to note, I added the EJB module, `HelloEJB`, and its interface, to `RemoteJNDI` to lookup the bean. – Thufir Sep 20 '14 at 16:28

1 Answers1

1

Use the Remote Interface Name for lookup via JNDI. Then use the PortableRemoteObject.narrow() method to cast it to your remote bean.

Object obj = ctx.lookup("HelloBeanRemote");
HelloBean bean = (HelloBean) PortableRemoteObject.narrow(obj, HelloBean.class);
ares
  • 4,283
  • 6
  • 32
  • 63
  • see edit for output, I think it's the same error. I tried port 3700 instead of 4848, but still can't lookup the bean. I do like using the interface name to look it up. Why "HelloBeanRemote" and not "hello.HelloBeanRemote"? – Thufir Sep 20 '14 at 16:21
  • The server automatically detects the package name for any remote interface of a session bean and that's the way I do and it works. Also HelloBeanRemote is much more neat. Coming to the problem, can you provide the trace after the edit. – ares Sep 20 '14 at 16:33
  • There was no more output than that -- unless I pass compiler options or change what is logged in try loop. Will do. – Thufir Sep 20 '14 at 16:36
  • In the error line I cannot see the exception. Would you log the complete stacktrace and put it somewhere so that I can see. – ares Sep 20 '14 at 16:46
  • I don't know that this is a solution to the problem. I'll try this with a `@local` bean instead. – Thufir Sep 21 '14 at 02:52
  • see http://stackoverflow.com/questions/25955698/lookup-local-stateless-ejb-with-corba-settings-from-jndi-properties-file for trying with `@local` – Thufir Sep 21 '14 at 04:13