software.amazon.awssdk.services.apigateway.model.GatewayResponse Maven / Gradle / Ivy
Show all versions of api-gateway Show documentation
/*
* Copyright 2013-2018 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 software.amazon.awssdk.services.apigateway.model;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.protocol.ProtocolMarshaller;
import software.amazon.awssdk.core.protocol.StructuredPojo;
import software.amazon.awssdk.services.apigateway.transform.GatewayResponseMarshaller;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* A gateway response of a given response type and status code, with optional response parameters and mapping templates.
*
* For more information about valid gateway response types, see Gateway
* Response Types Supported by Amazon API Gateway Example: Get a Gateway Response of a
* given response type
Request
*
* This example shows how to get a gateway response of the MISSING_AUTHNETICATION_TOKEN
type.
*
*
*
* GET /restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN HTTP/1.1 Host: beta-apigateway.us-east-1.amazonaws.com Content-Type: application/json X-Amz-Date: 20170503T202516Z Authorization: AWS4-HMAC-SHA256 Credential={access-key-id}/20170503/us-east-1/apigateway/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=1b52460e3159c1a26cff29093855d50ea141c1c5b937528fecaf60f51129697a Cache-Control: no-cache Postman-Token: 3b2a1ce9-c848-2e26-2e2f-9c2caefbed45
*
*
* The response type is specified as a URL path.
*
* Response
*
* The successful operation returns the 200 OK
status code and a payload similar to the following:
*
*
*
* { "_links": { "curies": { "href": "http://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-gatewayresponse-{rel}.html", "name": "gatewayresponse", "templated": true }, "self": { "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN" }, "gatewayresponse:delete": { "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN" }, "gatewayresponse:put": { "href": "/restapis/o81lxisefl/gatewayresponses/{response_type}", "templated": true }, "gatewayresponse:update": { "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN" } }, "defaultResponse": false, "responseParameters": { "gatewayresponse.header.x-request-path": "method.request.path.petId", "gatewayresponse.header.Access-Control-Allow-Origin": "'a.b.c'", "gatewayresponse.header.x-request-query": "method.request.querystring.q", "gatewayresponse.header.x-request-header": "method.request.header.Accept" }, "responseTemplates": { "application/json": "{\n \"message\": $context.error.messageString,\n \"type\": \"$context.error.responseType\",\n \"stage\": \"$context.stage\",\n \"resourcePath\": \"$context.resourcePath\",\n \"stageVariables.a\": \"$stageVariables.a\",\n \"statusCode\": \"'404'\"\n}" }, "responseType": "MISSING_AUTHENTICATION_TOKEN", "statusCode": "404" }
*
*
*
*
*/
@Generated("software.amazon.awssdk:codegen")
public class GatewayResponse implements StructuredPojo, ToCopyableBuilder {
private final String responseType;
private final String statusCode;
private final Map responseParameters;
private final Map responseTemplates;
private final Boolean defaultResponse;
private GatewayResponse(BuilderImpl builder) {
this.responseType = builder.responseType;
this.statusCode = builder.statusCode;
this.responseParameters = builder.responseParameters;
this.responseTemplates = builder.responseTemplates;
this.defaultResponse = builder.defaultResponse;
}
/**
*
* The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #responseType} will
* return {@link GatewayResponseType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available
* from {@link #responseTypeString}.
*
*
* @return The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
* @see GatewayResponseType
*/
public GatewayResponseType responseType() {
return GatewayResponseType.fromValue(responseType);
}
/**
*
* The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #responseType} will
* return {@link GatewayResponseType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available
* from {@link #responseTypeString}.
*
*
* @return The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
* @see GatewayResponseType
*/
public String responseTypeString() {
return responseType;
}
/**
*
* The HTTP status code for this GatewayResponse.
*
*
* @return The HTTP status code for this GatewayResponse.
*/
public String statusCode() {
return statusCode;
}
/**
*
* Response parameters (paths, query strings and headers) of the GatewayResponse as a string-to-string map of
* key-value pairs.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return Response parameters (paths, query strings and headers) of the GatewayResponse as a
* string-to-string map of key-value pairs.
*/
public Map responseParameters() {
return responseParameters;
}
/**
*
* Response templates of the GatewayResponse as a string-to-string map of key-value pairs.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return Response templates of the GatewayResponse as a string-to-string map of key-value pairs.
*/
public Map responseTemplates() {
return responseTemplates;
}
/**
*
* A Boolean flag to indicate whether this GatewayResponse is the default gateway response (true
* ) or not (false
). A default gateway response is one generated by Amazon API Gateway without any
* customization by an API developer.
*
*
* @return A Boolean flag to indicate whether this GatewayResponse is the default gateway response (
* true
) or not (false
). A default gateway response is one generated by Amazon API
* Gateway without any customization by an API developer.
*/
public Boolean defaultResponse() {
return defaultResponse;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(responseTypeString());
hashCode = 31 * hashCode + Objects.hashCode(statusCode());
hashCode = 31 * hashCode + Objects.hashCode(responseParameters());
hashCode = 31 * hashCode + Objects.hashCode(responseTemplates());
hashCode = 31 * hashCode + Objects.hashCode(defaultResponse());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof GatewayResponse)) {
return false;
}
GatewayResponse other = (GatewayResponse) obj;
return Objects.equals(responseTypeString(), other.responseTypeString())
&& Objects.equals(statusCode(), other.statusCode())
&& Objects.equals(responseParameters(), other.responseParameters())
&& Objects.equals(responseTemplates(), other.responseTemplates())
&& Objects.equals(defaultResponse(), other.defaultResponse());
}
@Override
public String toString() {
return ToString.builder("GatewayResponse").add("ResponseType", responseTypeString()).add("StatusCode", statusCode())
.add("ResponseParameters", responseParameters()).add("ResponseTemplates", responseTemplates())
.add("DefaultResponse", defaultResponse()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "responseType":
return Optional.of(clazz.cast(responseTypeString()));
case "statusCode":
return Optional.of(clazz.cast(statusCode()));
case "responseParameters":
return Optional.of(clazz.cast(responseParameters()));
case "responseTemplates":
return Optional.of(clazz.cast(responseTemplates()));
case "defaultResponse":
return Optional.of(clazz.cast(defaultResponse()));
default:
return Optional.empty();
}
}
@SdkInternalApi
@Override
public void marshall(ProtocolMarshaller protocolMarshaller) {
GatewayResponseMarshaller.getInstance().marshall(this, protocolMarshaller);
}
public interface Builder extends CopyableBuilder {
/**
*
* The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
*
*
* @param responseType
* The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
* @see GatewayResponseType
* @return Returns a reference to this object so that method calls can be chained together.
* @see GatewayResponseType
*/
Builder responseType(String responseType);
/**
*
* The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
*
*
* @param responseType
* The response type of the associated GatewayResponse. Valid values are
*
* - ACCESS_DENIED
* - API_CONFIGURATION_ERROR
* - AUTHORIZER_FAILURE
* - AUTHORIZER_CONFIGURATION_ERROR
* - BAD_REQUEST_PARAMETERS
* - BAD_REQUEST_BODY
* - DEFAULT_4XX
* - DEFAULT_5XX
* - EXPIRED_TOKEN
* - INVALID_SIGNATURE
* - INTEGRATION_FAILURE
* - INTEGRATION_TIMEOUT
* - INVALID_API_KEY
* - MISSING_AUTHENTICATION_TOKEN
* - QUOTA_EXCEEDED
* - REQUEST_TOO_LARGE
* - RESOURCE_NOT_FOUND
* - THROTTLED
* - UNAUTHORIZED
* - UNSUPPORTED_MEDIA_TYPES
*
* @see GatewayResponseType
* @return Returns a reference to this object so that method calls can be chained together.
* @see GatewayResponseType
*/
Builder responseType(GatewayResponseType responseType);
/**
*
* The HTTP status code for this GatewayResponse.
*
*
* @param statusCode
* The HTTP status code for this GatewayResponse.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder statusCode(String statusCode);
/**
*
* Response parameters (paths, query strings and headers) of the GatewayResponse as a string-to-string
* map of key-value pairs.
*
*
* @param responseParameters
* Response parameters (paths, query strings and headers) of the GatewayResponse as a
* string-to-string map of key-value pairs.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder responseParameters(Map responseParameters);
/**
*
* Response templates of the GatewayResponse as a string-to-string map of key-value pairs.
*
*
* @param responseTemplates
* Response templates of the GatewayResponse as a string-to-string map of key-value pairs.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder responseTemplates(Map responseTemplates);
/**
*
* A Boolean flag to indicate whether this GatewayResponse is the default gateway response (
* true
) or not (false
). A default gateway response is one generated by Amazon API
* Gateway without any customization by an API developer.
*
*
* @param defaultResponse
* A Boolean flag to indicate whether this GatewayResponse is the default gateway response (
* true
) or not (false
). A default gateway response is one generated by Amazon
* API Gateway without any customization by an API developer.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder defaultResponse(Boolean defaultResponse);
}
static final class BuilderImpl implements Builder {
private String responseType;
private String statusCode;
private Map responseParameters;
private Map responseTemplates;
private Boolean defaultResponse;
private BuilderImpl() {
}
private BuilderImpl(GatewayResponse model) {
responseType(model.responseType);
statusCode(model.statusCode);
responseParameters(model.responseParameters);
responseTemplates(model.responseTemplates);
defaultResponse(model.defaultResponse);
}
public final String getResponseType() {
return responseType;
}
@Override
public final Builder responseType(String responseType) {
this.responseType = responseType;
return this;
}
@Override
public final Builder responseType(GatewayResponseType responseType) {
this.responseType(responseType.toString());
return this;
}
public final void setResponseType(String responseType) {
this.responseType = responseType;
}
public final String getStatusCode() {
return statusCode;
}
@Override
public final Builder statusCode(String statusCode) {
this.statusCode = statusCode;
return this;
}
public final void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public final Map getResponseParameters() {
return responseParameters;
}
@Override
public final Builder responseParameters(Map responseParameters) {
this.responseParameters = MapOfStringToStringCopier.copy(responseParameters);
return this;
}
public final void setResponseParameters(Map responseParameters) {
this.responseParameters = MapOfStringToStringCopier.copy(responseParameters);
}
public final Map getResponseTemplates() {
return responseTemplates;
}
@Override
public final Builder responseTemplates(Map responseTemplates) {
this.responseTemplates = MapOfStringToStringCopier.copy(responseTemplates);
return this;
}
public final void setResponseTemplates(Map responseTemplates) {
this.responseTemplates = MapOfStringToStringCopier.copy(responseTemplates);
}
public final Boolean getDefaultResponse() {
return defaultResponse;
}
@Override
public final Builder defaultResponse(Boolean defaultResponse) {
this.defaultResponse = defaultResponse;
return this;
}
public final void setDefaultResponse(Boolean defaultResponse) {
this.defaultResponse = defaultResponse;
}
@Override
public GatewayResponse build() {
return new GatewayResponse(this);
}
}
}