Adding an item to a HornetQ queue from a servlet

112 views Asked by At

I have a project that gets built as a war file and deployed to a JBOSS server. The JBOSS server's standalone-full-ha.xml file is configured to create several queues. The war file uses Spring to register a class to listen to these queues, and process the messages it gets. The application that normally puts messages on the queue is written by another vendor; I don't have visibility into what that code is like. However, I need to be able to add messages to the queue in my dev environment for testing purposes.

I wrote a small servlet and added it to the war to attempt this test. However, I'm getting an exception when I call the servlet:

13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1) javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeExcept
ion: Operation failed with status WAITING]
13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121
)
13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.InitialContext.init(InitialContext.java:242)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.InitialContext.<init>(InitialContext.java:216)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at com.me.me.servlets.SingleFileImportServlet.doGet(SingleFileImportServlet.java:75)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.ja
va:67)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.j
ava:48)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java
:169)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at java.lang.Thread.run(Thread.java:745)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1) Caused by: java.lang.RuntimeException: Operation failed with status WAITING
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:89)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFacto
ry.java:166)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.jav
a:139)
13:54:12,273 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104
)
13:54:12,273 ERROR [stderr] (http-/0.0.0.0:8080-1)      ... 22 more

This is the code before and up to line 75 (referenced in the stack trace). It's borrowed from a previous test, so I have some reason to believe it should work.

Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

properties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
properties.put(Context.SECURITY_PRINCIPAL, "user");
properties.put(Context.SECURITY_CREDENTIALS, "pwd");

ConnectionFactory connectionFactory = null;
Destination destination = null;

try {
    Context context = new InitialContext(properties);

So a few questions: 1) Can you see anything that I need to do differently in this servlet to connect to the queue? 2) Is there documentation for valid other values where I have "remote://"? 3) Presumably the port where I have 4447 needs to match something in the JBOSS config - is there documentation around that?

Thanks

1

There are 1 answers

4
shonky linux user On BEST ANSWER

The Factory, URL and security principles being passed to InitialContext are only required when performing a JNDI lookup from outside the server.

If the war containing your test servlet is being deployed inside the same server that has the queues configured then you should be able to just instantiate a new InitialContext() without any properties to perform a lookup against the local JDNI instance.

try {
    Context context = new InitialContext();