选定的bean不在同一模块或企业应用程序中

时间:2014-09-13 08:50:00

标签: java glassfish ejb jndi remote-execution

只是在黑暗中拍摄,但我是否需要本地接口来调用远程无状态EJB?

当我尝试通过Netbeans远程调用bean时:

enter image description here

Netbeans不允许对此bean进行远程调用或任何调用。为什么不呢?

尝试手动执行,如下所示:

部署在glassfish上的远程EJB的jndi 全局远程名称是什么?

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.

如果可能的话,我宁愿在属性文件中指定类而不是硬编码。无论如何,不​​同的变化会导致查找失败。这是堆栈跟踪:

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)

客户代码:

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");
    }
}

远程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..";
    }
}

请注意,界面是远程,即:它实际上是一个Java类库。正确?这使得EJB远程。

参考:

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

虽然我稍微更改了名称。其他方面应该与教程完全相同。

1 个答案:

答案 0 :(得分:1)

试试Object o = ic.lookup("salutationBean"); 请注意,mappedName指定在JNDI中用于远程访问的名称。