开发者

CXF JAX-RS Client Null Pointer Exception

I am trying to use the Apache CXF JAX-RS Client API code found here. However, when I run the client it throws this:

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.j开发者_开发技巧axrs.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)

Here is my client:

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() );
    }
}

And here is the interface:

@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();

}

When I run it in a browser with the correct URL's it works fine, and in fact I see the proper requests on the server side:

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    -

I'm baffled as to what could be causing this. I thought maybe I missed a dependency, so I went back and checked that and added a couple more. I thought maybe I missed something in the documentation, but I'm not seeing anything.

Am I missing something obvious? Does anyone know how to make this work?

Thanks.


The problem was not CXF. The problem was the JAX-RS restlet extension that was on my path. Adding the following to my 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>

Fixed it for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜