All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.serverless.proxy.model.AwsProxyRequest Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
/*
 * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
 * with the License. A copy of the License is located at
 *
 * http://aws.amazon.com/apache2.0/
 *
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */
package com.amazonaws.serverless.proxy.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashMap;
import java.util.Map;

/**
 * Default implementation of the request object from an API Gateway AWS_PROXY integration
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class AwsProxyRequest {

    //-------------------------------------------------------------
    // Variables - Private
    //-------------------------------------------------------------

    private String body;
    private String resource;
    private AwsProxyRequestContext requestContext;
    private MultiValuedTreeMap multiValueQueryStringParameters;
    private Headers multiValueHeaders;
    private Map pathParameters;
    private String httpMethod;
    private Map stageVariables;
    private String path;
    private boolean isBase64Encoded;

    public AwsProxyRequest() {
        multiValueHeaders = new Headers();
        multiValueQueryStringParameters = new MultiValuedTreeMap<>();
        pathParameters = new HashMap<>();
        stageVariables = new HashMap<>();
    }


    //-------------------------------------------------------------
    // Methods - Getter/Setter
    //-------------------------------------------------------------

    @JsonIgnore
    public String getQueryString() {
        StringBuilder params = new StringBuilder("");

        if (this.getMultiValueQueryStringParameters() == null) {
            return "";
        }

        for (String key : this.getMultiValueQueryStringParameters().keySet()) {
            for (String val : this.getMultiValueQueryStringParameters().get(key)) {
                String separator = params.length() == 0 ? "?" : "&";

                params.append(separator + key + "=" + val);
            }
        }

        return params.toString();
    }

    public RequestSource getRequestSource() {
        if (getRequestContext() != null && getRequestContext().getElb() != null) {
            return RequestSource.ALB;
        }

        return RequestSource.API_GATEWAY;
    }


    public String getBody() {
        return body;
    }


    public void setBody(String body) {
        this.body = body;
    }


    public String getResource() {
        return resource;
    }


    public void setResource(String resource) {
        this.resource = resource;
    }


    public AwsProxyRequestContext getRequestContext() {
        return requestContext;
    }


    public void setRequestContext(AwsProxyRequestContext requestContext) {
        this.requestContext = requestContext;
    }

    public MultiValuedTreeMap getMultiValueQueryStringParameters() {
        return multiValueQueryStringParameters;
    }


    public void setMultiValueQueryStringParameters(
            MultiValuedTreeMap multiValueQueryStringParameters) {
        this.multiValueQueryStringParameters = multiValueQueryStringParameters;
    }

    public Headers getMultiValueHeaders() {
        return multiValueHeaders;
    }


    public void setMultiValueHeaders(Headers multiValueHeaders) {
        this.multiValueHeaders = multiValueHeaders;
    }


    public Map getPathParameters() {
        return pathParameters;
    }


    public void setPathParameters(Map pathParameters) {
        this.pathParameters = pathParameters;
    }


    public String getHttpMethod() {
        return httpMethod;
    }


    public void setHttpMethod(String httpMethod) {
        this.httpMethod = httpMethod;
    }


    public Map getStageVariables() {
        return stageVariables;
    }


    public void setStageVariables(Map stageVariables) {
        this.stageVariables = stageVariables;
    }


    public String getPath() {
        return path;
    }


    public void setPath(String path) {
        this.path = path;
    }

    @JsonProperty("isBase64Encoded")
    public boolean isBase64Encoded() {
        return isBase64Encoded;
    }


    public void setIsBase64Encoded(boolean base64Encoded) {
        isBase64Encoded = base64Encoded;
    }

    public static enum RequestSource {
        ALB,
        API_GATEWAY
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy