【问题标题】:Not able to lookup Remote EJB in JBoss 7.x无法在 JBoss 7.x 中查找远程 EJB
【发布时间】:2013-10-04 23:59:19
【问题描述】:

我正在尝试连接到部署在 JBoss 7 服务器中的远程 EJB。我试图通过查看从 JBoss CLI 获得的 JNDI 转储来弄清楚 JNDI 名称是什么。
无论我尝试什么,我都无法查找 EJB。

我认为jndi名称应该是:java:global/XNet/api/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote

这是我正在使用的客户端:

package com.mycompany.mavenproject1;

import com.mycompany.receiving.api.ReceivingAPI_EJBRemote;
import com.mycompany.receiving.api.ReceivingAPI;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws NamingException
    {
        System.out.println( "Hello World!" );


        //ReceivingAPI ejbRemote = DomainHelper.getHQApi(com.mycompany.receiving.api.ReceivingAPI.class);
        ReceivingAPI_EJBRemote ejbRemote = App.lookupRemoteStatelessCalculator();

        ejbRemote.getOpenRcvdocForSite(null, 7);
    }

//    private static ReceivingAPI_EJBRemote lookupRemoteStatelessReceiving() throws NamingException {
//        
//    }
//    
    private static ReceivingAPI_EJBRemote lookupRemoteStatelessCalculator() throws NamingException {
        final Properties jndiProperties = new Properties();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProperties.put(Context.PROVIDER_URL,"remote://someserver.xmx.com:1199");
        // username
        jndiProperties.put(Context.SECURITY_PRINCIPAL, "mycompany1");
        // password
        jndiProperties.put(Context.SECURITY_CREDENTIALS, "<removed>");
        //final Context context = new InitialContext(jndiProperties);


        jndiProperties.put("jboss.naming.client.ejb.context", true);

        InitialContext context = new InitialContext( jndiProperties );
        // The app name is the application name of the deployed EJBs. This is typically the ear name
        // without the .ear suffix. However, the application name could be overridden in the application.xml of the
        // EJB deployment on the server.
        // Since we haven't deployed the application as a .ear, the app name for us will be an empty string
        final String appName = "XNet";
        // This is the module name of the deployed EJBs on the server. This is typically the jar name of the
        // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
        // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
        // jboss-as-ejb-remote-app
        final String moduleName = "api";
        // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
        // our EJB deployment, so this is an empty string
        final String distinctName = "hq";
        // The EJB name which by default is the simple class name of the bean implementation class
        final String beanName = com.mycompany.receiving.api.ReceivingAPI.class.getSimpleName();
        // the remote view fully qualified class name
        final String viewClassName = ReceivingAPI_EJBRemote.class.getName();
        // let's do the lookup

        try {
            ReceivingAPI test1 = (ReceivingAPI)context.lookup("java:global/XNet/api/" + beanName + "_EJB!" + viewClassName);
            System.out.println("Test1 = " + test1.getClass().getName());
        } catch(Throwable t) {
          System.out.println(t);  
        }

        try {
            ReceivingAPI test = (ReceivingAPI)context.lookup("java:global/XNet/api/hq/" + beanName + "_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote");
            System.out.println("Test = " + test.getClass().getName());
        } catch(Throwable t) {
            System.out.println(t);
        }

        try {
            ReceivingAPI test = (ReceivingAPI)context.lookup("ejb:XNet/api/hq/" + beanName + "_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote");
            System.out.println("Test = " + test.getClass().getName());
        } catch(Throwable t) {
            System.out.println(t);
        }
        return (ReceivingAPI_EJBRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "_EJB!" + viewClassName);
    }

}

上一个java类的运行输出:

Hello World!
javax.naming.NameNotFoundException: global/XNet/api/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.global.XNet.api."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
javax.naming.NameNotFoundException: global/XNet/api/hq/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.global.XNet.api.hq."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
javax.naming.NameNotFoundException: ejb:XNet/api/hq/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.ejb:XNet.api.hq."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
Exception in thread "main" javax.naming.NameNotFoundException: ejb:XNet/api/hq/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.ejb:XNet.api.hq."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

这是 JNDI CLI 命令的转储:

[jboss1@hmudev01 bin]$ ./jboss-cli.sh --connect controller=localhost:10099
[standalone@localhost:10099 /] /subsystem=naming:jndi-view
{
    "outcome" => "success",
    "result" => {
        "java: contexts" => {
            "java:global" => {
                "XNet" => {
                    "class-name" => "javax.naming.Context",
                    "children" => {
                        "api" => {
                            "class-name" => "javax.naming.Context",
                            "children" => {
                                "ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBLocal" => {
                                    "class-name" => "com.mycompany.receiving.api.ReceivingAPI_EJBLocal$$$view46",
                                    "value" => "Proxy for view class: com.mycompany.receiving.api.ReceivingAPI_EJBLocal of EJB: ReceivingAPI_EJB"
                                },
                                "ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote" => {
                                    "class-name" => "com.sun.proxy.$Proxy272",
                                    "value" => "Proxy for remote EJB StatelessEJBLocator{appName='XNet', moduleName='api', distinctName='hq', beanName='ReceivingAPI_EJB', view='interface com.mycompany.receiving.api.ReceivingAPI_EJBRemote'}"
                                },
                            }
                        }
                    }
                }
            }
        }

        ...
    }
}
[standalone@localhost:10099 /] 

我的任何 maven 部门如下:

 <dependencies>
    <dependency>
        <groupId>com.mycompany.receiving</groupId>
        <artifactId>xnet-domain-receiving-client</artifactId>
        <version>2.5.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-naming</artifactId>
        <version>7.1.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.marshalling</groupId>
        <artifactId>jboss-marshalling-river</artifactId>
        <version>1.4.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.client</groupId>
        <artifactId>jbossall-client</artifactId>
        <version>5.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec.javax.ejb</groupId>
        <artifactId>jboss-ejb-api_3.1_spec</artifactId>
        <version>1.0.2.Final</version>
    </dependency>
</dependencies>

【问题讨论】:

  • 对于远程查找,我认为您可以取消与 global 相关的任何内容,因为您所追求的将是 ejb:。话虽如此,我认为您的查找字符串有点时髦。它应该类似于ejb:&lt;app_name&gt;/&lt;bean_name&gt;!&lt;bean_interface&gt;。如果您部署在 .ear 中,这将略有变化
  • 所以在你的情况下,我认为(假设 RNet 是你的 .jar 的名称)你所追求的字符串是ejb:RNet/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBLocal(注意缺少 java:ejb)。假设这是故意的,您似乎也在将一些非标准端口推入您的 jndi 设置中。如果这不起作用,可能想看看 jndiProps 接下来。
  • Rhys 你大部分是对的,但它让我有能力弄清楚我需要做什么。我会在答案中发布。

标签: java jakarta-ee jboss7.x


【解决方案1】:

在上面的评论中,Rhys 关于 jndi 字符串看起来“时髦”的说法是正确的。我尝试了我想的一切。这是适合我的情况的方法。

JNDI URL 需要如下所示:

XNet/api/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote

我还必须向问题中显示的其他内容添加依赖项:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多