@Test public void testGetFile() throws IOException { checkGetNotFound(CONTENTS_PATH); try (CloseableClientResponse response = get(joeToken, hugeBlobDocFileId, CONTENTS_PATH)) { assertEquals(412, response.getStatus()); } Map<String, String> headers = new HashMap<>(); headers.put(MAX_EXPECTED_SIZE, "1"); try (CloseableClientResponse response = get(joeToken, headers, blobDocFileId, CONTENTS_PATH)) { assertEquals(412, response.getStatus()); } headers.put(MAX_EXPECTED_SIZE, "foo"); String expectedFileBlobString = expectedFileBlob.getString(); try (CloseableClientResponse response = get(joeToken, headers, blobDocFileId, CONTENTS_PATH)) { assertEquals(200, response.getStatus()); Blob actualBlob = Blobs.createBlob(response.getEntityInputStream()); assertEquals(expectedFileBlobString, actualBlob.getString()); } try (CloseableClientResponse response = get(joeToken, blobDocFileId, CONTENTS_PATH)) { assertEquals(200, response.getStatus()); Blob actualBlob = Blobs.createBlob(response.getEntityInputStream()); assertEquals(expectedFileBlobString, actualBlob.getString()); } }
@GET @Path("contents") public Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader) { int maxExpectedSize = getMaxExpectedSize(maxExpectedSizeHeader); logRequest(OPERATION_GET_FILE, MAX_EXPECTED_SIZE, maxExpectedSizeHeader); long blobLength = blob.getLength(); if (blobLength > maxExpectedSize) { logCondition(() -> "Blob length " + blobLength + " > max expected size " + maxExpectedSize); logResponse(OPERATION_GET_FILE, PRECONDITION_FAILED.getStatusCode()); throw new PreConditionFailedException(); } buildItemVersionResponse(OPERATION_GET_FILE, blob); return blob; }
FilesEndpoint extends DefaultObject { @GET @Path("contents") public Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader) { int maxExpectedSize = getMaxExpectedSize(maxExpectedSizeHeader); logRequest(OPERATION_GET_FILE, MAX_EXPECTED_SIZE, maxExpectedSizeHeader); long blobLength = blob.getLength(); if (blobLength > maxExpectedSize) { logCondition(() -> "Blob length " + blobLength + " > max expected size " + maxExpectedSize); logResponse(OPERATION_GET_FILE, PRECONDITION_FAILED.getStatusCode()); throw new PreConditionFailedException(); } buildItemVersionResponse(OPERATION_GET_FILE, blob); return blob; } }
FilesEndpoint extends DefaultObject { @GET @Path("contents") public Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader) { int maxExpectedSize = getMaxExpectedSize(maxExpectedSizeHeader); logRequest(OPERATION_GET_FILE, MAX_EXPECTED_SIZE, maxExpectedSizeHeader); long blobLength = blob.getLength(); if (blobLength > maxExpectedSize) { logCondition(() -> "Blob length " + blobLength + " > max expected size " + maxExpectedSize); logResponse(OPERATION_GET_FILE, PRECONDITION_FAILED.getStatusCode()); throw new PreConditionFailedException(); } buildItemVersionResponse(OPERATION_GET_FILE, blob); return blob; }  }
FilesEndpoint extends DefaultObject { @GET @Path("contents") public Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader) { int maxExpectedSize = getMaxExpectedSize(maxExpectedSizeHeader); logRequest(OPERATION_GET_FILE, MAX_EXPECTED_SIZE, maxExpectedSizeHeader); long blobLength = blob.getLength(); if (blobLength > maxExpectedSize) { logCondition(() -> "Blob length " + blobLength + " > max expected size " + maxExpectedSize); logResponse(OPERATION_GET_FILE, PRECONDITION_FAILED.getStatusCode()); throw new PreConditionFailedException(); } buildItemVersionResponse(OPERATION_GET_FILE, blob); return blob; }  @Override void initialize(Object... args); @GET @Produces(MediaType.APPLICATION_JSON) Response checkFileInfo(); @GET @Path("contents") Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader); @POST Object doPost(@HeaderParam(OVERRIDE) Operation operation); Object putRelativeFile(); Object renameFile(); Object getShareUrl(); @POST @Path("contents") Object doPostContents(@HeaderParam(OVERRIDE) Operation operation); Object putFile(); }
FilesEndpoint extends DefaultObject { @GET @Path("contents") public Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader) { int maxExpectedSize = getMaxExpectedSize(maxExpectedSizeHeader); logRequest(OPERATION_GET_FILE, MAX_EXPECTED_SIZE, maxExpectedSizeHeader); long blobLength = blob.getLength(); if (blobLength > maxExpectedSize) { logCondition(() -> "Blob length " + blobLength + " > max expected size " + maxExpectedSize); logResponse(OPERATION_GET_FILE, PRECONDITION_FAILED.getStatusCode()); throw new PreConditionFailedException(); } buildItemVersionResponse(OPERATION_GET_FILE, blob); return blob; }  @Override void initialize(Object... args); @GET @Produces(MediaType.APPLICATION_JSON) Response checkFileInfo(); @GET @Path("contents") Object getFile(@HeaderParam(MAX_EXPECTED_SIZE) String maxExpectedSizeHeader); @POST Object doPost(@HeaderParam(OVERRIDE) Operation operation); Object putRelativeFile(); Object renameFile(); Object getShareUrl(); @POST @Path("contents") Object doPostContents(@HeaderParam(OVERRIDE) Operation operation); Object putFile();  }