Reputation: 6242
I'm trying to connect from Java to a running ActiveMQ servlet(on Weblogic 12), but I'm getting the following exception on conn.start();
:
javax.jms.JMSException: Could not post command: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:lmdesetup-jab-38449-1378221016985-2:1, clientId = ID:lmdesetup-jab-38449-1378221016985-1:1, clientIp = null, userName = null, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = false, failoverReconnect = false} due to: java.io.IOException: Failed to post command: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:lmdesetup-jab-38449-1378221016985-2:1, clientId = ID:lmdesetup-jab-38449-1378221016985-1:1, clientIp = null, userName = null, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = false, failoverReconnect = false} as response was: HTTP/1.1 500 Internal Server Error [Connection: close, Date: Tue, 03 Sep 2013 15:11:02 GMT, Content-Length: 3092, Content-Type: text/html; charset=UTF-8, X-Powered-By: Servlet/3.0 JSP/2.2]
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:62)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1409)
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1496)
at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:524)
The code is here:
QueueConnectionFactory factory = new ActiveMQConnectionFactory("http://localhost:8888/myApp/amq");
Connection conn = factory.createConnection();
conn.start();
(The code is based on this example: http://activemq.apache.org/hello-world.html)
I'm quite sure the ActiveMQ broker and AjaxServlet are fine, because I can send and receive messages using js client.
The servlet is defined like this in web.xml:
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>vm://localhost</param-value>
</context-param>
<context-param>
<param-name>org.apache.activemq.embeddedBroker</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>AjaxServlet</servlet-name>
<servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>AjaxServlet</servlet-name>
<url-pattern>/amq/*</url-pattern>
</servlet-mapping>
...
I have found someone wlse with the same problem, but the solution is not there: http://blog.gmane.org/gmane.comp.java.activemq.user/month=20090501
Here's the exception from Weblogic:
####<Sep 3, 2013 4:19:32 PM UTC> <Error> <Kernel> <mymachine> <myServer> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1378225172656> <BEA-000802> <ExecuteRequest failed
java.lang.IllegalStateException: Can NOT error at this state: AsyncCompleted.
java.lang.IllegalStateException: Can NOT error at this state: AsyncCompleted
at weblogic.servlet.internal.async.DefaultState.notifyError(AsyncStates.java:62)
at weblogic.servlet.internal.async.AsyncContextImpl.handleError(AsyncContextImpl.java:125)
at weblogic.servlet.internal.async.DispatchHandler.run(DispatchHandler.java:33)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
>
####<Sep 3, 2013 4:19:32 PM UTC> <Error> <HTTP> <mymachine> <myServer> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1378225172779> <BEA-101020> <[ServletContext@1154401993[app:ino-all module:ino path:null spec-version:3.0]] Servlet failed with an Exception
java.lang.UnsupportedOperationException: A destination must be specified.
at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:257)
at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:224)
at org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:300)
at org.apache.activemq.web.WebClient.send(WebClient.java:243)
at org.apache.activemq.web.MessageListenerServlet.doPost(MessageListenerServlet.java:219)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:751)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
at org.apache.activemq.web.SessionFilter.doFilter(SessionFilter.java:45)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
Upvotes: 1
Views: 1977
Reputation: 15310
I don't think you need to create an ActiveMQConnectionFactory
in your Java client if you are going to try using the Ajax servlet. If you look at the javascript files bundled with the distribution, all the javascript is doing is constructing a POST request to put a message to a queue.
If you look at the Client Sending messages section of the ActiveMQ Ajax docs it explains a little of what happens behind the scene. So I think if you want to use the AjaxServlet for your Java client you would need to construct a HttpServletRequest similar to the way the javascript is creating a XMLHttpRequest
.
Alternatively, If you want to follow the example that you linked to, I believe you would need to connect like this:
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
tcp://localhost:61616
should work because by default ActiveMQ adds a tcp connector on port 61616.
Upvotes: 2