【问题标题】:Wildfly Remote EJB InvocationWildfly 远程 EJB 调用
【发布时间】:2014-08-18 13:53:10
【问题描述】:

我正在尝试调用部署在远程服务器上的无状态 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);

请帮忙。

谢谢大家。 杰克。

【问题讨论】:

  • 究竟是什么“不起作用”?你到底用什么来查找?因为这可能是错误的,而您简化的“jndi_name”可能是它的重要部分。
  • 我无法调用远程 EJB。我能够调用本地 EJB。我的 jboss-ejb-client.properties 文件中有 localhost,它工作正常。但是当我将其更改为远程服务器的 IP 或主机名时,它不起作用。请指教。
  • 尝试连接时出现以下错误。 “无法注册 EJB 接收器以连接到主机名:8080。java.lang.RuntimeException:操作失败,状态为 WAITING”。
  • 调用EJB的远程端口大概是4447。
  • @Geziefer WildFly 使用 8080,4447 用于 JBoss AS 7。您的 JNDI 查找字符串到底是什么?

标签: java jboss ejb remote-server wildfly-8


【解决方案1】:

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

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

@EJB Example example;

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

【讨论】:

  • 问题是关于从远程服务器调用 EJB。
  • @wibobm:由于评论中的原因,您是否对我的回答投了反对票?然后您可能想阅读我提到的 Java EE 教程的章节,特别是“远程客户端”子章节。如果您在一台机器上有@Remote 接口EJB,您可以通过@EJB 注入它从另一台机器访问它。
【解决方案2】:

您的客户端代码必须使用 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 中定义。

【讨论】:

    【解决方案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());
    

    【讨论】:

    • 这是第一种对我有用的方法!我已经尝试过(太多)了:)
    【解决方案4】:

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

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

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

    希望这能减轻我遭受的痛苦。

    【讨论】:

      【解决方案5】:

      什么对我有用:

      我的客户在一个独立的 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 示例得出了这个解决方案。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-20
      • 2020-09-16
      • 1970-01-01
      • 2014-08-22
      • 2015-08-06
      • 2014-01-16
      • 2016-05-06
      • 2016-08-02
      相关资源
      最近更新 更多