2012-02-14 123 views
0

我正在將CometD集成到Grails 2.0應用程序中(通過創建一個新的插件 - 我沒有使用現有的cometd插件,因爲它現在看起來很破碎)。我相信我已經正確配置了一切。我所經歷的是,當瀏覽器連接時,初始元/握手會成功。但是,之後的每個元/連接調用都會返回多個客戶端設置爲true的建議,關閉長輪詢連接。然後每2秒發生一次(我相信的默認時間間隔)。爲什麼我只有一個客戶端連接時獲得多客戶端:來自cometd的真正建議?

正如我所說的,我正在使用Grails 2.0和tomcat 7,這是Grails默認使用的。

這裏是我目前看到的:

電話/元/握手

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正在在瀏覽器中設置。與內容長度和ID在每每個請求變更請求負載

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 

:到/元的後續調用/連接是這個樣子。第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

我不認爲你的插件在GitHub或任何地方?我想用我的Grails 2應用程序來使用CometD,但是我不喜歡現有CometD插件的蜘蛛網外觀... – 2012-07-25 18:17:45

+0

我已經將它放在專用的bitbucket存儲庫中。這絕對不是功能完整的,沒有文檔。我並不打算髮布它,並且目前還沒有開發它(因爲我沒有在任何使用彗星的項目ATM上工作)。如果沒有人關心你,我當然願意開放它。 – aasukisuki 2012-07-26 17:59:55

+0

無論如何,當我試圖讓自己的事情發揮作用時,可能是值得一提的。謝謝! – 2012-07-26 22:40:27

回答

0

看起來,這與Grails 2.0.0中的一個錯誤有關。升級到Grails 2.0.1(今天發佈)後,錯誤自行解決。