/** * @param request Not null. * @param context Nullable. */ public void executeRequest(final RollRequest request, final IRequestContext context) throws FatalException { try { final String methodCode = resolveMethodCode(request, context); final String input = request.getRequest(); try { if (requestTooLong(input)) throw new RequestTooLongException(input.length(), getMaxRequestLength()); final IRollingMethod method = this.factory.getMethod(methodCode); final IDieRollerFactory factory = createDieRollerFactory(); final IRollConfig config = context != null ? context.getConfig(method) : null; final IFormattedBufferedOutput wrappedOutput = wrapOutput(request); method.writeResult(factory, config, input, wrappedOutput); wrappedOutput.flush(); } catch (final UserReadableException exception) { request.getOutput().append(exception.getMessage()).with(Style.RED); } } catch (final OutputException exception) { throw new FatalException(exception); } }
public IFormattedBufferedOutput wrapOutput(final RollRequest request) { final IFormattedBufferedOutput output = getMaxResultLength() == null ? new WrappingWriter(request.getOutput()) : new LimitingWriter(request.getOutput(), getMaxResultLength()); return output; }