JvmService { @GET @Path("/dump/heap") @Produces("application/zip") @ApiOperation("Get heap dump of jvm") @ApiResponses(@ApiResponse(code = 200, message = "The response contains jvm heap dump")) @ApiResponse(code = 500, message = "Internal server error occurred") public Response heapDump() throws IOException { File heapDump = manager.createZippedHeapDump(); heapDump.deleteOnExit(); return Response.ok( new FileInputStream(heapDump) { @Override public void close() throws IOException { super.close(); if (!heapDump.delete()) { LOG.warn("Not able to delete temporary file {}", heapDump); } } }, "application/zip") .header("Content-Length", String.valueOf(Files.size(heapDump.toPath()))) .header("Content-Disposition", "attachment; filename=heapdump.hprof.zip") .build(); } @Inject  JvmService(JvmManager manager); @GET @Path("/dump/thread") @Produces(MediaType.TEXT_PLAIN) @ApiOperation("Get thread dump of jvm") @ApiResponses(@ApiResponse(code = 200, message = "The response contains thread dump")) @ApiResponse(code = 500, message = "Internal server error occurred") StreamingOutput threadDump(); @GET @Path("/dump/heap") @Produces("application/zip") @ApiOperation("Get heap dump of jvm") @ApiResponses(@ApiResponse(code = 200, message = "The response contains jvm heap dump")) @ApiResponse(code = 500, message = "Internal server error occurred") Response heapDump();  }
@Test public void testHeapDump() throws IOException { final Response response = expect().statusCode(200).contentType("application/zip").when().get("/jvm/dump/heap"); byte[] array = response.asByteArray(); File tmp = File.createTempFile("test", "zip"); tmp.deleteOnExit(); Files.write(tmp.toPath(), array); assertTrue(ZipUtils.isZipFile(tmp)); assertTrue(array.length > 1000); }