Returning an excel document via a Java REST service with Apache Wink
<p>I need to return a Microsoft Excel file from a Java REST service.  I'm using WebSphere 8.5 which inherently uses Apache Wink as it's JAX-RS implementation; that's a requirement which I can not change.  I am also using Java 7 JDK.  Here is the error I'm receiving:</p>

<blockquote>
  <p>org.apache.wink.server.internal.handlers.FlushResultHandler
  handleResponse The system could not find a
  javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for
  the com.somewhere.else.message.core.BaseResponseMessage type and
  application/vnd.ms-excel mediaType.  Ensure that a
  javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for
  the type and media type specified.</p>
</blockquote>

<p>Here is my Java Resource class method:</p>

<pre><code>@GET
@Path("/report")
@Produces("application/vnd.ms-excel")
public Response getReport() { 

    int fileSize = 0;

    byte[] reportByteArray = null;

    ResponseBuilder responseBuilder = null;
    InputStream report = null;

    BaseResponseMessage&lt;InputStream&gt; baseResponseMessage = new  
    BaseResponseMessage&lt;InputStream&gt;();

    Path reportPath = null;

    String localPath = "C:/Users/me/Report.xls";

    responseBuilder = Response.ok(baseResponseMessage); 

    responseBuilder.header("Content-Description", "File Transfer");
    responseBuilder.header("Content-Disposition", "attachment; 
         filename=Report.xls");
    responseBuilder.header("Content-Transfer-Encoding", "binary");
    responseBuilder.header("Connection", "Keep-Alive");

    reportPath = Paths.get(localPath);

    if (Files.exists(reportPath)) {

        if (Files.isReadable(reportPath)) {

            reportByteArray = Files.readAllBytes(reportPath);

            report = new ByteArrayInputStream(reportByteArray);
        }
    }

    fileSize = report.available();

    responseBuilder.header("Content-Length", fileSize);

    baseResponseMessage.setPayload(report);

    return responseBuilder.build();
}
</code></pre>

<p>I do know from looking at the debugger that the path and the excel file are found correctly, and the fileSize is populated correctly as well.</p>

<p>I will gladly provide any more information that is needed.  Thank you for your time!</p>