2015-07-20 140 views
0

我有一个代码将请求发送到远程服务器以获取响应。虽然返回的响应,但在下面一行返回NPE:Jersey客户端返回MediaType上的NullPointerException

return (String) response.getEntity(String.class); 

response.getEntity返回NullPointerException异常一旦部署在OSGi容器此代码。它可以作为一个独立的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在 j avax.ws.rs.core.MediaType.valueOf(MediaType.java:119)at com.sun.jersey.api.client.ClientResponse.getType(ClientResponse.java:695) at com.sun.jersey.api客户端响应.getEntity(ClientResponse.java:612) at java:179)

+0

返回的例外是显示java.lang.NullPointerException:空 \t在javax.ws.rs.core.MediaType.valueOf(MediaType.java:119) \t在com.sun.jersey.api.client.ClientResponse。 getType(ClientResponse.java:695) \t at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:612) \t at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse。 Java的:586) \t在io.swagger.client.ApiInvoker.invokeAPI(ApiInvoker.java:179) –

+1

我想你会需要提供比这更多的信息,以获得一个有意义的/正确的答案。 –

回答

0

一旦这些依赖关系在Felix中作为一个包安装,它就可以工作。早些时候,我试图将这些依赖关系嵌入到正在为服务提供实际提供者实现的同时给类加载问题的包中。