2012-06-08 51 views
1

所有的ActiveMQ的主題的用戶名/密碼,如何指定使用org.apache.activemq.web.AjaxServlet

我使用的ActiveMQ 5.5 AjaxServlet使ActiveMQ的隊列/主題通過JavaScript聽。

此方法在主題不以用戶名&密碼安全保護時正常工作;然而,一旦發現,我很難找出正確的配置來驗證主題訂閱。

大部分的ActiveMQ文檔都是基於Spring,但是我只是在這種情況下使用AjaxServlet。因此,我留下了web.xml作爲指定驗證參數的手段。也許我只是使用不正確的參數名稱?沒有一個ActiveMQ Web Demos連接到受保護的主題。

歡迎指教!

這是我的當前web.xml文件,我與我的「ActiveMQ-JS」WAR一起部署。我也嘗試在brokerURL本身內指定?userName=xyz&password=xyz,但這似乎會導致問題。

<?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

創建定製的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>