selected bean is not in the same module or enterprise application

╄→гoц情女王★ 提交于 2019-12-11 03:58:26

问题


Just a shot in the dark, but do I need a local interface to call a remote stateless EJB?

when I try call the bean remotely through Netbeans:

Netbeans doesn't allow a remote call, or any call, on this bean. Why not?

Trying to do it manually, as below:

What is the jndi global remote name for the Remote EJB which is deployed on glassfish?

INFO:   visiting unvisited references
INFO:   visiting unvisited references
INFO:   EJB5181:Portable JNDI names for EJB MyRemoteSessionClass: [java:global/RemoteSalutation-ejb/MyRemoteSessionClass!net.bounceme.dur.glassfish.MyRemoteSession, java:global/RemoteSalutation-ejb/MyRemoteSessionClass]
INFO:   RemoteSalutation-ejb was successfully deployed in 941 milliseconds.

If possible, I would rather specify the class in the properties file rather than hard-coded. In any event, different variations result in a lookup failure. Here's the stack-trace:

run-deploy:
Copying 1 file to /home/thufir/NetBeansProjects/RemoteLookup/dist
Copying 2 files to /home/thufir/NetBeansProjects/RemoteLookup/dist/RemoteLookupClient
Warning: /home/thufir/NetBeansProjects/RemoteLookup/dist/gfdeploy/RemoteLookup does not exist.
Sep 13, 2014 1:35:41 AM net.bounceme.dur.remote.RemoteLookup run
INFO: java.naming.factory.initial   com.sun.enterprise.naming.impl.SerialInitContextFactory
Sep 13, 2014 1:35:41 AM net.bounceme.dur.remote.RemoteLookup run
INFO: java.naming.factory.url.pkgs  com.sun.enterprise.naming
Sep 13, 2014 1:35:41 AM net.bounceme.dur.remote.RemoteLookup run
INFO: java.naming.factory.state com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Sep 13, 2014 1:35:46 AM net.bounceme.dur.remote.RemoteLookup main
SEVERE: Lookup failed for ' java:comp/env//RemoteSalutation-ejb/MyRemoteSessionClass!net/bounceme/dur/glassfish/MyRemoteSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, remote=net.bounceme.ix.Foo, org.omg.CORBA.ORBInitialHost=localhost, java.naming.security.principal=user, org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.provider.url=server.local:1199, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.security.credentials=password}
javax.naming.NamingException: Lookup failed for ' java:comp/env//RemoteSalutation-ejb/MyRemoteSessionClass!net/bounceme/dur/glassfish/MyRemoteSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, remote=net.bounceme.ix.Foo, org.omg.CORBA.ORBInitialHost=localhost, java.naming.security.principal=user, org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.provider.url=server.local:1199, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.security.credentials=password} [Root exception is javax.naming.NameNotFoundException:  java:comp]
    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.remote.RemoteLookup.run(RemoteLookup.java:34)
    at net.bounceme.dur.remote.RemoteLookup.main(RemoteLookup.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:446)
    at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:166)
Caused by: javax.naming.NameNotFoundException:  java:comp
    at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:299)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:207)
    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.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    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)

run:
BUILD SUCCESSFUL (total time: 17 seconds)

client code:

package net.bounceme.dur.remote;

import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class RemoteLookup {

    private static final Logger log = Logger.getLogger(RemoteLookup.class.getName());
    private final MyProps p = new MyProps();

    public static void main(String... args) {
        try {
            new RemoteLookup().run();
        } catch (NamingException ex) {
            Logger.getLogger(RemoteLookup.class.getName()).log(Level.SEVERE, ex.getExplanation(), ex);
        }
    }

    private void run() throws NamingException {
        Properties jndi = p.getJNDI();
        Enumeration e = jndi.propertyNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String val = jndi.getProperty(key);
            log.info(key + "\t" + val);
        }
        Context ic = new InitialContext();
        //    Object o = ic.lookup(" java:comp/env/RemoteSalutation-ejb/MyRemoteSessionClass");
        Object o = ic.lookup(" java:comp/env//RemoteSalutation-ejb/MyRemoteSessionClass!net/bounceme/dur/glassfish/MyRemoteSession");
    }
}

the remote EJB:

package net.bounceme.dur.glassfish;

import javax.ejb.Stateless;

//@LocalBean
@Stateless(mappedName = "salutationBean")
public class MyRemoteSessionClass implements MyRemoteSession {

    @Override
    public String SayHello() {
        return "hello from glassfish..";
    }

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

note that the interface is remote, ie: it's literally a Java class library. Correct? This makes the EJB remote.

referencing:

https://netbeans.org/kb/docs/javaee/entappclient.html

although I changed the names a bit..otherwise should be exactly as the tutorial.


回答1:


Try Object o = ic.lookup("salutationBean"); Note that mappedName specifies the name to use in JNDI for a remote access.



来源:https://stackoverflow.com/questions/25821480/selected-bean-is-not-in-the-same-module-or-enterprise-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!