title: Jersey Client returning NullPointerException on MediaType
body: <p>I have a code which sends the request to remote server to get the response. Though the response is being returned but returns NPE on below line:</p>
  
  <pre><code> return (String) response.getEntity(String.class);
  </code></pre>
  
  <p><code>response.getEntity</code>  returns NullPointerException once deployed this code on OSGI container. It works as a standalone Java Application</p>
  
  <p>Following dependencies are part of the bundle:</p>
  
  <pre><code>     &lt;dependency&gt;
          &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
          &lt;version&gt;1.18&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-json&lt;/artifactId&gt;
          &lt;version&gt;1.18&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-multipart&lt;/artifactId&gt;
          &lt;version&gt;1.18&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>Stack Trace:</strong></p>
  
  <pre><code>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)
  </code></pre>
  
  <p>The returned exception is as follows:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>