0
votes

I have an activemq broker deployed within my jboss server. activemq is deployed as a rar file placed in jboss standalone/deployment repository. An other project is also deployed within my jboss as an ear file.
This last is exposing some ejb objects in my jboss. I tried to get an ejb from a jar file that I put into my activemq rar file. A class placed within the jar is called when I connect a client to the broker.

This is how I tried to get ejb within jar file:

  Context ctx; 
  Properties jndiProps = new Properties(); 
  jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
  jndiProps.put("jboss.naming.client.ejb.context", true); 
  ctx = new InitialContext(jndiProps); 
  Ctx.lookup("ejb:Hemis/HemisCoreClient//"+ "HardwareDataManagement" + "!" + "com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement");

Log from jboss when ejb is exposed:

11:50:17,538 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named HardwareDataManagement in deployment unit subdeployment "HemisCoreClient.jar" of deployment "Hemis.ear" are as follows:

java:global/Hemis/HemisCoreClient/HardwareDataManagement!com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement java:app/HemisCoreClient/HardwareDataManagement!com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement java:module/HardwareDataManagement!com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement java:jboss/exported/Hemis/HemisCoreClient/HardwareDataManagement!com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement java:global/Hemis/HemisCoreClient/HardwareDataManagement java:app/HemisCoreClient/HardwareDataManagement java:module/HardwareDataManagement*

The log error when I try to connect client to the broker:

17:26:15,555 ERROR [stderr] (qtp1869699331-251) javax.naming.NameNotFoundException; remaining name 'java:Hemis/HemisCoreClient//HardwareDataManagement!com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement' 17:26:15,556 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:490) 17:26:15,557 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:536) 17:26:15,557 ERROR [stderr] (qtp1869699331-251) at javax.naming.InitialContext.lookup(InitialContext.java:411) 17:26:15,558 ERROR [stderr] (qtp1869699331-251) at authentification.TokenAuthentificationBroker.addConnection(TokenAuthentificationBroker.java:46) 17:26:15,558 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:97) 17:26:15,558 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:733) 17:26:15,559 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79) 17:26:15,559 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139) 17:26:15,560 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:292) 17:26:15,561 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:149) 17:26:15,562 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83) 17:26:15,562 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.transport.ws.MQTTSocket.sendToActiveMQ(MQTTSocket.java:112) 17:26:15,563 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.transport.mqtt.MQTTProtocolConverter.sendToActiveMQ(MQTTProtocolConverter.java:133) 17:26:15,564 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.transport.mqtt.MQTTProtocolConverter.onMQTTConnect(MQTTProtocolConverter.java:235) 17:26:15,564 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.transport.mqtt.MQTTProtocolConverter.onMQTTCommand(MQTTProtocolConverter.java:157) 17:26:15,566 ERROR [stderr] (qtp1869699331-251) at org.apache.activemq.transport.ws.MQTTSocket.onMessage(MQTTSocket.java:59) 17:26:15,566 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455$WSFrameHandler.onFrame(WebSocketConnectionRFC6455.java:860) 17:26:15,567 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.websocket.WebSocketParserRFC6455.parseNext(WebSocketParserRFC6455.java:349) 17:26:15,568 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455.handle(WebSocketConnectionRFC6455.java:225) 17:26:15,568 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) 17:26:15,569 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) 17:26:15,571 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) 17:26:15,571 ERROR [stderr] (qtp1869699331-251) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) 17:26:15,572 ERROR [stderr] (qtp1869699331-251) at java.lang.Thread.run(Thread.java:745)

When I try this code from a class inside the ear which is exposing EJB, it work and I can get EJB object. Do I think that the problem is that I try to get ejb from jar included in rar deployed in my jboss. Could someone help me with this?

2

2 Answers

0
votes

It should not be necessary to perform a remote lookup like that.

The following should work:

 Context ctx = new InitialContext();
 ... = ctx.lookup("java:global/Hemis/HemisCoreClient/HardwareDataManagement!com.ubiant.hemis.client.ejb.interf.I_HardwareDataManagement");

Objects in the java:global/... namespace are accessible from within any module deployed on the server instance.

0
votes

As I posted at http://activemq.2283324.n4.nabble.com/Adding-activemq-jetty-all-jar-for-using-ws-doesn-t-allow-me-anymore-getting-jboss-exposed-ejb-tp4727190p4727305.html, I believe your question boils down to the following:

When a webapp deployed to JBoss contains jetty-all.jar, the Jetty classes cause the default InitialContext to be created as a Jetty class. How can I get a JBoss InitialContext instead, to allow lookups of EJBs exposed by JBoss?

It seems like the Jetty JAR is setting the InitialContextFactory class property to something Jetty-specific, overriding the JBoss-specific value set by the JBoss JARs. To force it back to the JBoss class, can you try setting the following option when creating your InitialContext?

props.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory");

If the problem really is just that you're getting the wrong JNDI context, that line should solve the problem.