Java WildFly:来自远程客户端的 EJB 调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20817223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WildFly: EJB invocations from a remote client
提问by Tapas Bose
I was trying to lookup and call an EJB deployed as EAR in WildFly. I have tried different ways.
我试图在 WildFly 中查找并调用部署为 EAR 的 EJB。我尝试了不同的方法。
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, myUser);
properties.put(Context.SECURITY_CREDENTIALS, myPassword);
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext context = new InitialContext(properties);
Object object = context.lookup(jndi);
MyService service = (MyService)object;
System.out.println(service.echo("JYM"));
It has thrown:
它抛出了:
javax.naming.NamingException: Failed to connect to any server. Servers tried: [remote://localhost:4447]
at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:213)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:144)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:125)
at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:241)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.app.test.service.MyServiceTest.echo(MyServiceTest.java:60)
If I add the following properties:
如果我添加以下属性:
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put("jboss.ejb.client.scoped.context", "true");
I recieved:
我收到了:
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:roolafic, moduleName:usermanagement, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@3c0f93f1
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:183)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy4.echo(Unknown Source)
at com.app.test.service.MyServiceTest.echo(MyServiceTest.java:62)
Then I saw a Jboss forum postwhich says to use http-remoting
instead of remote
. But that also didn't work. Even using port 8080.
然后我看到了一个Jboss 论坛帖子,上面说要使用http-remoting
而不是remote
. 但这也不起作用。即使使用端口 8080。
I have tried the way mentioned here. But it seems that it would not work for my case. Though I have placed the jboss-ejb-client.properties
in the same directory from where I am running my client method from Eclipse.
我已经尝试过这里提到的方式。但似乎它不适用于我的情况。虽然我已经将它放在了jboss-ejb-client.properties
从 Eclipse 运行我的客户端方法的同一目录中。
采纳答案by Tapas Bose
After spending almost half a day I found the solution. Here it is:
花了将近半天后,我找到了解决方案。这里是:
public static <T> T connectEJB(String jndi) throws NamingException {
Properties clientProperties = new Properties();
clientProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
clientProperties.put("remote.connections", "default");
clientProperties.put("remote.connection.default.port", myPort);
clientProperties.put("remote.connection.default.host", myHost);
clientProperties.put("remote.connection.default.username", myUser);
clientProperties.put("remote.connection.default.password", myPassword);
clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(clientProperties);
ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
EJBClientContext.setSelector(contextSelector);
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(properties);
return (T) context.lookup(jndi);
}
For more information see here. Hope it will be helpful to others.
有关更多信息,请参见此处。希望对其他人有帮助。
回答by 99Sono
I have encountered the same exception on Wildfly 10.
我在 Wildfly 10 上遇到了同样的异常。
While following some important references:
在遵循一些重要参考资料的同时:
Namely documentation on establishing remote EJB connection on: https://docs.jboss.org/author/display/WFLY10/EJB+invocations+from+a+remote+client+using+JNDI
即关于建立远程 EJB 连接的文档:https: //docs.jboss.org/author/display/WFLY10/EJB+invocations+from+a+remote+client+using+JNDI
java.lang.IllegalStateException: EJBCLIENT000025:
No EJB receiver available for handling [appName:, moduleName:wildfly10-test-client-remote-ejb, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@1b26f7b2 at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) 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.$Proxy6.doWork(Unknown Source) at ejb.InvokeRemoteEjbTest.testThatFailsWithEJBCLIENT000025(InvokeRemoteEjbTest.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
java.lang.IllegalStateException: EJBCLIENT000025:
没有 EJB 接收器可用于处理 [appName:, moduleName:wildfly10-test-client-remote-ejb, distinctName:] 组合调用上下文 org.jboss.ejb.client.EJBClientInvocationContext@1b26f7b2 在 org.jboss.ejb.client.EJBClientContext .requireEJBReceiver(EJBClientContext.java:798) 在 org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) 在 org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:1org8) jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200) at org.jboss.eJBvvocationInvocationInvoke(EJBInvocationHandler.java:200) java:183) 在 org.jboss.ejb.client.EJBInvocationHandler。invoke(EJBInvocationHandler.java:146) at com.sun.proxy.$Proxy6.doWork(Unknown Source) at ejb.InvokeRemoteEjbTest.testThatFailsWithEJBCLIENT000025(InvokeRemoteEjbTest.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit .runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively( FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org .junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 在 org。junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 在 org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java) :268) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:363) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 在 org.eclipse.jdt。 internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit。 runner.RemoteTestRunner。runTests(RemoteTestRunner.java:675) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.爪哇:192)
But this test exception was not alone, I also had on the console the following exception:
但是这个测试异常并不孤单,我在控制台上也有以下异常:
NFO: XNIO version 3.3.4.Final Feb 13, 2017 12:42:28 PM org.xnio.nio.NioXnio INFO: XNIO NIO Implementation Version 3.3.4.Final Feb 13, 2017 12:42:28 PM org.jboss.remoting3.EndpointImpl INFO: JBoss Remoting version 4.0.18.Final Feb 13, 2017 12:42:28 PM org.jboss.ejb.client.EJBClient INFO: JBoss EJB Client version 2.1.4.Final Feb 13, 2017 12:42:28 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers WARN: Could not register a EJB receiver for connection to localhost:4447 java.io.EOFException: XNIO000812: Connection closed unexpectedly at org.xnio.http.HttpUpgrade$HttpUpgradeState$UpgradeResultListener.handleEvent(HttpUpgrade.java:416) at org.xnio.http.HttpUpgrade$HttpUpgradeState$UpgradeResultListener.handleEvent(HttpUpgrade.java:400) at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88) at org.xnio.nio.WorkerThread.run(WorkerThread.java:559) at ...asynchronous invocation...(Unknown Source) at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:294) at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:416) at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:192) at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:153) at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133) at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:78) at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:161)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:118) at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47) at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:281) at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:291) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146) at com.sun.proxy.$Proxy6.doWork(Unknown Source) at ejb.InvokeRemoteEjbTest.testThatFailsWithEJBCLIENT000025(InvokeRemoteEjbTest.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
NFO:XNIO 版本 3.3.4.Final 2017 年 2 月 13 日下午 12:42:28 org.xnio.nio.NioXnio 信息:XNIO NIO 实施版本 3.3.4.Final 2017 年 2 月 13 日下午 12:42:28 org.jbos .remoting3.EndpointImpl 信息:JBoss Remoting 版本 4.0.18.Final 2017 年 2 月 13 日下午 12:42:28 org.jboss.ejb.client.EJBClient 信息:JBoss EJB 客户端版本 2.1.4.Final 2017 年 2 月 13 日下午 42:28 org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers 警告:无法注册 EJB 接收器以连接到 localhost:4447 java.io.EOFException:XNIO000812:连接在 org.xnio.http.HttpUpgrade 意外关闭org.xnio.http.HttpUpgrade$HttpUpgradeState$UpgradeResultListener.handleEvent(HttpUpgrade.java:400) 在 org.xnio.ChannelListeners 上的 HttpUpgradeState$UpgradeResultListener.handleEvent(HttpUpgrade.java:416)。invokeChannelListener(ChannelListeners.java:92) at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88) at org.xnio.nio .WorkerThread.run(WorkerThread.java:559) 在...异步调用...(未知来源)在 org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:294) 在 org.jboss.remoting3.EndpointImpl。 connect(EndpointImpl.java:416) at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:192) at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java: 153) 在 org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133) 在 org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:78) 在 org.jboss。ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:161)
在 org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:118) 在 org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java.org.getCurrent(ConfigBasedEJBClientContextSelector.java:4jbjbClientContextSelector) .EJBClientContext.getCurrent(EJBClientContext.java:281) at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:291) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178) org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146) at com.sun.proxy.$Proxy6.doWork(Unknown Source) at ejb.InvokeRemoteEjbTest.testThatFailsWithEJBCLIENT000025(Invoke)EjbTestRemote
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit .runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively( FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org .junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 在 org。junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 在 org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java) :268) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:363) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 在 org.eclipse.jdt。 internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit。 runner.RemoteTestRunner。runTests(RemoteTestRunner.java:675) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.爪哇:192)
The critical point is the following. (1) Jboss seems to have two different layers of code that behave differently. The first one, is the JNDI initial context, that works properly when you connect to a "remoting" port such as the old traditional port 4447.
关键点如下。(1) Jboss 似乎有两个不同的代码层,它们的行为不同。第一个是 JNDI 初始上下文,当您连接到“远程”端口(例如旧的传统端口 4447)时,它可以正常工作。
So when you do in your code for the JNDI context something like:
因此,当您在 JNDI 上下文的代码中执行以下操作时:
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
// why is this needed?
// This is an important property to set if you want to do EJB invocations via the remote-naming project
env.put("jboss.naming.client.ejb.context", true);
// Lookup optimization for @Stateless EJBs.
// https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project
// section: Why use the EJB client API approach then?
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
// authenticate
env.put(Context.SECURITY_PRINCIPAL, "adminUser");
env.put(Context.SECURITY_CREDENTIALS, "adminPassword");
initialContext = new InitialContext(env);
You are OK geting the Remote EJB out of the server, you have the proxy in hand. Where things go really wrong, is when you take the proxu and do something like:
您可以从服务器中取出远程 EJB,您已经拥有代理。真正出错的地方是当您使用 proxu 并执行以下操作时:
remoteEJB.doWorkg();
This happens because the Lookup logic and execute logic on the proxy are not exactly the same, namely, the execute logic is looking for these:
发生这种情况是因为代理上的 Lookup 逻辑和执行逻辑并不完全相同,即执行逻辑正在寻找这些:
"No EJB receiver available for handling "
“没有可用于处理的 EJB 接收器”
based on the configuration file: "jboss-ejb-client.properties"
基于配置文件:“jboss-ejb-client.properties”
That yous should have in your classpath to run your system test. Or your client application.
你应该在你的类路径中运行你的系统测试。或您的客户端应用程序。
Now, when you go to this: jboss-ejb-client.properties
现在,当你去这个:jboss-ejb-client.properties
You can try to confiugure your "remoting" port 4447, but this goes very wrong, because the modern remote EJB client that you get out of using the;
您可以尝试配置您的“远程处理”端口 4447,但这是非常错误的,因为您无法使用现代远程 EJB 客户端;
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>10.0.0.Final</version>
<type>pom</type>
<scope>test</scope>
</dependency>
This client expects that your wildfly 10 is configured with the todays default configuration, where remoting can be serviced from normal HTTP sockets. So it wants to do an HTTP socket upgrade to TCP pretty much like what happens with web sockets. This will not work on your: 4447 socket, which has never been from conception an http socket.
该客户端希望您的 wildfly 10 配置为今天的默认配置,其中远程处理可以从正常的 HTTP 套接字提供服务。因此,它希望将 HTTP 套接字升级到 TCP,就像 Web 套接字发生的那样。这不适用于您的:4447 套接字,它从未从一个 http 套接字开始。
So when I finally went to look how the remote subsystem is configured, I needed to fatten it with the following:
因此,当我最终查看远程子系统的配置方式时,我需要使用以下内容对其进行增肥:
<subsystem xmlns="urn:jboss:domain:remoting:3.0">
<endpoint/>
<connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
<http-connector name="http-remoting-connector" connector-ref="default" security-realm="ApplicationRealm"/>
</subsystem>
The http-connector is the new addition. Now, as far as JNDI initial context setup is concerned, it does not matter if I usee port 4447 or 8080, both work. To keep consistent, i do not use the 4447 port .. which is still open, and I use the 8080 port. Hoever, for 8080 pot your provider URL has to be adapted as follows:
http-connector 是新增的。现在,就 JNDI 初始上下文设置而言,我使用端口 4447 或 8080 都没有关系,两者都可以工作。为了保持一致,我不使用仍然打开的 4447 端口,我使用 8080 端口。但是,对于 8080 pot,您的提供商 URL 必须进行如下调整:
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
My recommendation is: configure both port 4447 and 8080 for your remote ejb subsytem. But for Client conneciton use port 8080, both for JNDI lookup and EJB execution.
我的建议是:为您的远程 ejb 子系统配置端口 4447 和 8080。但是对于客户端连接,使用端口 8080,用于 JNDI 查找和 EJB 执行。
The wildfly exception in this case is borderline useless, it does not help that much the developer figuring out what is going wrong.
在这种情况下,wildfly 异常是无用的,它对开发人员弄清楚出了什么问题没有多大帮助。
The key to this problem was seing the HTTP connection upgrade problem and figuring out that that behavior is obviously wrong for socket 4447.
解决这个问题的关键是看到 HTTP 连接升级问题,并找出套接字 4447 的行为显然是错误的。
Finally, just for reference. Your ejb-client.proeprties file should be something of the form:
最后,仅供参考。您的 ejb-client.proeprties 文件应该是以下形式:
#QUOTE:
#First the endpoint.name property.
#We mentioned earlier that the EJB receivers will communicate with the server for EJB invocations.
#Internally, they use JBoss Remoting project to carry out the communication.
#The endpoint.name property represents the name that will be used to create the client side of the enpdoint.
# The endpoint.name property is optional and if not specified in the jboss-ejb-client.properties file, it will default to "config-based-ejb-client-endpoint" name.
# https://docs.jboss.org/author/display/WFLY10/EJB+invocations+from+a+remote+client+using+JNDI
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
remote.connection.default.username=youAppServerAdmin
remote.connection.default.password=youAppServerAdminPass
The key thing to keep in mind is that the PORT on the above file should be an HTTP port and not a "remoting" port like 4447. At least in wildfly 10, for older versions I am not sure.
要记住的关键是上面文件中的端口应该是 HTTP 端口,而不是像 4447 这样的“远程”端口。至少在 Wildfly 10 中,对于旧版本我不确定。
Good luck.
祝你好运。