@Test public void testIOExceptionDuringMapping() throws Exception { bindOperations(); HttpCommand command = mock(HttpCommand.class); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getScheme()).thenReturn("http"); ServletInputStream is = mock(ServletInputStream.class); when(request.getInputStream()).thenReturn(is); when(is.read()).thenThrow(new IOException("i/o error")); when(is.read((byte[])any())).thenThrow(new IOException("i/o error")); when(is.read((byte[])any(),anyInt(),anyInt())).thenThrow(new IOException("i/o error")); HttpServletResponse response = mock(HttpServletResponse.class); RequestTimer mockTimer = mock(RequestTimer.class); when(command.getRequest()).thenReturn(request); when(command.getResponse()).thenReturn(response); when(command.getTimer()).thenReturn(mockTimer); TestOutputStream tos = new TestOutputStream(); when(response.getOutputStream()).thenReturn(tos); commandProcessor.process(command); assertTrue(commandProcessor.errorCalled); verify(logger).logAccess(eq(command), isA(ExecutionContext.class), anyLong(), anyLong(), any(MediaType.class), any(MediaType.class), any(ResponseCode.class)); verifyTracerCalls(); }
@Override public void process(HttpCommand command) { boolean traceStarted = false; incrementCommandsProcessed(); DehydratedExecutionContext ctx = null; try { validateCommand(command); final CommandResolver<HttpCommand> resolver = createCommandResolver(command, tracer); traceStarted = true; ctx = resolver.resolveExecutionContext(); final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest())); final DehydratedExecutionContext finalCtx = ctx; ExecutionCommand resolveCommand = new ExecutionCommand() { @Override public OperationKey getOperationKey() { return IDENTITY_RESOLUTION_OPDEF.getOperationKey(); } @Override public Object[] getArgs() { return new Object[0]; } @Override public void onResult(ExecutionResult executionResult) { Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands(); if (executionResult.isFault()) { for (ExecutionCommand exec : batchCalls) { exec.onResult(executionResult); } } else { ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity()); for (ExecutionCommand exec : resolver.resolveExecutionCommands()) { ExecutionContext subContext = createCallContext(context); tracer.start(subContext.getRequestUUID(), exec.getOperationKey()); ExecutionCommand newCommand = createTraceableSubCommand(exec, tracer, subContext.getRequestUUID()); executeCommand(newCommand, context); } } } @Override public TimeConstraints getTimeConstraints() { return realTimeConstraints; } }; executeCommand(resolveCommand, ctx); } catch (CougarException ex) { writeErrorResponse(command, ctx, ex, traceStarted); } catch (Throwable ex) { writeErrorResponse(command, ctx, new CougarServiceException(ServerFaultCode.ServiceRuntimeException, ex.getMessage()), traceStarted); } }
JsonRpcTransportCommandProcessor extends AbstractHttpCommandProcessor<Void> { @Override public void process(HttpCommand command) { boolean traceStarted = false; incrementCommandsProcessed(); DehydratedExecutionContext ctx = null; try { validateCommand(command); final CommandResolver<HttpCommand> resolver = createCommandResolver(command, tracer); traceStarted = true; ctx = resolver.resolveExecutionContext(); final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest())); final DehydratedExecutionContext finalCtx = ctx; ExecutionCommand resolveCommand = new ExecutionCommand() { @Override public OperationKey getOperationKey() { return IDENTITY_RESOLUTION_OPDEF.getOperationKey(); } @Override public Object[] getArgs() { return new Object[0]; } @Override public void onResult(ExecutionResult executionResult) { Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands(); if (executionResult.isFault()) { for (ExecutionCommand exec : batchCalls) { exec.onResult(executionResult); } } else { ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity()); for (ExecutionCommand exec : resolver.resolveExecutionCommands()) { ExecutionContext subContext = createCallContext(context); tracer.start(subContext.getRequestUUID(), exec.getOperationKey()); ExecutionCommand newCommand = createTraceableSubCommand(exec, tracer, subContext.getRequestUUID()); executeCommand(newCommand, context); } } } @Override public TimeConstraints getTimeConstraints() { return realTimeConstraints; } }; executeCommand(resolveCommand, ctx); } catch (CougarException ex) { writeErrorResponse(command, ctx, ex, traceStarted); } catch (Throwable ex) { writeErrorResponse(command, ctx, new CougarServiceException(ServerFaultCode.ServiceRuntimeException, ex.getMessage()), traceStarted); } } }
JsonRpcTransportCommandProcessor extends AbstractHttpCommandProcessor<Void> { @Override public void process(HttpCommand command) { boolean traceStarted = false; incrementCommandsProcessed(); DehydratedExecutionContext ctx = null; try { validateCommand(command); final CommandResolver<HttpCommand> resolver = createCommandResolver(command, tracer); traceStarted = true; ctx = resolver.resolveExecutionContext(); final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest())); final DehydratedExecutionContext finalCtx = ctx; ExecutionCommand resolveCommand = new ExecutionCommand() { @Override public OperationKey getOperationKey() { return IDENTITY_RESOLUTION_OPDEF.getOperationKey(); } @Override public Object[] getArgs() { return new Object[0]; } @Override public void onResult(ExecutionResult executionResult) { Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands(); if (executionResult.isFault()) { for (ExecutionCommand exec : batchCalls) { exec.onResult(executionResult); } } else { ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity()); for (ExecutionCommand exec : resolver.resolveExecutionCommands()) { ExecutionContext subContext = createCallContext(context); tracer.start(subContext.getRequestUUID(), exec.getOperationKey()); ExecutionCommand newCommand = createTraceableSubCommand(exec, tracer, subContext.getRequestUUID()); executeCommand(newCommand, context); } } } @Override public TimeConstraints getTimeConstraints() { return realTimeConstraints; } }; executeCommand(resolveCommand, ctx); } catch (CougarException ex) { writeErrorResponse(command, ctx, ex, traceStarted); } catch (Throwable ex) { writeErrorResponse(command, ctx, new CougarServiceException(ServerFaultCode.ServiceRuntimeException, ex.getMessage()), traceStarted); } } JsonRpcTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, ObjectMapper mapper);  JsonRpcTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, JSONBindingFactory jsonBindingFactory); }
JsonRpcTransportCommandProcessor extends AbstractHttpCommandProcessor<Void> { @Override public void process(HttpCommand command) { boolean traceStarted = false; incrementCommandsProcessed(); DehydratedExecutionContext ctx = null; try { validateCommand(command); final CommandResolver<HttpCommand> resolver = createCommandResolver(command, tracer); traceStarted = true; ctx = resolver.resolveExecutionContext(); final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest())); final DehydratedExecutionContext finalCtx = ctx; ExecutionCommand resolveCommand = new ExecutionCommand() { @Override public OperationKey getOperationKey() { return IDENTITY_RESOLUTION_OPDEF.getOperationKey(); } @Override public Object[] getArgs() { return new Object[0]; } @Override public void onResult(ExecutionResult executionResult) { Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands(); if (executionResult.isFault()) { for (ExecutionCommand exec : batchCalls) { exec.onResult(executionResult); } } else { ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity()); for (ExecutionCommand exec : resolver.resolveExecutionCommands()) { ExecutionContext subContext = createCallContext(context); tracer.start(subContext.getRequestUUID(), exec.getOperationKey()); ExecutionCommand newCommand = createTraceableSubCommand(exec, tracer, subContext.getRequestUUID()); executeCommand(newCommand, context); } } } @Override public TimeConstraints getTimeConstraints() { return realTimeConstraints; } }; executeCommand(resolveCommand, ctx); } catch (CougarException ex) { writeErrorResponse(command, ctx, ex, traceStarted); } catch (Throwable ex) { writeErrorResponse(command, ctx, new CougarServiceException(ServerFaultCode.ServiceRuntimeException, ex.getMessage()), traceStarted); } } JsonRpcTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, ObjectMapper mapper);  JsonRpcTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, JSONBindingFactory jsonBindingFactory); @Override void onCougarStart(); boolean bindOperation(OperationDefinition operationDefinition); @Override void process(HttpCommand command); @Override void writeErrorResponse(HttpCommand command, DehydratedExecutionContext context, CougarException error, boolean traceStarted); boolean writeResponseIfComplete(HttpCommand command, DehydratedExecutionContext context, boolean isBatch, List<JsonRpcRequest> requests, List<JsonRpcResponse> responses, long bytesRead, Tracer tracer); }
JsonRpcTransportCommandProcessor extends AbstractHttpCommandProcessor<Void> { @Override public void process(HttpCommand command) { boolean traceStarted = false; incrementCommandsProcessed(); DehydratedExecutionContext ctx = null; try { validateCommand(command); final CommandResolver<HttpCommand> resolver = createCommandResolver(command, tracer); traceStarted = true; ctx = resolver.resolveExecutionContext(); final TimeConstraints realTimeConstraints = DefaultTimeConstraints.rebaseFromNewStartTime(ctx.getRequestTime(), readRawTimeConstraints(command.getRequest())); final DehydratedExecutionContext finalCtx = ctx; ExecutionCommand resolveCommand = new ExecutionCommand() { @Override public OperationKey getOperationKey() { return IDENTITY_RESOLUTION_OPDEF.getOperationKey(); } @Override public Object[] getArgs() { return new Object[0]; } @Override public void onResult(ExecutionResult executionResult) { Iterable<ExecutionCommand> batchCalls = resolver.resolveExecutionCommands(); if (executionResult.isFault()) { for (ExecutionCommand exec : batchCalls) { exec.onResult(executionResult); } } else { ExecutionContext context = ExecutionContextFactory.resolveExecutionContext(finalCtx, finalCtx.getIdentity()); for (ExecutionCommand exec : resolver.resolveExecutionCommands()) { ExecutionContext subContext = createCallContext(context); tracer.start(subContext.getRequestUUID(), exec.getOperationKey()); ExecutionCommand newCommand = createTraceableSubCommand(exec, tracer, subContext.getRequestUUID()); executeCommand(newCommand, context); } } } @Override public TimeConstraints getTimeConstraints() { return realTimeConstraints; } }; executeCommand(resolveCommand, ctx); } catch (CougarException ex) { writeErrorResponse(command, ctx, ex, traceStarted); } catch (Throwable ex) { writeErrorResponse(command, ctx, new CougarServiceException(ServerFaultCode.ServiceRuntimeException, ex.getMessage()), traceStarted); } } JsonRpcTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, ObjectMapper mapper);  JsonRpcTransportCommandProcessor(DehydratedExecutionContextResolution contextResolution, String requestTimeoutHeader, JSONBindingFactory jsonBindingFactory); @Override void onCougarStart(); boolean bindOperation(OperationDefinition operationDefinition); @Override void process(HttpCommand command); @Override void writeErrorResponse(HttpCommand command, DehydratedExecutionContext context, CougarException error, boolean traceStarted); boolean writeResponseIfComplete(HttpCommand command, DehydratedExecutionContext context, boolean isBatch, List<JsonRpcRequest> requests, List<JsonRpcResponse> responses, long bytesRead, Tracer tracer);  }