2013-05-29 4 views
0

cometD와 Longpolling에서 Tomcat 작업을하는 데 문제가 있습니다.CometD와 Tomcat이 긴 폴링을 사용하지 않습니다.

투표는 최소 1 초 동안 있어야하지만 모든 요청은 ms 영역에 있습니다. 서버가 ms 시간 내에 응답하지 않습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    version="3.0"> 

<servlet> 
    <servlet-name>cometd</servlet-name> 
    <servlet-class>org.cometd.server.CometdServlet</servlet-class> 
    <init-param> 
     <param-name>transports</param-name> 
     <param-value>org.cometd.websocket.server.JSONTransport</param-value> 
    </init-param> 
    <init-param> 
     <param-name>allowedTransports</param-name> 
     <param-value>org.cometd.server.transport.LongPollingTransport</param-value> 
    </init-param> 
    <init-param> 
     <param-name>services</param-name> 
     <param-value>com.xxxxx.StockPriceService</param-value> 
    </init-param> 
    <init-param> 
     <param-name>timeout</param-name> 
     <param-value>60000</param-value> 
    </init-param> 
    <init-param> 
     <param-name>logLevel</param-name> 
     <param-value>3</param-value> 
    </init-param> 
    <init-param> 
     <param-name>interval</param-name> 
     <param-value>0</param-value> 
    </init-param> 
    <init-param> 
     <param-name>long-polling.multiSessionInterval</param-name> 
     <param-value>2000</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    <async-supported>true</async-supported> 
</servlet> 
<servlet-mapping> 
    <servlet-name>cometd</servlet-name> 
    <url-pattern>/cometd/*</url-pattern> 
</servlet-mapping> 

<servlet> 
    <servlet-name>initializer</servlet-name> 
    <servlet-class>com.xxxxx.Initializer</servlet-class> 
    <load-on-startup>2</load-on-startup> 
</servlet> 

<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> 

<filter> 
    <filter-name>continuation</filter-name> 
    <filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>continuation</filter-name> 
    <url-pattern>/cometd/*</url-pattern> 
</filter-mapping> 

내 치어가

8ms 
    dojo.j...ssed.js (Zeile 11610) 
    POST http://localhost:8080/chatty/cometd/connect 

    200 OK 
       4ms 
      dojo.j...ssed.js (Zeile 11610) 
     POST http://localhost:8080/chatty/cometd/connect 

    200 OK 
    2ms 
    dojo.j...ssed.js (Zeile 11610) 
    POST http://localhost:8080/chatty/cometd/connect 

내 web.xml의 : 이 받는다는 전쟁 - 플러그인 을 설치 여기

내가 방화범에있어 무엇인가,451,515, org.cometd.javascript cometd - 자바 스크립트 도장 org.mortbay.jetty 부두-받는다는 - 플러그인 /

<dependencies> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.cometd.java</groupId> 
     <artifactId>bayeux-api</artifactId> 
     <version>${cometd-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.cometd.javascript</groupId> 
     <artifactId>cometd-javascript-dojo</artifactId> 
     <version>${cometd-version}</version> 
     <type>war</type> 
    </dependency> 
    <dependency> 
     <groupId>org.cometd.java</groupId> 
     <artifactId>cometd-java-server</artifactId> 
     <version>${cometd-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.cometd.java</groupId> 
     <artifactId>cometd-java-annotations</artifactId> 
     <version>${cometd-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.cometd.java</groupId> 
     <artifactId>cometd-java-client</artifactId> 
     <version>${cometd-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.cometd.java</groupId> 
     <artifactId>cometd-websocket-jetty</artifactId> 
     <version>${cometd-version}</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.cometd.java</groupId> 
       <artifactId>cometd-java-client</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-util</artifactId> 
     <version>${jetty-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-jmx</artifactId> 
     <version>${jetty-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-continuation</artifactId> 
     <version>${jetty-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-websocket</artifactId> 
     <version>${jetty-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-servlets</artifactId> 
     <version>${jetty-version}</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.eclipse.jetty</groupId> 
       <artifactId>jetty-client</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>${slf4j-version}</version> 
    </dependency> 
</dependencies> 

longpoll 구성에 대해 뭔가 빠졌습니까?

+0

누군가이 코드 기반으로 긴 폴링 예제를 만들 수 있습니다. https://github.com/cometd/cometd-tutorials/tree/master/client-hello – Androidewbie

답변

0

필터는 org.eclipse.jetty.continuation.ContinuationFilter

2

web.xml은 실제로 잘못되었습니다.

우선 long-polling 전송을 사용하려는 경우 transports < init-param >을 지정할 필요가 없습니다. 이 매개 변수는 websocket과 같은 추가 전송 용입니다. 이것은 here으로 설명됩니다.

매개 변수 allowedTransports은 전체 이름이 아닌 클래스 인 전송을 지정합니다. 이것은 here입니다.

services 매개 변수는 으로, here (6.4.2.3.4 절 참조)에 설명 된 대로만 읽을 수 있습니다.

primer을보고 초기 웹 응용 프로그램을 설정하고 tutorials을 따르십시오. 은 web.xml에서

+0

당신 말이 맞습니다. 서블릿 클래스를 수정했습니다. 이 예제는 부두에서 작동합니다. 내가 가지고있는 문제는 그것을 바람둥이와 웹 소켓으로 돌리는 것이다. – Androidewbie

0

나는 당신이 당신의 문제를 해결하면 잘 모릅니다 예를 들어 진정한 으로 표시해야합니다. Faye Browser 클라이언트 (JS)를 사용하여 동일한 문제가 발생했습니다. 필자의 경우 프로젝트에 새로운 Transport 클래스를 추가하고 web.xml에 포함 시켰을 때 작동하기 시작했습니다.

은 아래를 참조, 웹에 포함

package org.foo.bar.http.transports; 

import java.util.Enumeration; 

import java.io.IOException; 
import java.text.ParseException; 
import javax.servlet.ServletOutputStream; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

import org.cometd.bayeux.server.ServerMessage; 
import org.cometd.server.BayeuxServerImpl; 
import org.cometd.server.ServerSessionImpl; 
import org.cometd.server.transport.LongPollingTransport; 


public class CrossOriginLongPollingTransport extends LongPollingTransport 
{ 
    public final static String PREFIX = "long-polling-cross-origin.json"; 
    public final static String NAME = "cross-origin-long-polling"; 
    public final static String MIME_TYPE_OPTION = "mimeType"; 

    private boolean _jsonDebug = false; 
    private String _mimeType = "application/json;charset=UTF-8"; 

    public CrossOriginLongPollingTransport(BayeuxServerImpl bayeux) 
    { 
     super(bayeux, NAME); 
     setOptionPrefix(PREFIX); 
    } 

    @Override 
    protected boolean isAlwaysFlushingAfterHandle() 
    { 
     return false; 
    } 

    @Override 
    protected void init() 
    { 
     super.init(); 
     _jsonDebug = getOption(JSON_DEBUG_OPTION, _jsonDebug); 
     _mimeType = getOption(MIME_TYPE_OPTION, _mimeType); 
    } 

    @Override 
    public boolean accept(HttpServletRequest request) 
    { 
     return "POST".equals(request.getMethod()); 
    } 

    @Override 
    protected ServerMessage.Mutable[] parseMessages(HttpServletRequest request) throws IOException, ParseException 
    { 
     String charset = request.getCharacterEncoding(); 
     if (charset == null) 
      request.setCharacterEncoding("UTF-8"); 
     String contentType = request.getContentType(); 
     if (contentType == null || contentType.startsWith("application/json")) 
      return parseMessages(request.getReader(), _jsonDebug); 
     else if (contentType.startsWith("application/x-www-form-urlencoded")) { 
      return parseMessages(request.getParameterValues(MESSAGE_PARAM)); 
     } else 
      throw new IOException("Invalid Content-Type " + contentType); 
    } 

    @Override 
    protected ServletOutputStream beginWrite(HttpServletRequest request, HttpServletResponse response, ServerSessionImpl session) throws IOException 
    { 
     response.setContentType(_mimeType); 
     ServletOutputStream output = response.getOutputStream(); 
     output.write('['); 
     return output; 
    } 

    @Override 
    protected void endWrite(ServletOutputStream output, ServerSessionImpl session) throws IOException 
    { 
     output.write(']'); 
     output.close(); 
    } 
} 

후.xml :

<init-param> 
     <param-name>transports</param-name> 
     <param-value>org.cometd.websocket.server.WebSocketTransport,org.foo.bar.http.transports.CrossOriginLongPollingTransport</param-value> 
    </init-param> 
    <init-param> 
     <param-name>allowedTransports</param-name> 
     <param-value>cross-origin-long-polling,long-polling,callback-polling,websocket</param-value> 
    </init-param> 

제게 도움이 되었으면 좋겠어요.

최고.