我正在尝试从嵌入式jetty服务器中运行的代码访问jbossAS7.1中公开的ejb:
final Properties jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
jndiProperties.put("jboss.naming.client.ejb.context", true);
jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
jndiProperties.put(Context.SECURITY_PRINCIPAL, "ubiant");
jndiProperties.put(Context.SECURITY_CREDENTIALS, "ubiant2iA");
ctx = new InitialContext(jndiProperties);
Object b = ctx.lookup("ejb:Hemis/HemisCoreClient//" + "HardwareDataManagement" + "!" + "com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement");
但是我得到了这个例外: " EJB客户端上下文选择器可能不会被更改"
有人可以帮我这个吗?
这里是完整的堆栈跟踪:
11:17:43,003错误[stderr](qtp10117087-119) javax.naming.NamingException:无法创建远程连接 [根异常是java.lang.RuntimeException:无法设置EJB 远程上下文]
11:17:43,011错误[stderr](qtp10117087-119)at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
11:17:43,011错误[stderr](qtp10117087-119)at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
11:17:43,012错误[stderr](qtp10117087-119)at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
11:17:43,012错误[stderr](qtp10117087-119)at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
11:17:43,012错误[stderr](qtp10117087-119)at javax.naming.InitialContext.init(InitialContext.java:242)
11:17:43,012错误[stderr](qtp10117087-119)at javax.naming.InitialContext中。(InitialContext.java:216)
11:17:43,012错误[stderr](qtp10117087-119)at authentification.TokenAuthentificationBroker.addConnection(TokenAuthentificationBroker.java:86)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:97)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:733)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:292)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.broker.TransportConnection $ 1.onCommand(TransportConnection.java:149)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.transport.ws.MQTTSocket.sendToActiveMQ(MQTTSocket.java:112)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.transport.mqtt.MQTTProtocolConverter.sendToActiveMQ(MQTTProtocolConverter.java:133)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.transport.mqtt.MQTTProtocolConverter.onMQTTConnect(MQTTProtocolConverter.java:235)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.transport.mqtt.MQTTProtocolConverter.onMQTTCommand(MQTTProtocolConverter.java:157)
11:17:43,012错误[stderr](qtp10117087-119)at org.apache.activemq.transport.ws.MQTTSocket.onMessage(MQTTSocket.java:59)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455 $ WSFrameHandler.onFrame(WebSocketConnectionRFC6455.java:860)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.websocket.WebSocketParserRFC6455.parseNext(WebSocketParserRFC6455.java:349)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455.handle(WebSocketConnectionRFC6455.java:225)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.io.nio.SelectChannelEndPoint $ 1.run(SelectChannelEndPoint.java:52)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
11:17:43,012错误[stderr](qtp10117087-119)at org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:543)
11:17:43,012错误[stderr](qtp10117087-119)at java.lang.Thread.run(Thread.java:745)
11:17:43,012错误[stderr](qtp10117087-119)引起: java.lang.RuntimeException:无法设置EJB远程上下文
11:17:43,012错误[stderr](qtp10117087-119)at org.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:438)
11:17:43,012错误[stderr](qtp10117087-119)at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:115)
11:17:43,012错误[stderr](qtp10117087-119)... 25更多
11:17:43,012错误[stderr](qtp10117087-119)引起: java.lang.reflect.InvocationTargetException
11:17:43,012错误[stderr](qtp10117087-119)at sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)
11:17:43,012错误[stderr](qtp10117087-119)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
11:17:43,028错误[stderr](qtp10117087-119)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11:17:43,028错误[stderr](qtp10117087-119)at java.lang.reflect.Method.invoke(Method.java:606)
11:17:43,028错误[stderr](qtp10117087-119)at org.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:420)
11:17:43,028错误[stderr](qtp10117087-119)... 26更多
11:17:43,028错误[stderr](qtp10117087-119)引起: java.lang.SecurityException:EJB客户端上下文选择器可能不是 改变
11:17:43,028错误[stderr](qtp10117087-119)at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:181)
11:17:43,028错误[stderr](qtp10117087-119)at org.jboss.naming.remote.client.ejb.RemoteNamingEjbClientContextSelector.setupSelector(RemoteNamingEjbClientContextSelector.java:18)
11:17:43,028错误[stderr](qtp10117087-119)... 31更多
答案 0 :(得分:0)
根据https://developer.jboss.org/thread/273859,"设置jboss.naming.client.ejb.context = true尝试创建一个EJB客户端上下文选择器,但它已经为JBoss EAP 6实例创建了,#34 ; so"如果客户端在[JBoss]服务器内部运行,则无法更改ejbSelector,正如您所做的那样。该线程中的建议是使用范围上下文功能(7.5.4. Using Scoped EJB Client Contexts)来处理与您类似的情况。
顺便说一下,我认为可能有效的另一种方法是返回执行本地(非远程)查找,这种查找依赖于您的代码最终在JBoss内部运行的事实,就像您最初尝试的那样在你的第一个问题(Get EJB object inside rar deployed inside jboss)中做。但是https://developer.jboss.org/thread/273428说"你需要实现Remote接口才能从不同的应用程序ear / jar中查找它,"所以我认为这不是一个可行的选择,而你接近它的方式(进行远程调用)听起来就像是正确的方法。编辑1,基于2017年6月23日的评论:
基于"远程可访问的JNDI对象的先决条件"在https://docs.jboss.org/author/display/AS72/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project的部分中,只有满足两个条件时才会远程暴露EJB:
1)此类对象应绑定在java:jboss / exported /下 命名空间。例如,java:jboss / exported / foo / bar
2)绑定到java:jboss / exported / namespace的对象应该是可序列化的。 这允许通过线路将对象发送到远程客户端
当我查看显示从your original question注册的EJB的日志时,我看不到任何迹象表明您尝试访问的EJB正在{{1}下绑定命名空间。为了使远程查找起作用,我认为除了使用作用域上下文之外,您还需要弄清楚如何在该命名空间下绑定EJB。