public class UserPictureResource extends BaseUserResource {
@RequestMapping(value="/identity/users/{userId}/picture", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody byte[] getUserPicture(@PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
User user = getUserFromRequest(userId);
Picture userPicture = identityService.getUserPicture(user.getId());
if (userPicture == null) {
throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
}
String mediaType = "image/jpeg";
if (userPicture.getMimeType() != null) {
mediaType = userPicture.getMimeType();
}
response.setContentType(mediaType);
try {
return IOUtils.toByteArray(userPicture.getInputStream());
} catch (Exception e) {
throw new ActivitiException("Error exporting picture: " + e.getMessage(), e);
}
}