Jersey Client在MediaType上返回NullPointerException

时间:2015-07-20 04:18:16

标签: java nullpointerexception osgi jersey-client

我有一个代码将请求发送到远程服务器以获取响应。虽然回复但是在下面的行返回NPE:

 return (String) response.getEntity(String.class);
在OSGI容器上部署此代码后,

response.getEntity返回NullPointerException。它作为独立的Java应用程序

运行

以下依赖项是捆绑包的一部分:

     <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.18</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.18</version>
    </dependency>

堆栈追踪:

java.lang.NullPointerException: null at
javax.ws.rs.core.MediaType.valueOf(MediaType.java:119) at
com.sun.jersey.api.client.ClientResponse.getType(ClientResponse.java:695) at
com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:612) at
com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:586) at
io.swagger.client.ApiInvoker.invokeAPI(ApiInvoker.java:179)

返回的异常如下:

  

java.lang.NullPointerException:null at   javax.ws.rs.core.MediaType.valueOf(MediaType.java:119)at   com.sun.jersey.api.client.ClientResponse.getType(ClientResponse.java:695)   在   com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:612)   在   com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:586)   在io.swagger.client.ApiInvoker.invokeAPI(ApiInvoker.java:179)

1 个答案:

答案 0 :(得分:0)

一旦这些依赖项作为Felix中的bundle安装,就可以使用。早些时候我试图将这些依赖项嵌入到捆绑包中,这会在为服务选择实际的提供程序实现时给出类加载问题。

相关问题