java - CXF JAX-RS 客户端空指针异常

标签 java web-services cxf

我正在尝试使用发现的 Apache CXF JAX-RS 客户端 API 代码 here 。但是,当我运行客户端时,它会抛出以下错误:

Exception in thread "main" java.lang.NullPointerException
    at java.util.HashMap.<init>(HashMap.java:223)
    at org.restlet.ext.jaxrs.internal.core.ResponseBuilderImpl.clone(ResponseBuilderImpl.java:126)
    at org.restlet.ext.jaxrs.internal.core.ResponseBuilderImpl.clone(ResponseBuilderImpl.java:62)
    at org.apache.cxf.jaxrs.client.AbstractClient.setResponseBuilder(AbstractClient.java:374)
    at org.apache.cxf.jaxrs.client.ClientProxyImpl.handleResponse(ClientProxyImpl.java:451)
    at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:445)
    at org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:177)
    at $Proxy12.foo(Unknown Source)
    at com.paml.JaxTestClient.main(JaxTestClient.java:20)

这是我的客户:

public class JaxTestClient {

    public static void main( String[] args ) {
        // Works with Restlet API - but paths are not mapped automatically
        // JaxExampleEcho jaxExampleEcho = ClientResource.create( "http://localhost:8111/", JaxExampleEcho.class );

        JaxExampleEcho jaxExampleEcho = JAXRSClientFactory.create( "http://localhost:8111/", JaxExampleEcho.class );
        System.out.println( jaxExampleEcho.foo() );
        System.out.println( jaxExampleEcho.bar() );
        System.out.println( jaxExampleEcho.baz() );
    }
}

这是界面:

@Path( "/" )
public interface JaxExampleEcho {

    @GET
    @Path( "foo" )
    @Produces( "text/plain" )
    String foo();

    @GET
    @Path( "bar" )
    @Produces( "text/plain" )
    String bar();

    @GET
    @Path( "baz" )
    @Produces( "text/plain" )
    String baz();

}

当我在浏览器中使用正确的 URL 运行它时,它工作正常,事实上我在服务器端看到了正确的请求:

Jun 9, 2011 11:06:03 AM org.restlet.engine.log.LogFilter afterHandle
INFO: 2011-06-09    11:06:03    127.0.0.1   -   -   8111    GET /foo    -   200 3   0   1   http://localhost:8111   Apache CXF 2.4.0    -

我很困惑到底是什么原因造成的。我想也许我错过了一个依赖项,所以我回去检查了一下并添加了更多依赖项。我想也许我错过了文档中的某些内容,但我没有看到任何内容。

我是否遗漏了一些明显的东西?有谁知道如何做到这一点?

谢谢。

最佳答案

问题不在于 CXF。问题是我路径上的 JAX-RS ReSTLet 扩展。将以下内容添加到我的 pom 中:

        <exclusions>
            <exclusion>
                <artifactId>org.restlet</artifactId>
                <groupId>org.restlet</groupId>
            </exclusion>
            <exclusion>
                <artifactId>org.restlet.ext.xstream</artifactId>
                <groupId>org.restlet.jse</groupId>
            </exclusion>
            <exclusion>
                <artifactId>org.restlet.ext.jaxrs</artifactId>
                <groupId>org.restlet.jse</groupId>
            </exclusion>
            <exclusion>
                <artifactId>org.restlet.ext.slf4j</artifactId>
                <groupId>org.restlet.jse</groupId>
            </exclusion>
            <exclusion>
                <artifactId>org.restlet</artifactId>
                <groupId>org.restlet.jse</groupId>
            </exclusion>
        </exclusions>

帮我修好了。

关于java - CXF JAX-RS 客户端空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6297377/

相关文章:

java - 使用 Apache POI 在 Word 表中使用单倍行距

java - 发送十六进制命令到 ESC/POS 打印机 Android

c# - 为什么.NET 的 EnableDecompression 默认值在 2.0 和 3.0 之间变化?

cxf - 在 CXF 代理客户端上设置超时

java - 使用类型化集合时编译错误对方法的引用不明确

java - 极小极大算法错误

web-services - Scala 相当于 wsdl2java?

c# - 如何从 C# Web 服务调用 C++ Oppencv 项目?

Java Web 服务 REST 正确设计最佳实践

java - 使用 CXF 时如何处理 WS 输出中的无效字符?