Jersey application - Error on start up
<p>I have a Jersey application for fileupload. And during the startup or when I upload a file in my application, I get below errors in WebSphere trace logs.</p>

<p><strong>Error:</strong></p>

<pre><code>The registered message body writers compatible with the MIME media type are:
application/octet-stream -&gt;
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
*/* -&gt;
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
  com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General

[7/12/16 13:26:16:263 CEST] 0000034e ContainerResp E   Mapped exception to response: 500 (Internal Server Error)
                                 javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.sun.proxy.$Proxy553, and Java type interface javax.servlet.http.HttpServletResponse, and MIME media type application/octet-stream was not found.

        at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:284)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
</code></pre>

<p><strong>Web.xml</strong></p>

<pre><code>&lt;servlet&gt;
        &lt;servlet-name&gt;my-service&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.sun.jersey.spi.spring.container.servlet.SpringServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
            &lt;param-value&gt;my.app.service&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
</code></pre>

<p><strong>pom.xml</strong></p>

<pre><code>&lt;dependency&gt;
            &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
            &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
            &lt;version&gt;1.19&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt;
            &lt;artifactId&gt;jersey-spring&lt;/artifactId&gt;
            &lt;version&gt;1.19&lt;/version&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
                    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
                    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
                    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;/exclusion&gt;
                &lt;exclusion&gt;
                    &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
                    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&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.19&lt;/version&gt;
        &lt;/dependency&gt;
</code></pre>

<p>I am not sure what was the problem here? Please help.</p>

<p><strong>Edit: 1</strong></p>

<pre><code>import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.core.header.FormDataContentDisposition;

@Autowired
private ObjectMapper objectMapper;

@POST
@Path("/upload")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public HttpServletResponse attachDocument(@Context HttpServletRequest request,
                                          @Context HttpServletResponse response,
                                          @FormDataParam("file") InputStream fileInputStream,
                                          @FormDataParam("file") FormDataContentDisposition filedata) {

    String webServiceResponse = //call webservice here to store document
    objectMapper.writeValue(response.getOutputStream(), webServiceResponse);
}
</code></pre>