如何使用Apache CXF实现推送式RESTful Web服务?

时间:2013-03-20 18:52:08

标签: java asynchronous cxf push servlet-3.0

我们已经在项目中使用Apache CXF,我想知道是否有可能在CXF 2.7中实现推送RESTful服务(Servlet 3.0规范引入的功能)?

1 个答案:

答案 0 :(得分:0)

是.....下载cxf-3.0.0 framework zip(这里是link)。在提取时你可以找到样本目录(样本cxf项目的数量可供我们参考)。在我们的例子中选择jax_rs / websocket目录。您可以找到示例推客户maven项目。我修改了现有的pom.xml,如下所示,导入到eclipse并完美运行。

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.cxf.sample</groupId>
    <artifactId>jax_rs_websocket</artifactId>
    <version>3.0.0</version>
    <name>JAX-RS WebSocket Demo</name>
    <description>JAX-RS WebSocket Demo</description>
    <properties>
        <cxf.version>3.0.0</cxf.version>
        <cxf.ahc.version>1.8.1</cxf.ahc.version>
        <cxf.jetty.version>8.1.14.v20131031</cxf.jetty.version>
        <cxf.netty3.version>3.8.0.Final</cxf.netty3.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>server</id>
            <build>
                <defaultGoal>test</defaultGoal>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>demo.jaxrs.server.Server</mainClass>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>client</id>
            <build>
                <defaultGoal>test</defaultGoal>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>demo.jaxrs.client.Client</mainClass>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- This dependency is needed if you're using the Jetty container -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-websocket</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>
         <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-websocket</artifactId>
            <version>${cxf.jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>com.ning</groupId>
            <artifactId>async-http-client</artifactId>
            <version>${cxf.ahc.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty</artifactId>
            <version>${cxf.netty3.version}</version>
        </dependency>
        <!--  JettyHttpDestination is referring to org.springframework.util.ClassUtils -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>

    </dependencies>
</project>