Search in sources :

Example 1 with ApiRedirectResponse

use of com.formkiq.lambda.apigateway.ApiRedirectResponse in project formkiq-core by formkiq.

the class PublicWebhooksRequestHandler method buildRedirect.

private ApiRequestHandlerResponse buildRedirect(final ApiGatewayRequestEvent event, final String redirectUri, final String body) {
    ApiRequestHandlerResponse response;
    StringBuilder sb = new StringBuilder();
    sb.append(redirectUri);
    Map<String, String> queryMap = decodeQueryString(body);
    String responseFields = getParameter(event, "responseFields");
    if (StringUtils.isNotBlank(responseFields)) {
        String[] fields = responseFields.split(",");
        for (int i = 0; i < fields.length; i++) {
            String value = queryMap.get(fields[i]);
            sb.append(i == 0 && redirectUri.indexOf("?") == -1 ? "?" : "&");
            sb.append(fields[i] + "=" + value);
        }
    }
    response = new ApiRequestHandlerResponse(MOVED_PERMANENTLY, new ApiRedirectResponse(sb.toString()));
    return response;
}
Also used : ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiRedirectResponse(com.formkiq.lambda.apigateway.ApiRedirectResponse)

Example 2 with ApiRedirectResponse

use of com.formkiq.lambda.apigateway.ApiRedirectResponse in project formkiq-core by formkiq.

the class PublicWebhooksRequestHandler method buildResponse.

private ApiRequestHandlerResponse buildResponse(final ApiGatewayRequestEvent event, final DynamicObject item) {
    String body = item.getString("content");
    String documentId = item.getString("documentId");
    String contentType = item.getString("contentType");
    ApiRequestHandlerResponse response = new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("documentId", documentId)));
    String redirectUri = getParameter(event, "redirect_uri");
    if ("application/x-www-form-urlencoded".equals(contentType) && StringUtils.isNotBlank(redirectUri)) {
        response = buildRedirect(event, redirectUri, body);
    } else if (StringUtils.isNotBlank(redirectUri)) {
        response = new ApiRequestHandlerResponse(MOVED_PERMANENTLY, new ApiRedirectResponse(redirectUri));
    }
    return response;
}
Also used : ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ApiRedirectResponse(com.formkiq.lambda.apigateway.ApiRedirectResponse) ApiMapResponse(com.formkiq.lambda.apigateway.ApiMapResponse)

Aggregations

ApiRedirectResponse (com.formkiq.lambda.apigateway.ApiRedirectResponse)2 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)2 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)1