1

我正在尝试从 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)
4

1 回答 1

2

ActiveMQConnectionFactory如果您打算尝试使用 Ajax servlet,我认为您不需要在 Java 客户端中创建一个。如果您查看与分发捆绑在一起的javascript 文件,所有 javascript 所做的就是构建一个 POST 请求以将消息放入队列。

如果您查看 ActiveMQ Ajax 文档的客户端发送消息部分,它会解释一些幕后发生的事情。所以我认为如果你想为你的 Java 客户端使用 AjaxServlet,你需要构造一个HttpServletRequest,类似于 javascript 创建XMLHttpRequest.

或者,如果您想遵循链接到的示例,我相信您需要像这样连接:

// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();

tcp://localhost:61616应该可以工作,因为默认情况下ActiveMQ 在端口 61616 上添加了一个 tcp 连接器。

于 2013-09-03T17:07:10.087 回答