public ProgressEvent handleRequest()

in aws-customerprofiles-integration/src/main/java/software/amazon/customerprofiles/integration/CreateHandler.java [41:82]


    public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
            final AmazonWebServicesClientProxy proxy,
            final ResourceHandlerRequest<ResourceModel> request,
            final CallbackContext callbackContext,
            final Logger logger) {

        if (this.client == null) {
            this.client = ClientBuilder.getClient();
        }

        final ResourceModel model = request.getDesiredResourceState();

        // calls to GetIntegration without a URI result in a 400 so we can skip calling
        if (model.getUri() == null) {
            return createIntegration(proxy, request, logger);
        }

        final GetIntegrationRequest getIntegrationRequest = GetIntegrationRequest.builder()
                .domainName(model.getDomainName())
                .uri(model.getUri())
                .build();

        final GetIntegrationResponse getIntegrationResponse;
        try {
            getIntegrationResponse = proxy.injectCredentialsAndInvokeV2(getIntegrationRequest, client::getIntegration);
        } catch (Exception exc) {
            // 1. BadRequestException will also handled by PutIntegration
            // 2. ResourceNotFoundException is the exact exception we want before calling PutIntegration
            // 3. Whatever 5xx error GetIntegration call meet, it should not affect the performance of Create Action
            return createIntegration(proxy, request, logger);
        }

        // If GetIntegration Call succeed
        // Return a Bad Request Exception as Integration already existed
        final String errorMessage = String.format("Integration %s already exists with domainName = %s", getIntegrationResponse.uri(), getIntegrationResponse.domainName());
        logger.log(errorMessage);
        BadRequestException e = BadRequestException.builder()
                .statusCode(BAD_REQUEST_ERROR_CODE)
                .message(errorMessage)
                .build();
        throw new CfnAlreadyExistsException(e);
    }