public void processRequest()

in src/main/java/software/amazon/cloudformation/AbstractWrapper.java [179:240]


    public void processRequest(final InputStream inputStream, final OutputStream outputStream) throws IOException,
        TerminalException {

        ProgressEvent<ResourceT, CallbackT> handlerResponse = null;
        HandlerRequest<ResourceT, CallbackT, ConfigurationT> request = null;
        scrubFiles();
        try {
            if (inputStream == null) {
                throw new TerminalException("No request object received");
            }

            String input = this.serializer.decompress(IOUtils.toString(inputStream, StandardCharsets.UTF_8));

            JSONObject rawInput = new JSONObject(new JSONTokener(input));
            // deserialize incoming payload to modelled request
            try {
                request = this.serializer.deserialize(input, typeReference);

                handlerResponse = processInvocation(rawInput, request);
            } catch (MismatchedInputException e) {
                JSONObject resourceSchemaJSONObject = provideResourceSchemaJSONObject();
                JSONObject rawModelObject = rawInput.getJSONObject("requestData").getJSONObject("resourceProperties");

                this.validator.validateObject(rawModelObject, resourceSchemaJSONObject);

                handlerResponse = ProgressEvent.defaultFailureHandler(
                    new CfnInvalidRequestException("Resource properties validation failed with invalid configuration", e),
                    HandlerErrorCode.InvalidRequest);

            }

        } catch (final ValidationException e) {
            String message;
            String fullExceptionMessage = ValidationException.buildFullExceptionMessage(e);
            if (!StringUtils.isEmpty(fullExceptionMessage)) {
                message = String.format("Model validation failed (%s)", fullExceptionMessage);
            } else {
                message = "Model validation failed with unknown cause.";
            }

            publishExceptionMetric(request == null ? null : request.getAction(), e, HandlerErrorCode.InvalidRequest);
            handlerResponse = ProgressEvent.defaultFailureHandler(new TerminalException(message, e),
                HandlerErrorCode.InvalidRequest);
        } catch (final Throwable e) {
            // Exceptions are wrapped as a consistent error response to the caller (i.e;
            // CloudFormation)
            log(ExceptionUtils.getStackTrace(e)); // for root causing
            handlerResponse = ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.InternalFailure);
            if (request != null && request.getRequestData() != null && MUTATING_ACTIONS.contains(request.getAction())) {
                handlerResponse.setResourceModel(request.getRequestData().getResourceProperties());
            }
            if (request != null) {
                publishExceptionMetric(request.getAction(), e, HandlerErrorCode.InternalFailure);
            }

        } finally {
            // A response will be output on all paths, though CloudFormation will
            // not block on invoking the handlers, but rather listen for callbacks
            writeResponse(outputStream, handlerResponse);
            publishExceptionCodeAndCountMetrics(request == null ? null : request.getAction(), handlerResponse.getErrorCode());
        }
    }