所有
我使用ActiveMQ 5.5 AjaxServlet通过JavaScript启用ActiveMQ队列/主题监听。
当主题不受用户名和安全保护时,此方法可以正常工作密码;但是,一旦它,我正在努力找出正确的配置来验证主题订阅。
大多数ActiveMQ文档都是基于Spring的,但我只是在这种情况下使用AjaxServlet。因此,我留下了web.xml作为指定身份验证参数的方法。也许我只是使用不正确的参数名称? ActiveMQ Web演示都没有连接到安全主题。
向建议开放!
这是我当前与我的“ActiveMQ-JS”WAR一起部署的web.xml文件。我也尝试在?userName=xyz&password=xyz
内部指定brokerURL
,但这似乎会导致问题。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>activemq-js</display-name>
<context-param>
<param-name>org.apache.activemq.brokerURL</param-name>
<param-value>failover://tcp://127.0.0.1:61616</param-value>
</context-param>
<context-param>
<param-name>org.apache.activemq.userName</param-name>
<param-value>username_to_topic</param-value>
</context-param>
<context-param>
<param-name>org.apache.activemq.password</param-name>
<param-value>password_to_topic</param-value>
</context-param>
<context-param>
<param-name>org.apache.activemq.embeddedBroker</param-name>
<param-value>false</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>
</servlet>
<servlet-mapping>
<servlet-name>AjaxServlet</servlet-name>
<url-pattern>/amq/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>session</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>session</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
答案 0 :(得分:0)
创建一个自定义的ajax servlet,它将扩展AjaxServlet并更改用户名和密码。
public class MyAjaxServlet extends AjaxServlet{
protected AjaxWebClient getAjaxWebClient( HttpServletRequest request ) {
AjaxWebClient client = super.getAjaxWebClient(request);
client.setUsername("test");
client.setPassword("test");
return client;
}
}
使用自定义ajax servlet更新web.xml。
<servlet>
<servlet-name>MyAjaxServlet</servlet-name>
<servlet-class>com.example.esb.web.MyAjaxServlet</servlet-class>
<init-param>
<param-name>maximumReadTimeout</param-name>
<param-value>120000</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>MyAjaxServlet</servlet-name>
<url-pattern>/amq/*</url-pattern>
</servlet-mapping>