title: Jersey asynchronous download of a zip file
body: <p>I am currently using Jersey 2.13. I want the client to download a zip file from the server, and I want the server to delete the file after the download is completed. Hence, I tried AsyncResponse, so I can register a CompletionCallback in order to know that the download is done. For my current code the client gets: "Failed : HTTP error code : 415".</p>
  
  <p>The server code is:</p>
  
  <pre><code>@GET
  @Path("/{id}")
  @Produces({"application/zip"})
  public void getResourceTree(@Suspended final AsyncResponse asyncResponse, @PathParam("id") String id) throws IOException{
      asyncResponse.register(new CompletionCallback() {
          @Override
          public void onComplete(Throwable throwable) {
  
              if (throwable == null) {
                  // no throwable - the processing ended successfully
                  // (response already written to the client)
                  // Delete temporary zip file...
              } else {
                  throw new UnexpectedException("The user did not receive the zip file in path:"+ getResourceTreeZipName(id) +" successfully");
              }
          }
      });
  
      new Thread(new Runnable() {
          @Override
          public void run() {
                  File file = createZipFile(id);
                  asyncResponse.resume(Response.ok((Object) file).build());
          }
      }).start();
  }
  </code></pre>
  
  <p>The client code is:</p>
  
  <pre><code>private File downloadZipFile(String resourceId){
      Client client = Client.create();
      WebResource serverWebResource = client.resource(serverURI+"/"+resourceId);
      ClientResponse response = serverWebResource.accept("application/zip").get(ClientResponse.class);
      InputStream in = response.getEntityInputStream();
      //Create and return the zip file from the input stream...
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>