我正在努力将CometD集成到Grails 2.0应用程序中(通过创建一个新的插件 - 我没有使用现有的cometd插件,因为它现在看起来很破碎)。我相信我已经正确配置了所有内容。我所经历的是,当浏览器连接时,初始元/握手成功返回。但是,之后的每个meta / connect调用都会返回多个客户端的建议设置为true,从而关闭长轮询连接。然后每2秒发生一次(我相信默认的间隔)。
正如我所说,我正在使用Grails 2.0,这是Grails默认使用的tomcat 7。
以下是我目前看到的内容:
致电/ meta / handshake
Request URL:http://localhost:8080/cometd/handshake
Request Method:POST
Status Code:200 OK
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:182
Content-Type:application/json;charset=UTF-8
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
X-Requested-With:XMLHttpRequest
Request Payload
[{"version":"1.0","minimumVersion":"0.9","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0},"id":"1"}]
Response Headers
Content-Length:201
Content-Type:application/json;charset=UTF-8
Date:Tue, 14 Feb 2012 03:32:24 GMT
Server:Apache-Coyote/1.1
Set-Cookie:BAYEUX_BROWSER=dac8yl3vlli7s8x2gymdm2ca177s; Path=/
这是返回有效载荷:
[{"id":"1","minimumVersion":"1.0","supportedConnectionTypes":["callback-polling","long-polling"],"successful":true,"channel":"/meta/handshake","clientId":"115v93y19uvavr159qvzz43yct1","version":"1.0"}]
我已经确认已在浏览器中设置了Cookie。随后对/ meta / connect的调用如下所示:
Request URL:http://localhost:8080/cometd/connect
Request Method:POST
Status Code:200 OK
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:134
Content-Type:application/json;charset=UTF-8
Cookie:BAYEUX_BROWSER=dac8yl3vlli7s8x2gymdm2ca177s
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
X-Requested-With:XMLHttpRequest
Request Payload
[{"channel":"/meta/connect","connectionType":"long-polling","advice":{"timeout":0},"id":"2","clientId":"115v93y19uvavr159qvzz43yct1"}]
Response Headers
Content-Length:116
Content-Type:application/json;charset=UTF-8
Date:Tue, 14 Feb 2012 03:32:24 GMT
Server:Apache-Coyote/1.1
每个请求的请求有效负载中的content-length和id。前3个电话回来了:
致电1:
[{"id":"2","successful":true,"advice":{"interval":0,"reconnect":"retry","timeout":30000},"channel":"/meta/connect"}]
致电2:
[{"id":"3","successful":true,"channel":"/meta/connect"}]
致电3:
[{"id":"4","successful":true,"advice":{"interval":2000,"reconnect":"retry","multiple-clients":true},"channel":"/meta/connect"}]
从那时起,每个回来的消息都与上一封完全一样。我只打开了一个浏览器窗口/标签页。
以下是web.xml文件的适用部分的副本:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
<init-param>
<param-name>timeout</param-name>
<param-value>30000</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>3</param-value>
</init-param>
</servlet>
...
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
...
</web-app>
BuildConfig.groovy:
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits "global"
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
mavenCentral()
}
dependencies {
def cometVersion = '2.4.0'
compile(group: 'org.cometd.java', name: 'cometd-java-server', version: cometVersion) {
excludes 'servlet-api'
}
compile group: 'org.cometd.java', name: 'bayeux-api', version: cometVersion
runtime group: 'org.eclipse.jetty', name: 'jetty-servlets', version: '7.6.0.v20120127'
test group: 'org.cometd.java', name: 'cometd-java-client', version: cometVersion
}
plugins {
build(":tomcat:$grailsVersion",
":release:1.0.0") {
export = false
}
}
}
最后是CometdGrailsPlugin.groovy的doWithSpring部分:
def doWithSpring = {
bayeux(BayeuxServerImpl) { bean ->
bean.initMethod = 'start'
bean.destroyMethod = 'stop'
}
// the CometdServlet will pick up the Bayeux object from the servlet context
bayeuxAttributeExporter(ServletContextAttributeExporter) {
attributes = [(BayeuxServer.ATTRIBUTE): ref('bayeux')]
}
}
希望这不是太多的信息。过去几天我一直试图解决这个问题,并且已经没有想法,可以真正使用一些帮助
答案 0 :(得分:0)
这似乎与Grails 2.0.0中的错误有关。升级到Grails 2.0.1(今天发布)后,错误自行解决。