@Override public void onFailire(String message) { context.constructErrorResponse(operation, message); } });
public void testErrorOnFailingConnection() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(connector.fetchCapabilities(any(RobotAccountData.class), anyString())).thenThrow( new CapabilityFetchException("")); operationService.execute(operation, context, ROBOT); verify(accountStore, never()).putAccount(any(AccountData.class)); verify(context).constructErrorResponse(eq(operation), anyString()); }
public void testErrorOnFailingConnection() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(connector.fetchCapabilities(any(RobotAccountData.class), anyString())).thenThrow( new CapabilityFetchException("")); operationService.execute(operation, context, ROBOT); verify(accountStore, never()).putAccount(any(AccountData.class)); verify(context).constructErrorResponse(eq(operation), anyString()); }
} catch (PersistenceException e) { LOG.severe("Failed to retreive account data for " + robotAccountId, e); context.constructErrorResponse(operation, "Unable to retrieve account data"); return; } catch (CapabilityFetchException e) { LOG.fine("Unable to retrieve capabilities for " + account.getId(), e); context.constructErrorResponse(operation, "Unable to retrieve new capabilities"); return; } catch (PersistenceException e) { LOG.severe("Failed to update account data for " + robotAccountId, e); context.constructErrorResponse(operation, "Unable to update account data"); return;
/** * Executes an {@link OperationRequest}. If the operation throws an * {@link InvalidRequestException} this exception will be used to construct an * error response in the {@link OperationContext}. * * @param operation the operation to be executed. If the operation contains * {@link ParamsProperty.PROXYING_FOR} - then it will be taken in * account. * @param operationRegistry the registry containing the operations that can be * performed. * @param context the context in which the operation is to be executed. * @param author the author of the operation. */ public static void executeOperation(OperationRequest operation, OperationServiceRegistry operationRegistry, OperationContext context, ParticipantId author) { try { OperationService service = operationRegistry.getServiceFor(OperationUtil.getOperationType(operation)); ParticipantId proxyParticipant = OperationUtil.computeParticipant(operation, author); service.execute(operation, context, proxyParticipant); } catch (InvalidRequestException e) { LOG.warning("Operation " + operation + " failed to execute", e); context.constructErrorResponse(operation, e.getMessage()); } }
@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); }
} catch (WaveServerException ex) { LOG.info("Get wavelet snapshot", ex); context.constructErrorResponse(operation, ex.toString()); return; context.constructErrorResponse(operation, error.toString()); return; } catch (WaveServerException ex) { LOG.info("Get wavelet snapshot", ex); context.constructErrorResponse(operation, ex.toString()); return; context.constructErrorResponse(operation, "Expected wavelet version " + delta.getHashedVersion().getVersion() + ", but current version is " + currentVersion + "." + "Possibly wavelet is modified during import.");
} catch (IOException ex) { LOG.severe("Store attachment", ex); context.constructErrorResponse(operation, ex.toString()); return;