原文地址: http:///documentation/cometd-java/server/configuration
CometD
Java 服务器配置 由 sbordet 提交于星期二,2009/11/17-11:40。 CometD
Java 服务器配置 基本配置 CometD
servlet 必须在 web.xml 中的设置。 如果你是入门新手,那么 Maven 已经给你配了web.xml 文件,但在这里我们将详细介绍其配置。 这是 web.xml 示例: <?xml
version="1.0" encoding="UTF-8"?> <web-app
xmlns="http://java./xml/ns/javaee"
xmlns:xsi="http://www./2001/XMLSchema-instance"
xsi:schemaLocation="http://java./xml/ns/javaee
http://java./xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.continuation.ContinuationCometdServlet</servlet-class> <init-param>
<param-name>timeout</param-name>
<param-value>60000</param-value> </init-param> </servlet> <servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern> </servlet-mapping> </web-app> 这个
org.cometd.server.continuation.ContinuationCometdServlet,必须定义并映射在 web.xml,否则,服务器将不能解释 Bayeux 协议。 它通常映射上/cometd / *,但您可以根据您希望的来更改映射 url的模式。 这是ContinuationCometdServlet
的配置初始化参数的列表:
高级的配置 如果您使用的jetty 7,你可能想还配置 CrossOriginFilter。 此过滤器实现跨起源资源共享规范,并允许最近浏览器(如
2009 年 11 月的,Firefox 3.5.x,Chrome 3.x 和 Safari 4.x)实现执行跨域 JavaScript 请求 (请参阅传输章节)。 下面是为 CrossOriginFilter
web.xml 配置的一个示例: <?xml
version="1.0" encoding="UTF-8"?> <web-app
xmlns="http://java./xml/ns/javaee"
xmlns:xsi="http://www./2001/XMLSchema-instance"
xsi:schemaLocation="http://java./xml/ns/javaee
http://java./xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.continuation.ContinuationCometdServlet</servlet-class> <init-param>
<param-name>timeout</param-name>
<param-value>60000</param-value> </init-param> </servlet> <servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern> </servlet-mapping> <filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class> </filter> <filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/cometd/*</url-pattern> </filter-mapping> </web-app> 请参阅本文档的过滤器配置。 |
|
来自: phoneone > 《CometD 2.x》