`
sillycat
  • 浏览: 2491856 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Comet-Jetty(3)Update the Sample

 
阅读更多
Comet-Jetty(3)Update the Sample

Try the sample project cometd-demo

error message when import this to eclipse:
Plugin execution not covered by lifecycle configuration:org.apache.felix:maven-buildle-plugin:2.3.5:manifest(execution:osgi,phase:process-classes)

Solution:
temporarily comments the felix plugin in parent pom.xml

Run this project with command
>mvn jetty:run

Import this project to eclipse
>mvn eclipse:eclipse -Dwtpversion=1.5

Run this project on eclipse
First of all, install http://download.eclipse.org/jetty/updates/jetty-wtp plugin on eclipse:

Download the distributed version of jetty.
http://download.eclipse.org/jetty/

Find my sample project easycometd, start from here.

add this to my pom.xml
org.eclipse.jetty
jetty-server
7.6.4.v20120524

comment the websocket transport

error message:
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1664)
at org.apache.catalina.connector.Request.startAsync(Request.java:1657)

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

error message when running mvn tomcat:run
java.lang.ClassCastException: org.eclipse.jetty.continuation.ContinuationFilter cannot be cast to ja
vax.servlet.Filter

solution:
remove the jar in pom.xml
org.eclipse.jetty
jetty-server
7.6.4.v20120524

At the final testing, it is working. My sample pom.xml will be as follow:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sillycat</groupId>
    <artifactId>easycometd</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
   
    <properties>
<spring.version>3.1.1.RELEASE</spring.version>
<cometd.version>2.5.0-SNAPSHOT</cometd.version>
    </properties>
   
    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>7.6.4.v20120524</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                        <contextPath>/easycometd</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <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-jquery</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-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.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.eclipse.jetty</groupId>
            <artifactId>jetty-servlets</artifactId>
            <version>7.6.4.v20120524</version>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.4</version>
        </dependency>
    </dependencies>
</project>

And here is the cometd-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:groovy="http://www.sillycat.com/schema/groovy"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.sillycat.com/schema/groovy
http://www.sillycat.com/schema/groovy/groovy.xsd
">
     <bean id="bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
        <property name="options">
            <map>
                <entry key="logLevel" value="3" />
                <entry key="timeout" value="15000" />
            </map>
        </property>
        <property name="transports">
            <list>
                <bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
                    <constructor-arg ref="bayeux" />
                </bean>
                <bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
                    <constructor-arg ref="bayeux" />
                </bean>
            </list>
        </property>
    </bean>
   
    <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
        <property name="attributes">
            <map>
                <entry key="org.cometd.bayeux">
                    <ref local="bayeux" />
                </entry>
            </map>
        </property>
    </bean>
</beans>

And some little changes in web.xml to use the spring like my previous project:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:main-context.xml</param-value>
</context-param>
   
    <servlet>
        <servlet-name>cometd</servlet-name>
        <servlet-class>org.cometd.annotation.AnnotationCometdServlet</servlet-class>
        <init-param>
            <param-name>timeout</param-name>
            <param-value>30000</param-value>
        </init-param>
        <init-param>
            <param-name>interval</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>maxInterval</param-name>
            <param-value>10000</param-value>
        </init-param>
        <init-param>
            <param-name>maxLazyTimeout</param-name>
            <param-value>5000</param-value>
        </init-param>
        <init-param>
            <param-name>long-polling.multiSessionInterval</param-name>
            <param-value>2000</param-value>
        </init-param>
        <init-param>
            <param-name>logLevel</param-name>
            <param-value>1</param-value>
        </init-param>
        <init-param>
            <param-name>services</param-name>
            <param-value>com.sillycat.easycometd.comed.chat.service.ChatService</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>cometd</servlet-name>
        <url-pattern>/cometd/*</url-pattern>
    </servlet-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>
   
    <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>
   
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

It is working now. And I will try to refactor this project.

references:
http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01113.html
http://download.eclipse.org/jetty/
https://github.com/flowersinthesand/jquery-socket.git
http://code.google.com/p/jquery-stream/source/checkout
http://code.google.com/p/jquery-stream/wiki/ChatExample
http://cometd.org/documentation/2.x/howtos/servlet-containers
http://svn.cometd.com/trunk/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics