远程EJB无法在Wildfly上使用EJB Client API [英] Can't get Remote EJB to work with EJB Client API on Wildfly
问题描述
详细来说,它是使用EJB Client API方法从独立的客户端应用程序(不是从另一个应用程序服务器)进行远程调用。远程命名方法适用于我,但不适用于我的场景,因为我需要使用客户端拦截器将上下文数据传递给服务器端拦截器进行远程调用。
但是,现在我尝试使用客户端API获取远程调用,以作一个简单的例子。因此,我尝试了github可用的远程ejb调用的快速启动( wildfly /快速启动/ EJB-远程)。关键是这个quickstart引发了与我的简单示例应用程序相同的错误。以下是我的应用程序的一些细节:
我的远程界面:
package test.ejb;
public interface HelloRemote {
String greet(String name);
}
我的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){
returnHello+ name;
}
}
该bean的远程视图已正确注册在服务器(在导出命名空间中):
java:jboss / exported / ejb-test-backend.jar / Hello!de.coryx .HelloRemote
现在客户端: p>
我的主类:
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 {
属性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));
}
}
jboss-ejb-client.properties (包装在jar / META_INF):
endpoint.name = client-endpoint
remote.connectionprovider .create.options.org.xnio.Options.SSL_ENABLED = false
remote.connections =默认
remote.connection.default.host = localhost
remote.connection.default。 port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS = false
当我执行主方法我得到以下错误消息(同样的事情发生在尝试我上面提到的wildfly快速入门):
线程main中的异常java.lang.IllegalStateException:EJBCLIENT000025:没有EJB接收器可用于处理[appName :, moduleName:ejb-test-backend.jar,distinctName:]组合用于调用上下文org.jboss .ejb.client.EJBClientInvocationContext @ 497470ed
在org.jboss.ejb.client.EJBClientCo在EJBClientContext.java:774中,n EJBClientInvocationContext.java:186)
在org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
在org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java: 200)
在org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
在org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
at com.sun.proxy $ Proxy0.greet(Unknown Source)
在Main.main(Main.java:16)
当我使用远程命名方法时,一切都很好:
属性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));
此处的输出是(如预期):
Hello World
所以有谁知道这里或更好的可能是错误的,谁使用EJB客户端API在Wildfly上进行远程EJB调用的工作示例?
提前感谢!
经常在我写下这个问题后,我偶然发现了解决方案关于它。
此设置的问题是jboss-ejb-client.properties文件尚未被客户端API加载,然后客户端API丢失了连接网址, ...
我不知道这些属性必须放置的位置是否有所更改,或者我是否太愚蠢地无法正确读取它们我刚刚修改了一个被破坏的教程。它不甚重要;)
解决方案是将属性文件放置在类路径上,而不是在JAR的META-INF目录中
它按预期工作,我可以注册客户端拦截器。
I'm currently struggling with getting remote EJB invocation to work on wildfly (8.x and 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. 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. Therefore I tried the quickstart for remote ejb invocation which is available on github (wildfly/quickstart/ejb-remote). 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:
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):
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):
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):
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? 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, ...
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!
It works now as expected and I can register client-side interceptors.
这篇关于远程EJB无法在Wildfly上使用EJB Client API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!