简体   繁体   English

无法使Remote EJB与Wildfly上的EJB Client API一起使用

[英]Can't get Remote EJB to work with EJB Client API on Wildfly

I'm currently struggling with getting remote EJB invocation to work on wildfly (8.x and 9.x). 我目前正在努力使远程EJB调用可以在wildfly(8.x和9.x)上工作。

In detail it's about remote invocation from a standalone client application (not from another app server) using the EJB Client API approach. 详细而言,它涉及使用EJB客户端API方法从独立客户端应用程序(而不是另一个应用程序服务器)进行远程调用。 The remote naming approach works for me but isn't applicable in my scenario because I need to use client-side interceptors for passing context data to a server-side interceptor for the remote invocations. 远程命名方法对我有用,但不适用于我的情况,因为我需要使用客户端拦截器将上下文数据传递到服务器端拦截器以进行远程调用。

But for now I try to get remote invocations with the client API to work for a simple example. 但是现在,我尝试使用客户端API进行远程调用,以作为一个简单的示例。 Therefore I tried the quickstart for remote ejb invocation which is available on github ( wildfly/quickstart/ejb-remote ). 因此,我尝试了可用于github( wildfly / quickstart / ejb-remote )的远程ejb调用快速入门 The point is that this quickstart raises the same error as my on simple sample app. 关键是,此快速入门引发了与我在简单示例应用程序上相同的错误。 Here are some details of my application: 以下是我的应用程序的一些详细信息:

My remote interface: 我的远程界面:

package test.ejb;

public interface HelloRemote {
  String greet(String name);
}

My Bean implementation: 我的Bean实现:

package test.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless(name = "Hello")
@Remote(HelloRemote.class)
public class HelloBean implements HelloRemote {

  public String greet(String name) {
    return "Hello " + name;
  }
}

The remote view of the bean is correctly registered at the server (in export namespace): Bean的远程视图已在服务器上正确注册(在导出名称空间中):

java:jboss/exported/ejb-test-backend.jar/Hello!de.coryx.HelloRemote

Here now the client side: 现在是客户端:

My Main class: 我的主班:

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb.client.EJBClientContext;
import test.ejb.HelloRemote;

public class Main {
  public static void main(String[] args) throws Exception {
    Properties props = new Properties();
    props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    Context context = new InitialContext(props);

    String jndiLookup = "ejb:/ejb-test-backend.jar/Hello!" + HelloRemote.class.getName();
    HelloRemote hello = (HelloRemote) context.lookup(jndiLookup);
    System.out.println(hello.greet("World"));
  }
}

The jboss-ejb-client.properties (packaged in jar/META_INF): jboss-ejb-client.properties(打包在jar / META_INF中):

endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

When I execute the main Method I get the following error message (same thing occurs when trying the wildfly quickstart that I mentioned above): 当我执行main方法时,我收到以下错误消息(尝试上面提到的wildfly快速入门时发生了同样的事情):

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:ejb-test-backend.jar, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@497470ed
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:774)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
    at com.sun.proxy.$Proxy0.greet(Unknown Source)
    at Main.main(Main.java:16)

When I use the remote naming approach everything is fine: 当我使用远程命名方法时,一切都很好:

Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
props.put("jboss.naming.client.ejb.context", true);
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
Context context = new InitialContext(props);

String jndiLookup = "/ejb-test-backend.jar/Hello!" + HelloRemote.class.getName();
HelloRemote hello = (HelloRemote) context.lookup(jndiLookup);
System.out.println(hello.greet("World"));

Output here is (as expected): 这里的输出是(如预期的那样):

Hello World

So is there anyone who knows what could be wrong here or better, who has a working example for remote EJB invocation on Wildfly using the EJB client API? 那么,有没有人知道这里或哪里可能出什么问题了,并且有使用EJB客户端API进行Wildfly远程EJB调用的有效示例? Thanks in advance! 提前致谢!

As so often, I stumbled over the solution shortly after writing down the question and talking about it. 通常,在写下问题并讨论之后不久,我偶然发现了解决方案。

The problem with this setup was that the jboss-ejb-client.properties file has not been loaded by the client API which was then missing the connection url, ... 此设置的问题是客户端API尚未加载jboss-ejb-client.properties文件,该文件随后丢失了连接URL,...

I don't know whether there where changes to the required location where these properties have to be placed or whether I was too dumb to read it correctly or whether I just adapted a tutorial that was corrupted. 我不知道是否对必须放置这些属性的位置进行了更改,或者我是否太笨而无法正确阅读它,或者我是否只是改编了已损坏的教程。 It doesn't even matter ;) 甚至都没有关系;)

The solution is to place the properties file toplevel on the classpath and not in the META-INF directory of the JAR! 解决方案是将属性文件放在顶层,而不是放在JAR的META-INF目录中!

It works now as expected and I can register client-side interceptors. 现在它可以按预期运行,我可以注册客户端拦截器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM