DocumentController { @SneakyThrows @PutMapping(value = "/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Write document to user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully written") }) public void writeDocument(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable String path, @RequestParam("file") MultipartFile file) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); WriteRequest<UserIDAuth, PrivateResource> request = WriteRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path); try (OutputStream os = datasafeService.privateService().write(request); InputStream is = file.getInputStream()) { StreamUtils.copy(is, os); } log.debug("User: {}, write private file to: {}", user, path); }  @SneakyThrows @GetMapping(value = "/document/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 401, message = "Document not found") }) void readDocument(@RequestHeader String user,
                             @RequestHeader String password,
                             @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                             @PathVariable String path,
                             HttpServletResponse response); @SneakyThrows @PutMapping(value = "/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Write document to user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully written") }) void writeDocument(@RequestHeader String user,
                              @RequestHeader String password,
                              @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                              @PathVariable String path,
                              @RequestParam("file") MultipartFile file); @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listDocuments(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                      @ApiParam(defaultValue = ".")
                                      @PathVariable(required = false) String path); @DeleteMapping("/document/{path:.*}") @ApiOperation("Delete document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void removeDocument(@RequestHeader String user,
                               @RequestHeader String password,
                               @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                               @PathVariable String path);  }
@SneakyThrows @Test void writeDocumentTest() { when(dataSafeService.privateService().write(any())).thenReturn(new PasswordClearingOutputStream(new ByteArrayOutputStream(), null)); RestDocumentationResultHandler document = document("document-write-success", pathParameters( parameterWithName("path").description("path to the file") ), requestHeaders( headerWithName("token").description(TOKEN_DESCRIPTION), headerWithName("user").description(USER_DESCRIPTION), headerWithName("password").description(PASSWORD_DESCRIPTION) ) ); String path = "path/to/file"; mvc.perform(putFileBuilder("/document/{path}", path) .content(new MockMultipartFile("file", path.getBytes()).getBytes()) .header("user", TEST_USER) .header("password", TEST_PASS) .header("token", token) ) .andExpect(status().isOk()) .andDo(document); verify(privateSpaceService).write(any()); }