@Override
public void execute(OperationRequest operation, OperationContext context, ParticipantId participant)
throws InvalidRequestException {
AttachmentId attachmentId;
try {
attachmentId = AttachmentId.deserialise(OperationUtil.<String>getRequiredParameter(operation,
ParamsProperty.ATTACHMENT_ID));
} catch (InvalidIdException ex) {
throw new InvalidRequestException("Invalid id", operation, ex);
}
AttachmentMetadata meta;
byte[] data;
try {
meta = attachmentService.getMetadata(attachmentId);
data = readInputStreamToBytes(attachmentService.getAttachment(attachmentId).getInputStream());
} catch (IOException ex) {
LOG.info("Get attachment", ex);
context.constructErrorResponse(operation, ex.toString());
return;
}
RawAttachmentData attachment = new RawAttachmentData(meta.getFileName(), meta.getCreator(),
data);
Map<ParamsProperty, Object> parameters =
ImmutableMap.<ParamsProperty, Object> of(ParamsProperty.ATTACHMENT_DATA, attachment);
context.constructResponse(operation, parameters);
}