@Test public void testGetPresent() throws IOException { String network = "network1"; String snapshot = "snapshot1"; Main.getWorkMgr().initNetwork(network, null); WorkMgrTestUtils.initSnapshotWithTopology(network, snapshot, ImmutableSet.of()); String key = "foo/bar"; String content = "baz"; InputStream inputStream = new ByteArrayInputStream(content.getBytes()); Main.getWorkMgr().putSnapshotExtendedObject(inputStream, network, snapshot, key); try (Response response = getTarget(network, snapshot, key).get()) { assertThat(response.getStatus(), equalTo(OK.getStatusCode())); assertThat(response.readEntity(String.class), equalTo(content)); } }
@GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) public Response get(@QueryParam(QP_KEY) String key) throws IOException { InputStream inputStream = Main.getWorkMgr().getSnapshotObject(_network, _snapshot, key); if (inputStream == null) { return Response.status(Status.NOT_FOUND).build(); } String filename = Paths.get(FilenameUtils.separatorsToSystem(key)).getFileName().toString(); return Response.ok(inputStream, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + filename + "\"") .header(CoordConsts.SVC_FILENAME_HDR, filename) .build(); }
SnapshotObjectsResource { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) public Response get(@QueryParam(QP_KEY) String key) throws IOException { InputStream inputStream = Main.getWorkMgr().getSnapshotObject(_network, _snapshot, key); if (inputStream == null) { return Response.status(Status.NOT_FOUND).build(); } String filename = Paths.get(FilenameUtils.separatorsToSystem(key)).getFileName().toString(); return Response.ok(inputStream, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + filename + "\"") .header(CoordConsts.SVC_FILENAME_HDR, filename) .build(); } }
SnapshotObjectsResource { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) public Response get(@QueryParam(QP_KEY) String key) throws IOException { InputStream inputStream = Main.getWorkMgr().getSnapshotObject(_network, _snapshot, key); if (inputStream == null) { return Response.status(Status.NOT_FOUND).build(); } String filename = Paths.get(FilenameUtils.separatorsToSystem(key)).getFileName().toString(); return Response.ok(inputStream, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + filename + "\"") .header(CoordConsts.SVC_FILENAME_HDR, filename) .build(); } SnapshotObjectsResource(String network, String snapshot); }
SnapshotObjectsResource { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) public Response get(@QueryParam(QP_KEY) String key) throws IOException { InputStream inputStream = Main.getWorkMgr().getSnapshotObject(_network, _snapshot, key); if (inputStream == null) { return Response.status(Status.NOT_FOUND).build(); } String filename = Paths.get(FilenameUtils.separatorsToSystem(key)).getFileName().toString(); return Response.ok(inputStream, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + filename + "\"") .header(CoordConsts.SVC_FILENAME_HDR, filename) .build(); } SnapshotObjectsResource(String network, String snapshot); @DELETE Response delete(@QueryParam(QP_KEY) String key); @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) // Response eventually closes it. Response get(@QueryParam(QP_KEY) String key); @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) Response put(InputStream inputStream, @QueryParam(QP_KEY) String key); @Path(RSC_LIST) @GET @Produces(MediaType.APPLICATION_JSON) @Nonnull Response listKeys(); }
SnapshotObjectsResource { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) public Response get(@QueryParam(QP_KEY) String key) throws IOException { InputStream inputStream = Main.getWorkMgr().getSnapshotObject(_network, _snapshot, key); if (inputStream == null) { return Response.status(Status.NOT_FOUND).build(); } String filename = Paths.get(FilenameUtils.separatorsToSystem(key)).getFileName().toString(); return Response.ok(inputStream, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + filename + "\"") .header(CoordConsts.SVC_FILENAME_HDR, filename) .build(); } SnapshotObjectsResource(String network, String snapshot); @DELETE Response delete(@QueryParam(QP_KEY) String key); @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @SuppressWarnings({"MustBeClosedChecker", "PMD.CloseResource"}) // Response eventually closes it. Response get(@QueryParam(QP_KEY) String key); @PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) Response put(InputStream inputStream, @QueryParam(QP_KEY) String key); @Path(RSC_LIST) @GET @Produces(MediaType.APPLICATION_JSON) @Nonnull Response listKeys();  }