@Test public void testGetAttributionMSLowerCase() { String id = "ms"; Response response = backendResource.getAttribution(id); assertThat(response.getStatus()) .isEqualTo(Response.Status.OK.getStatusCode()); assertThat(response.getHeaders()).isNotEmpty() .containsKeys("Content-Disposition"); assertThat( (String) response.getHeaders().getFirst("Content-Disposition")) .contains(new File(BackendResource.MS_ATTRIBUTION_IMAGE).getName()); }
@Override public Response getAttribution(@QueryParam("id") String id) { Optional<APIResponse> response = validateId(id); if (response.isPresent()) { return Response.status(response.get().getStatus()) .entity(response.get()) .type(MediaType.APPLICATION_JSON_TYPE).build(); } BackendID backendID = BackendID.fromString(id); String imageResource = getAttributionImageResource(backendID); String docName = new File(imageResource).getName(); InputStream is = getResourceAsStream(imageResource); if (is == null) { return Response.status(Response.Status.NOT_FOUND) .entity(new APIResponse(Response.Status.NOT_FOUND, "attribution image can not be found: " + imageResource)) .type(MediaType.APPLICATION_JSON_TYPE) .build(); } StreamingOutput output = new InputStreamStreamingOutput(is); return Response.ok().header("Content-Disposition", "attachment; filename=\"" + docName + "\"") .entity(output).type("image/png").build(); }
BackendResourceImpl implements BackendResource { @Override public Response getAttribution(@QueryParam("id") String id) { Optional<APIResponse> response = validateId(id); if (response.isPresent()) { return Response.status(response.get().getStatus()) .entity(response.get()) .type(MediaType.APPLICATION_JSON_TYPE).build(); } BackendID backendID = BackendID.fromString(id); String imageResource = getAttributionImageResource(backendID); String docName = new File(imageResource).getName(); InputStream is = getResourceAsStream(imageResource); if (is == null) { return Response.status(Response.Status.NOT_FOUND) .entity(new APIResponse(Response.Status.NOT_FOUND, "attribution image can not be found: " + imageResource)) .type(MediaType.APPLICATION_JSON_TYPE) .build(); } StreamingOutput output = new InputStreamStreamingOutput(is); return Response.ok().header("Content-Disposition", "attachment; filename=\"" + docName + "\"") .entity(output).type("image/png").build(); } }
BackendResourceImpl implements BackendResource { @Override public Response getAttribution(@QueryParam("id") String id) { Optional<APIResponse> response = validateId(id); if (response.isPresent()) { return Response.status(response.get().getStatus()) .entity(response.get()) .type(MediaType.APPLICATION_JSON_TYPE).build(); } BackendID backendID = BackendID.fromString(id); String imageResource = getAttributionImageResource(backendID); String docName = new File(imageResource).getName(); InputStream is = getResourceAsStream(imageResource); if (is == null) { return Response.status(Response.Status.NOT_FOUND) .entity(new APIResponse(Response.Status.NOT_FOUND, "attribution image can not be found: " + imageResource)) .type(MediaType.APPLICATION_JSON_TYPE) .build(); } StreamingOutput output = new InputStreamStreamingOutput(is); return Response.ok().header("Content-Disposition", "attachment; filename=\"" + docName + "\"") .entity(output).type("image/png").build(); } @SuppressWarnings("unused")  BackendResourceImpl(); @Inject  BackendResourceImpl(@BackEndProviders Set<BackendID> availableProviders); }
BackendResourceImpl implements BackendResource { @Override public Response getAttribution(@QueryParam("id") String id) { Optional<APIResponse> response = validateId(id); if (response.isPresent()) { return Response.status(response.get().getStatus()) .entity(response.get()) .type(MediaType.APPLICATION_JSON_TYPE).build(); } BackendID backendID = BackendID.fromString(id); String imageResource = getAttributionImageResource(backendID); String docName = new File(imageResource).getName(); InputStream is = getResourceAsStream(imageResource); if (is == null) { return Response.status(Response.Status.NOT_FOUND) .entity(new APIResponse(Response.Status.NOT_FOUND, "attribution image can not be found: " + imageResource)) .type(MediaType.APPLICATION_JSON_TYPE) .build(); } StreamingOutput output = new InputStreamStreamingOutput(is); return Response.ok().header("Content-Disposition", "attachment; filename=\"" + docName + "\"") .entity(output).type("image/png").build(); } @SuppressWarnings("unused")  BackendResourceImpl(); @Inject  BackendResourceImpl(@BackEndProviders Set<BackendID> availableProviders); @Override Response getAttribution(@QueryParam("id") String id); @Override Response getStringAttribution(String id); @Override Response getAvailableBackends(); }
BackendResourceImpl implements BackendResource { @Override public Response getAttribution(@QueryParam("id") String id) { Optional<APIResponse> response = validateId(id); if (response.isPresent()) { return Response.status(response.get().getStatus()) .entity(response.get()) .type(MediaType.APPLICATION_JSON_TYPE).build(); } BackendID backendID = BackendID.fromString(id); String imageResource = getAttributionImageResource(backendID); String docName = new File(imageResource).getName(); InputStream is = getResourceAsStream(imageResource); if (is == null) { return Response.status(Response.Status.NOT_FOUND) .entity(new APIResponse(Response.Status.NOT_FOUND, "attribution image can not be found: " + imageResource)) .type(MediaType.APPLICATION_JSON_TYPE) .build(); } StreamingOutput output = new InputStreamStreamingOutput(is); return Response.ok().header("Content-Disposition", "attachment; filename=\"" + docName + "\"") .entity(output).type("image/png").build(); } @SuppressWarnings("unused")  BackendResourceImpl(); @Inject  BackendResourceImpl(@BackEndProviders Set<BackendID> availableProviders); @Override Response getAttribution(@QueryParam("id") String id); @Override Response getStringAttribution(String id); @Override Response getAvailableBackends();  }