1

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

4

1 回答 1

0

是的.....下载cxf-3.0.0框架zip(这里是链接)。解压后,您可以找到示例目录(示例 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>
于 2014-05-29T19:01:24.700 回答