ManifestRest extends BaseRest { @Path("/{spaceId}") @POST public Response generateManifest(@PathParam("spaceId") String spaceId, @QueryParam("format") String format, @QueryParam("storeID") String storeId) { if (!enabled) { return Response.status(501) .entity("This endpoint is currently disabled.") .build(); } if (format == null) { format = DEFAULT_FORMAT; } String account = getSubdomain(); log.info("generating manifest, {}:{}:{} [{}]", account, storeId, spaceId, format); try { URI uri = generateAsynchronously(account, spaceId, storeId, format); return Response.accepted("We are processing your manifest generation request. " + "To retrieve your file, please poll the URI in the Location " + "header of this response: (" + uri + ").").location(uri).build(); } catch (ManifestArgumentException e) { log.error("Error for, {}:{} [{}]", new Object[] {storeId, spaceId, format, e}); return responseBadRequest(e); } catch (ManifestNotFoundException e) { log.error("Error for, {}:{} [{}]", new Object[] {storeId, spaceId, format, e}); return responseNotFound(e.getMessage()); } catch (Exception e) { log.error("Error for, {}:{} [{}]", new Object[] {storeId, spaceId, format, e}); return responseBad(e); } } @Autowired  ManifestRest(ManifestResource manifestResource,
                        StorageProviderFactory storageProviderFactory); @Path("/{spaceId}") @GET Response getManifest(@PathParam("spaceId") String spaceId,
                                @QueryParam("format") String format,
                                @QueryParam("storeID") String storeId); @Path("/{spaceId}") @POST Response generateManifest(@PathParam("spaceId") String spaceId,
                                     @QueryParam("format") String format,
                                     @QueryParam("storeID") String storeId); void setEnabled(boolean enabled);  }
@Test public void generateAsync() throws Exception { String format = ManifestFormat.TSV.name(); CountDownLatch latch = new CountDownLatch(1); setupAccountId(); expect(request.getAttribute(Constants.SERVER_HOST)).andReturn("host"); expect(request.getAttribute(Constants.SERVER_PORT)).andReturn(443); expect(request.getContextPath()).andReturn("/context"); expectGetManifest(format); StorageAccount sa = createMock("StorageAccount", StorageAccount.class); expect(sa.getId()).andReturn(storeId); expect(sa.getType()).andReturn(StorageProviderType.AMAZON_S3); expect(storageProviderFactory.getStorageAccounts()).andReturn(Arrays.asList(sa)); expect(storageProviderFactory.getStorageProvider()).andReturn(provider); Map<String, String> props = new HashMap<>(); props.put(HttpHeaders.CONTENT_ENCODING, "gzip"); expect(provider.addContent(isA(String.class), isA(String.class), eq(ManifestFormat.TSV.getMimeType()), eq(props), anyLong(), isA(String.class), isA(InputStream.class))) .andAnswer( new IAnswer<String>() { @Override public String answer() throws Throwable { latch.countDown(); return "checksum"; } }); replayAll(); Response response = rest.generateManifest(spaceId, format, storeId); URI uri = (URI) response.getLocation(); assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus()); assertNotNull(uri); assertTrue("async generate and upload did not complete", latch.await(10000, TimeUnit.MILLISECONDS)); }