2013-07-23 76 views
3

我有一個運行在Tomcat7上的Java應用程序,它使用了Atmosphere Framework。大氣是一個Websocket框架。我使用Atmosphere Sample Chat的示例應用程序。 我的問題是,我沒有得到連接器以及運行我的Websocket Atmosphere應用程序的正確配置。如何配置Tomcat和HAProxy以使用WebSocket Framework大氣?

問題我已經是:

  1. 我希望如何配置我的HAProxy的?
  2. 如何配置我的Tomcat服務器?
  3. 如何爲APR和NIO連接器配置Tomcat?
  4. 我是否必須在我的應用程序(即我的web.xml)中更改某些內容?
  5. 如何解決下面的錯誤?

這是我HAProxy的配置:

defaults 
mode http 
log global 
option httplog 
option http-server-close 
option dontlognull 
option redispatch 
option contstats 
retries 3 
backlog 10000 
timeout client  25s 
timeout connect  5s 
timeout server  25s 
# timeout tunnel available in ALOHA 5.5 or HAProxy 1.5-dev10 and higher 
# timeout tunnel 3600s 
timeout http-keep-alive 1s 
timeout http-request  15s 
timeout queue  30s 
timeout tarpit  60s 
default-server inter 3s rise 2 fall 3 
option forwardfor 


frontend ft_web 
    bind *:80 name http 
    maxconn 60000 

    acl host_testhostdev hdr(host) -i www.testhost.com 

    use_backend apache-8080 if host_testhostdev 

    default_backend apache-8080 


backend apache-8080 
    balance roundrobin 

    server websrv1 localhost:8080 maxconn 8000 weight 10 cookie websrv1 check 

的web.xml一部分,我的Servlet的氣氛:

<async-supported>true</async-supported> 
<init-param> 
    <param-name>org.atmosphere.useNative</param-name> 
    <param-value>true</param-value> 
</init-param> 

<init-param> 
<param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name> 
    <param-value>org.atmosphere.interceptor.HeartbeatInterceptor,org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor,org.atmosphere.client.TrackMessageSizeInterceptor</param-value> 
</init-param> 

<init-param> 
    <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name> 
    <param-value>true</param-value> 
</init-param> 

<init-param> 
    <param-name>org.atmosphere.cpr.sessionSupport</param-name> 
    <param-value>true</param-value> 
</init-param> 
<init-param> 
    <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name> 
    <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value> 
</init-param> 

我在Tomcat的server.xml中改變什麼

!-- 
<Connector port="8080" protocol="HTTP/1.1" 
      connectionTimeout="20000" 
      redirectPort="8443" /> 
--> 

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/> 

這些都是錯誤我得到:

2013-08-02 11:03:11,384 [http-nio-8080-exec-26] ERROR test.ReflectionService - 
Service method exception in publishDataCreatedCount in service ClientNotificationUpdateService 
java.lang.NullPointerException 
at org.atmosphere.cpr.AtmosphereRequest.setAttribute(AtmosphereRequest.java:569) 
at org.atmosphere.cpr.DefaultBroadcaster.executeAsyncWrite(DefaultBroadcaster.java:922) 
at org.atmosphere.util.SimpleBroadcaster.queueWriteIO(SimpleBroadcaster.java:192) 
at org.atmosphere.cpr.DefaultBroadcaster.deliverPush(DefaultBroadcaster.java:768) 
at org.atmosphere.cpr.DefaultBroadcaster.push(DefaultBroadcaster.java:666) 
at org.atmosphere.util.SimpleBroadcaster.broadcast(SimpleBroadcaster.java:133) 
at test.ClientUpdateService.sendToBoard(ClientUpdateService.groovy:46) 
at test.ClientNotificationUpdateService.publishDataCreatedCount(ClientNotificationUpdateService.groovy:179) 
at test.ReflectionService.callByConvention(ReflectionService.groovy:59) 
at test.ClientUpdateService.methodMissing(ClientUpdateService.groovy:65) 
at test.NotificationService.create(NotificationService.groovy:206) 
at test.HomeController.addAction(HomeController.groovy:402) 
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195) 
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:724) 

而這一次,如果我訪問我的IE8和IE9應用:

2013-08-08 00:56:19,631 [http-nio-8080-exec-9] ERROR cpr.AtmosphereFramework - AtmosphereFramework exception 
java.lang.IllegalStateException: Not supported. 
    at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:594) 
    at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:130) 
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:105) 
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:65) 
    at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:87) 
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:61) 
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1594) 
    at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:176) 
    at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:162) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:722) 
2013-08-08 00:56:19,670 [http-nio-8080-exec-2] ERROR cpr.AtmosphereFramework - AtmosphereFramework exception 
java.lang.IllegalStateException: Not supported. 
    at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:594) 
    at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:130) 
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:105) 
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:65) 
    at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:87) 
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:61) 
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1594) 
    at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:176) 
    at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:162) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:722) 

回答

2

好這裏是我會做的。在您的Tomcat服務器上安裝APR連接器。這將加速生產環境。下載APR並按照安裝說明在您的操作系統上編譯它。您不再需要NIO連接器。

編輯您的server.xml:

<Connector port="8080" 
      protocol="org.apache.coyote.http11.Http11AprProtocol" 
      URIEncoding="UTF-8" 
      maxThreads="250" 
      redirectPort="8443" /> 

不要使用此導致錯誤對我來說org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor。

您的HAProxy配置沒問題。您還應該使用atmosphere-runtime-native.jar而不是atmosphere-runtime.jar。

您的錯誤可能會發生,因爲您將不支持websockets的瀏覽器連接到使用websockets的應用程序。