HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
Attachment attachment = taskService.getAttachment(attachmentId);
if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() +"' doesn't have an attachment with id '" + attachmentId + "'.", Attachment.class);
}
InputStream attachmentStream = taskService.getAttachmentContent(attachmentId);
if (attachmentStream == null) {
throw new ActivitiObjectNotFoundException("Attachment with id '" + attachmentId +
"' doesn't have content associated with it.", Attachment.class);
}
MediaType mediaType = null;
if (attachment.getType() != null) {