当前位置: 首页 > 知识库问答 >
问题:

Wildfly上的EJB从另一个Wildfly调用远程EJB

林冥夜
2023-03-14

我目前的问题是,我的机器上运行了两个Wildfly 8.2.0最终实例。我知道,有类似的问题,但没有一个真正有助于我的问题。其中一个拥有一个宁静的应用程序,当它收到GET时,它会触发无状态会话Bean发送者豆。之后,此无状态会话 Bean 应从远程无状态会话 Bean 调用方法该方法位于另一个 wildfly 实例上。

我将从解释我到目前为止所做的事情开始(也许我错过了一些东西,我对Java EE和Wildfly相当陌生)。

我将把带有发送方的Wildfly实例称为发送方,将带有PrintBean的实例称为接收方

我创建了一个名为Stefan的应用程序用户,其密码Stefan,属于 guest组。在 Sender上,在 standalone full中。xml,我添加了一个安全领域

<security-realm name="ejb-security-realm">
  <server-identities>
    <secret value="c3R1ZmFu"/>
  </server-identities>
</security-realm>

进入

<outbound-socket-binding name="remote-ejb">
  <remote-destination host="localhost" port="8080"/>
</outbound-socket-binding>

进入

<outbound-connections>
  <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" username="Stefan" security-realm="ejb-security-realm">
    <properties>
      <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
      <property name="SSL_ENABLED" value="false"/>
    </properties>
  </remote-outbound-connection>
</outbound-connections>

进入

我用CLI命令启动Senderstandalone.bat-cstandalone-full.xml-Djboss.socket.binding.port-偏移量=100-Djboss.node.name=Sender,用standalone.bat-cstandalone-full.xml-Djboss.node.name=接收器启动接收器

发送方上的本地无状态会话 Bean 称为发送方 Bean

@Stateless
public class SenderBean implements SenderService {

  private static final Logger logger = Logger.getLogger(SenderBean.class.getSimpleName());

  public void send(){
    logger.info("Trying to invoke");
    this.invoke();
  }

  private void invoke() {
    Properties clientProperties = new Properties();
    clientProperties.put("remote.connections", "default");
    clientProperties.put("remote.connection.default.port", "8080");
    clientProperties.put("remote.connection.default.host", "localhost");

    Properties properties = new Properties();
    properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");        

    try {
        Context context = new InitialContext(properties);
        context = new InitialContext(properties);
        Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/Receiver/PrintBean!com.schubert.baseproject.testdomain.service.PrintService");
        logger.info("Obtained some object "+x.toString());
        logger.info("Trying to cast.");
        PrintService s = (PrintService) x;
        logger.info("Cast successful");
        logger.info("Printing using remote ejb: "+s.print("Markus"));
    } catch (NamingException e) {
        e.printStackTrace();
    }
  } 
}

接收器包含打印豆

@Stateless
@Remote(PrintService.class)
public class PrintBean implements PrintService {

  @Override
  public String print(String name) {
    return "Hello " + name;
  }
}

现在的问题是,我总是收到一个IllegalStateException,上面写着EJBCLIENT000025:没有可用于处理的EJB接收器…

我可能做错了什么吗?我对EJB和野蝇相当陌生。您可以在 GitHub 上找到项目设置。


共有3个答案

邹杰
2023-03-14

您可以在GitHub快速入门中找到两个JBoss服务器之间配置的详细说明,源代码和配置文件也提供

符渊
2023-03-14

我认为问题在于InitialContext的参数,服务器配置很好。尝试按照我的例子连接到远程队列,在普通企业beans的情况下,您也可以探索这样的场景(插入正确的用户登录名和密码):

env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "client");
    env.put(Context.SECURITY_CREDENTIALS, "q");

    Context ctx = new InitialContext(env);
    connectionFactory = (ConnectionFactory)ctx.lookup("/jms/RemoteConnectionFactory");
    connection = connectionFactory.createConnection("client", "q");

请记住,具有开放外部访问可能性的jndi资源必须从服务器配置开始,使用java:/jboss/export/,但在客户端,您可以下拉这些词。此说明适用于WildFly,但不适用于JBoss EAP/AS和其他。您可以通过以下链接获得更多信息。

吴山
2023-03-14

您应该将文件jboss-ejb-client.xml添加到您的发送方EAR(而不是WAR)。将其放在application.xml旁边。

jboss-ejb-client.xml内容:

<jboss-ejb-client>
    <client-context>
        <ejb-receivers>
            <remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>
        </ejb-receivers>
    </client-context>
</jboss-ejb-client> 

在发送方bean中,两行就足够了:

Context context = new InitialContext();
Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/PrintBean!com.schubert.baseproject.testdomain.service.PrintService");

请注意,我从路径中删除了“Receiver/”。您可以在服务器日志中找到JNDI绑定。

 类似资料:
  • 我正在从另一个WildFly服务器实例中查找并调用部署在WildFly服务器(目标服务器)实例上的EJB。为此,我使用链接--https://docs.jboss.org/author/display/wfly9/developer+guide#developerguide-ejbinvocationsFromaRemoteserver test.jar已经部署在目标服务器上。以下是部署日志。 无

  • enviornment-source server@wildlfy_9.0.2.final,destination_server@jboss5.x,ejb3.0,buildingtool@ant 1.没有远程出站连接的Wildfly到Wildfly EJB客户端 2.https://docs.jboss.org/author/display/wfly9/developer+guide#develo

  • 我试图调用一个安全的远程ejb,但我不能。我使用ejb-client-API。 应用程序部署在名为som的ear中。耳朵 我用的是Wildfly 8.2.0决赛 代码客户端: JBossEJB客户端。财产 EJB 独立的。xml 服务器日志 客户端日志 我可以看到,之所以使用安全域“som_security_domain”的配置,是因为它运行查询以获取密码和主体的角色,但在尝试执行安全域的Auth

  • 我不能从另一个ejb模块注入远程ejb。我把应用程序分成一个库和两个ejb模块。我尝试通过远程接口从一个ejb模块访问另一个模块,并获得javax.naming.NameNotFoundExc0019。我尝试从NewBean"@EJB私有CountryFacadeRemote"访问。我用了玻璃鱼。 我必须配置一些东西?谢谢。 下载源代码 MyAppTestEJB域名库: *国家: *Country

  • 首先对我糟糕的英文写作表示歉意! 我在Wildfly 8上部署了我的EJB bean并在Wildfly 8中调用它没有任何问题。但是当我将客户端服务器从Wildfly 8更改为Jboss AS 7时,我得到“没有ejb接收器错误”。 Wildfly 8服务器端运行输出: 输出日志: ==========================================================

  • 如果我在Wildfly中使用默认的安全域设置,我可以成功调用远程EJB。我访问此安全域根本没有检查任何用户凭据。在实现或使用检查数据库中用户名和密码的安全域后,我遇到了下面的异常。 我不知道我错过了什么。我希望这里有人能给我指出一个正确的方向。 例外情况: jboss-ejb3。xml: 独立。xml TestRemote。Java语言 谢谢,贝尔