Return ZipInputStream as a Jax-RS response object

I am trying to return a ZipInputStream containing two different output streams, like a javax.ws.rs.core.Response stream. When I make a web service call to retrieve a stream, I notice that I am getting an empty stream back. I tried to return a GZipInputStream before, and I got the expected stream on the client side. Could there be a problem with ZipInputStream that prevents it from returning correctly? I am using javax 2.4 (servlet-api) Here is what my jax-rs service looks like (I simplified it a bit):

 @GET
 @Produces({"application/zip", MediaType.APPLICATION_XML})
 public Response getZipFiles(@PathParam("id") final Integer id){

    //Get required resources here
    ByteArrayOutputStream bundledStream = new ByteArrayOutputStream();
    ZipOutputStream out = new ZipOutputStream(bundledStream);
    out.putNextEntry(new ZipEntry("Item A"));
    out.write(outputStream.toByteArray());
    out.closeEntry();

    out.putNextEntry(new ZipEntry("Item B"));
    out.write(defectiveBillOutputStream.toByteArray());
    out.closeEntry();

    out.close();
    bundledStream.close();

    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bundledStream.toByteArray()));
    return Response.ok(zis).build();
 }

And this is the code that calls the service. I am using axis 1.4:

 HttpMethodBase getBillGroup = null;
 String id = "1234";
 String absoluteUrl = baseURL + BASE_SERVICE_PATH.replace("@id@",id) ;
 getZip = new GetMethod(absoluteUrl);

 HttpClient httpClient =  new HttpClient();
 try {
      httpClient.executeMethod(getZip);
 }
 catch (Exception e) {
      LOGGER.error("Error during retrieval " + e.getMessage());

 }

 InputStream dataToConvert =  getZip.getResponseBodyAsStream();
 ZipInputStream in = new ZipInputStream(dataToConvert);
 ZipEntry itemA = in.getNextEntry();
 //Do more things

On the last line, itemA should have been the first record added to the stream in the Jax-RS service, but I am returning zero. Any idea what could be causing this?

+5
1

ByteArrayInputStream ZipInputStream, zip.

+1

All Articles