8

我正在尝试调用部署在远程服务器上的无状态 EJB。我可以从本地 JBoss 环境调用 bean,但是当我更改remote.connection.default.host为远程机器的主机时,我的客户端代码不起作用。

这是我的jboss-ejb-client.properties

endpoint.name=client-endpoint

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=SERVERIP/HOSTNAME
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=username
remote.connection.default.password=Password

我的客户端代码如下所示:

Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
String jndi = "jndi_name";
Context context = new InitialContext(properties);
obj = context.lookup(jndi);

请帮忙。

谢谢大家。杰克。

4

5 回答 5

3

这个答案可能迟了,但我遇到了同样的问题,以上答案都没有帮助我,要解决这个问题,请参考以下内容:http: //blog.jonasbandi.net/2013/08/jboss-remote-ejb-invocation -unexpected.html

对我有用的代码如下:

Properties jndiProperties=new Properties();
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080/");
    //This property is important for remote resolving
    jndiProperties.put("jboss.naming.client.ejb.context", true);
    //This propert is not important for remote resolving
    jndiProperties.put("org.jboss.ejb.client.scoped.context", "true");

    Context context=new InitialContext(jndiProperties);


    /*
    java:global/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
    java:app/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
    java:module/GenericStateless!test.stateless.GenericStateless
    java:jboss/exported/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
    java:global/JEETest_Project/EJBTest_Project/GenericStateless
    java:app/EJBTest_Project/GenericStateless
    java:module/GenericStateless
     */

    //None of the above names work for remote EJb resolution ONLY THIS WORKS - 
    //"/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless"

    GenericStateless bean=(GenericStateless)context.lookup("/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless");

    //GenericStateless bean=(GenericStateless)c.lookup("GenericStateless!test.stateless.GenericStateless");
    System.out.println(bean.getInt());
于 2014-12-22T17:17:01.687 回答
1

什么对我有用:

我的客户在一个独立的 Maven 项目中。我需要做的就是添加这个依赖:

<dependency>
    <groupId>org.wildfly</groupId>
    <artifactId>wildfly-ejb-client-bom</artifactId>
    <version>10.1.0.Final</version>
    <type>pom</type>
    <scope>runtime</scope>
</dependency>

我通过查看ejb-remote示例得出了这个解决方案。

于 2016-10-31T15:58:12.730 回答
1

愚蠢地相信我理解了 Wildfly 上的 EJB 部署,几天来我一直在努力从 Servlet 远程调用我的无状态 EJB,并尝试从网上找到的代码片段中进行各种配置。没运气。

我终于看到了来自 JBOSS 的以下指南,它在大约 10 分钟内解决了我的问题。我错误地配置了我的远程出站连接。Wildfly 开发人员编写了一个很棒的 Java EE 应用程序服务器,但它们的解释性错误消息很糟糕。

该指南适用于 AS7.2,但与我的 Wildfly 8.2.0 平台相关。

希望这能拯救别人我所遭受的悲伤。

于 2015-08-18T00:59:42.273 回答
0

您的客户端代码必须使用 EJB 3 标准化 JNDI 名称来访问您的 bean

Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
// Not needed but I like to see it when debugging
properties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080/");
// EJB 3 bean naming convention
String jndi = "ejb:/myapp/mymodule/myEjbName!my.own.package.EjbInterface";
Context context = new InitialContext(properties);
obj = context.lookup(jndi);

并检查 WildFly server.log 以获取 bean 的导出 JNDI 绑定:java:jboss/exported/myapp/mymodule/myEjbName!my.own.package.EjbInterface

要通过安全检查,用户名必须在ApplicationRealm.

于 2014-11-27T11:18:28.993 回答
-1

通常在 Java EE 中,您让容器进行查找,而不是自己进行。来自Java EE 6 教程

要通过依赖注入获取对企业 bean 的远程业务接口的引用,请使用 javax.ejb.EJB 注解并指定企业 bean 的远程业务接口名称:

@EJB Example example;

如果它必须是 JNDI 查找,请查看这个 JBoss 教程- 虽然它适用于版本 7,但它可能对您的情况有所帮助。

于 2014-06-30T06:22:57.067 回答