Tomcat6上使用ActiveMQ AjaxServlet时,完全没有问题
但是,Tomcat7使用ActiveMQ AjaxServlet时,发生Not supported. exception
具体版本:
Tomcat 7.0.41
ActiveMQ 5.6.0
具体的问题描述,参看以下URL
http://activemq.2283324.n4.nabble.com/AjaxServlet-on-Tomcat-td3601798.html
?
网上搜索了很多方案,都说只要对AjaxServlet加上async-supported支持就可以了。
但是,实际结果还是报同样的异常。
经过长时间的尝试,终于找到问题的原因了。
原来消息请求在AjaxServlet处理前,会先被filter先处理,所以filter也要加上async-supported支持。
具体配置代码如下:
web.xml
<!-- ActiveMQ servlet --> <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> <!-- 著名 Character Encoding filter --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <!-- 强制进行转码 --> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ActiveMQ --> <filter> <filter-name>session</filter-name> <filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class> <async-supported>true</async-supported> </filter> <filter-mapping> <filter-name>session</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
?
?
?
?