@ApiOperation(value = "Get a user’s picture", produces = "application/octet-stream", tags = {
            "Users" }, notes = "The response body contains the raw picture data, representing the user’s picture. The Content-type of the response corresponds to the mimeType that was set when creating the picture.")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Indicates the user was found and has a picture, which is returned in the body."),
            @ApiResponse(code = 404, message = "Indicates the requested user was not found or the user does not have a profile picture. Status-description contains additional information about the error.")
    })
    @GetMapping(value = "/identity/users/{userId}/picture")
    public ResponseEntity<byte[]> getUserPicture(@ApiParam(name = "userId") @PathVariable String userId) {
        User user = getUserFromRequest(userId);
        Picture userPicture = identityService.getUserPicture(user.getId());

        if (userPicture == null) {
            throw new FlowableObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
        }

        HttpHeaders responseHeaders = new HttpHeaders();
        if (userPicture.getMimeType() != null) {
            responseHeaders.set("Content-Type", userPicture.getMimeType());
        } else {
            responseHeaders.set("Content-Type", "image/jpeg");
        }

        try {
            return new ResponseEntity<>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new FlowableException("Error exporting picture: " + e.getMessage(), e);
        }
    }
@Test
    public void testUpdatePicture() throws Exception {
        User savedUser = null;
        try {
            User newUser = identityService.newUser("testuser");
            newUser.setFirstName("Fred");
            newUser.setLastName("McDonald");
            newUser.setEmail("no-reply@activiti.org");
            identityService.saveUser(newUser);
            savedUser = newUser;

            HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
            httpPut.setEntity(HttpMultipartHelper
                    .getMultiPartEntity("myPicture.png", "image/png", new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), null));
            closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));

            Picture picture = identityService.getUserPicture(newUser.getId());
            assertThat(picture).isNotNull();
            assertThat(picture.getMimeType()).isEqualTo("image/png");
            assertThat(new String(picture.getBytes())).isEqualTo("this is the picture raw byte stream");

        } finally {

            // Delete user after test passes or fails
            if (savedUser != null) {
                identityService.deleteUser(savedUser.getId());
            }
        }
    }