我正在尝试从Java连接到正在运行的ActiveMQ servlet(在Weblogic 12上),但我在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)
代码在这里:
QueueConnectionFactory factory = new ActiveMQConnectionFactory("http://localhost:8888/myApp/amq");
Connection conn = factory.createConnection();
conn.start();
(代码基于此示例:http://activemq.apache.org/hello-world.html)
我非常确定ActiveMQ代理和AjaxServlet很好,因为我可以使用js客户端发送和接收消息。
servlet在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>
...
我发现有人遇到同样的问题,但解决方案不存在:http://blog.gmane.org/gmane.comp.java.activemq.user/month=20090501
以下是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)
答案 0 :(得分:2)
如果您打算尝试使用Ajax servlet,我认为您不需要在Java客户端中创建ActiveMQConnectionFactory
。如果您查看与发行版捆绑在一起的javascript files,那么所有javascript正在构建一个POST请求以将消息放入队列。
如果你看一下ActiveMQ Ajax文档的Client Sending messages部分,它会解释一下场景背后会发生什么。所以我认为如果你想为你的Java客户端使用AjaxServlet,你需要构建一个类似于javascript创建XMLHttpRequest
的方式的HttpServletRequest。
或者,如果您想要关注链接的示例,我相信您需要像这样连接:
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
tcp://localhost:61616
应该有效,因为by default ActiveMQ在端口61616上添加了一个tcp连接器。