@Test public void testPutFile() throws IOException { String data = "new content"; Map<String, String> headers = new HashMap<>(); headers.put(OVERRIDE, Operation.PUT.name()); checkPostNotFound(headers, CONTENTS_PATH); try (CloseableClientResponse response = post(joeToken, data, headers, zeroLengthBlobDocFileId, CONTENTS_PATH)) { assertEquals(409, response.getStatus()); } try (CloseableClientResponse response = post(johnToken, data, headers, zeroLengthBlobDocFileId, CONTENTS_PATH)) { assertEquals(200, response.getStatus()); transactionalFeature.nextTransaction(); Blob updatedBlob = (Blob) session.getDocument(zeroLengthBlobDoc.getRef()) .getPropertyValue(FILE_CONTENT_PROPERTY); assertNotNull(updatedBlob); assertEquals("new content", updatedBlob.getString()); assertEquals("zero-length-blob", updatedBlob.getFilename()); String itemVersion = response.getHeaders().getFirst(ITEM_VERSION); assertEquals(updatedBlob.getDigest(), itemVersion); } try (CloseableClientResponse response = post(johnToken, data, headers, blobDocFileId, CONTENTS_PATH)) { assertEquals(409, response.getStatus()); String lock = response.getHeaders().getFirst(LOCK); assertEquals("", lock); } headers.put(LOCK, "foo"); headers.put(OVERRIDE, Operation.LOCK.name()); try (CloseableClientResponse response = post(johnToken, headers, blobDocFileId)) { assertEquals(200, response.getStatus()); transactionalFeature.nextTransaction(); assertTrue(session.getDocument(blobDoc.getRef()).isLocked()); } headers.put(OVERRIDE, Operation.PUT.name()); try (CloseableClientResponse response = post(joeToken, data, headers, blobDocFileId, CONTENTS_PATH)) { assertEquals(409, response.getStatus()); } try (CloseableClientResponse response = post(johnToken, data, headers, blobDocFileId, CONTENTS_PATH)) { assertEquals(200, response.getStatus()); transactionalFeature.nextTransaction(); Blob updatedBlob = (Blob) session.getDocument(blobDoc.getRef()).getPropertyValue(FILE_CONTENT_PROPERTY); assertNotNull(updatedBlob); assertEquals("new content", updatedBlob.getString()); assertEquals("test-file.txt", updatedBlob.getFilename()); String itemVersion = response.getHeaders().getFirst(ITEM_VERSION); assertEquals(updatedBlob.getDigest(), itemVersion); } headers.put(LOCK, "bar"); try (CloseableClientResponse response = post(johnToken, data, headers, blobDocFileId, CONTENTS_PATH)) { assertConflictResponseWithLock(response); } session.getDocument(hugeBlobDoc.getRef()).setLock(); transactionalFeature.nextTransaction(); try (CloseableClientResponse response = post(johnToken, data, headers, hugeBlobDocFileId, CONTENTS_PATH)) { assertEquals(409, response.getStatus()); transactionalFeature.nextTransaction(); assertTrue(session.getDocument(hugeBlobDoc.getRef()).isLocked()); } }
public Object putFile() { checkWritePropertiesPermission(OPERATION_PUT_FILE); if (!doc.isLocked()) { logRequest(OPERATION_PUT_FILE); logCondition("Document isn't locked"); if (blob.getLength() == 0) { logCondition("Blob is empty"); return updateBlob(); } logCondition("Blob is not empty"); buildConflictResponse(OPERATION_PUT_FILE, ""); } String currentLock = getCurrentLock(OPERATION_PUT_FILE); String lock = getHeader(OPERATION_PUT_FILE, LOCK); logRequest(OPERATION_PUT_FILE, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return updateBlob(); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_PUT_FILE, currentLock); } }
FilesEndpoint extends DefaultObject { public Object putFile() { checkWritePropertiesPermission(OPERATION_PUT_FILE); if (!doc.isLocked()) { logRequest(OPERATION_PUT_FILE); logCondition("Document isn't locked"); if (blob.getLength() == 0) { logCondition("Blob is empty"); return updateBlob(); } logCondition("Blob is not empty"); buildConflictResponse(OPERATION_PUT_FILE, ""); } String currentLock = getCurrentLock(OPERATION_PUT_FILE); String lock = getHeader(OPERATION_PUT_FILE, LOCK); logRequest(OPERATION_PUT_FILE, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return updateBlob(); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_PUT_FILE, currentLock); } } }
FilesEndpoint extends DefaultObject { public Object putFile() { checkWritePropertiesPermission(OPERATION_PUT_FILE); if (!doc.isLocked()) { logRequest(OPERATION_PUT_FILE); logCondition("Document isn't locked"); if (blob.getLength() == 0) { logCondition("Blob is empty"); return updateBlob(); } logCondition("Blob is not empty"); buildConflictResponse(OPERATION_PUT_FILE, ""); } String currentLock = getCurrentLock(OPERATION_PUT_FILE); String lock = getHeader(OPERATION_PUT_FILE, LOCK); logRequest(OPERATION_PUT_FILE, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return updateBlob(); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_PUT_FILE, currentLock); } }  }
FilesEndpoint extends DefaultObject { public Object putFile() { checkWritePropertiesPermission(OPERATION_PUT_FILE); if (!doc.isLocked()) { logRequest(OPERATION_PUT_FILE); logCondition("Document isn't locked"); if (blob.getLength() == 0) { logCondition("Blob is empty"); return updateBlob(); } logCondition("Blob is not empty"); buildConflictResponse(OPERATION_PUT_FILE, ""); } String currentLock = getCurrentLock(OPERATION_PUT_FILE); String lock = getHeader(OPERATION_PUT_FILE, LOCK); logRequest(OPERATION_PUT_FILE, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return updateBlob(); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_PUT_FILE, currentLock); } }  @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 { public Object putFile() { checkWritePropertiesPermission(OPERATION_PUT_FILE); if (!doc.isLocked()) { logRequest(OPERATION_PUT_FILE); logCondition("Document isn't locked"); if (blob.getLength() == 0) { logCondition("Blob is empty"); return updateBlob(); } logCondition("Blob is not empty"); buildConflictResponse(OPERATION_PUT_FILE, ""); } String currentLock = getCurrentLock(OPERATION_PUT_FILE); String lock = getHeader(OPERATION_PUT_FILE, LOCK); logRequest(OPERATION_PUT_FILE, LOCK, lock); if (lock.equals(currentLock)) { logCondition(() -> LOCK + " header is equal to current WOPI lock"); return updateBlob(); } else { logCondition(() -> LOCK + " header is not equal to current WOPI lock"); return buildConflictResponse(OPERATION_PUT_FILE, currentLock); } }  @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();  }