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

software.amazon.awssdk.services.cloudfront.model.CustomErrorResponse Maven / Gradle / Ivy

/*
 * Copyright 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.cloudfront.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* A complex type that controls: *

*
    *
  • *

    * Whether CloudFront replaces HTTP status codes in the 4xx and 5xx range with custom error messages before returning * the response to the viewer. *

    *
  • *
  • *

    * How long CloudFront caches HTTP status codes in the 4xx and 5xx range. *

    *
  • *
*

* For more information about custom error pages, see Customizing Error * Responses in the Amazon CloudFront Developer Guide. *

*/ @Generated("software.amazon.awssdk:codegen") public final class CustomErrorResponse implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField ERROR_CODE_FIELD = SdkField . builder(MarshallingType.INTEGER) .getter(getter(CustomErrorResponse::errorCode)) .setter(setter(Builder::errorCode)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ErrorCode") .unmarshallLocationName("ErrorCode").build()).build(); private static final SdkField RESPONSE_PAGE_PATH_FIELD = SdkField . builder(MarshallingType.STRING) .getter(getter(CustomErrorResponse::responsePagePath)) .setter(setter(Builder::responsePagePath)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ResponsePagePath") .unmarshallLocationName("ResponsePagePath").build()).build(); private static final SdkField RESPONSE_CODE_FIELD = SdkField . builder(MarshallingType.STRING) .getter(getter(CustomErrorResponse::responseCode)) .setter(setter(Builder::responseCode)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ResponseCode") .unmarshallLocationName("ResponseCode").build()).build(); private static final SdkField ERROR_CACHING_MIN_TTL_FIELD = SdkField . builder(MarshallingType.LONG) .getter(getter(CustomErrorResponse::errorCachingMinTTL)) .setter(setter(Builder::errorCachingMinTTL)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ErrorCachingMinTTL") .unmarshallLocationName("ErrorCachingMinTTL").build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(ERROR_CODE_FIELD, RESPONSE_PAGE_PATH_FIELD, RESPONSE_CODE_FIELD, ERROR_CACHING_MIN_TTL_FIELD)); private static final long serialVersionUID = 1L; private final Integer errorCode; private final String responsePagePath; private final String responseCode; private final Long errorCachingMinTTL; private CustomErrorResponse(BuilderImpl builder) { this.errorCode = builder.errorCode; this.responsePagePath = builder.responsePagePath; this.responseCode = builder.responseCode; this.errorCachingMinTTL = builder.errorCachingMinTTL; } /** *

* The HTTP status code for which you want to specify a custom error page and/or a caching duration. *

* * @return The HTTP status code for which you want to specify a custom error page and/or a caching duration. */ public Integer errorCode() { return errorCode; } /** *

* The path to the custom error page that you want CloudFront to return to a viewer when your origin returns the * HTTP status code specified by ErrorCode, for example, /4xx-errors/403-forbidden.html. * If you want to store your objects and your custom error pages in different locations, your distribution must * include a cache behavior for which the following is true: *

*
    *
  • *

    * The value of PathPattern matches the path to your custom error messages. For example, suppose you * saved custom error pages for 4xx errors in an Amazon S3 bucket in a directory named /4xx-errors. * Your distribution must include a cache behavior for which the path pattern routes requests for your custom error * pages to that location, for example, /4xx-errors/*. *

    *
  • *
  • *

    * The value of TargetOriginId specifies the value of the ID element for the origin that * contains your custom error pages. *

    *
  • *
*

* If you specify a value for ResponsePagePath, you must also specify a value for * ResponseCode. *

*

* We recommend that you store custom error pages in an Amazon S3 bucket. If you store custom error pages on an HTTP * server and the server starts to return 5xx errors, CloudFront can't get the files that you want to return to * viewers because the origin server is unavailable. *

* * @return The path to the custom error page that you want CloudFront to return to a viewer when your origin returns * the HTTP status code specified by ErrorCode, for example, * /4xx-errors/403-forbidden.html. If you want to store your objects and your custom error * pages in different locations, your distribution must include a cache behavior for which the following is * true:

*
    *
  • *

    * The value of PathPattern matches the path to your custom error messages. For example, * suppose you saved custom error pages for 4xx errors in an Amazon S3 bucket in a directory named * /4xx-errors. Your distribution must include a cache behavior for which the path pattern * routes requests for your custom error pages to that location, for example, /4xx-errors/*. *

    *
  • *
  • *

    * The value of TargetOriginId specifies the value of the ID element for the * origin that contains your custom error pages. *

    *
  • *
*

* If you specify a value for ResponsePagePath, you must also specify a value for * ResponseCode. *

*

* We recommend that you store custom error pages in an Amazon S3 bucket. If you store custom error pages on * an HTTP server and the server starts to return 5xx errors, CloudFront can't get the files that you want * to return to viewers because the origin server is unavailable. */ public String responsePagePath() { return responsePagePath; } /** *

* The HTTP status code that you want CloudFront to return to the viewer along with the custom error page. There are * a variety of reasons that you might want CloudFront to return a status code different from the status code that * your origin returned to CloudFront, for example: *

*
    *
  • *

    * Some Internet devices (some firewalls and corporate proxies, for example) intercept HTTP 4xx and 5xx and prevent * the response from being returned to the viewer. If you substitute 200, the response typically won't * be intercepted. *

    *
  • *
  • *

    * If you don't care about distinguishing among different client errors or server errors, you can specify * 400 or 500 as the ResponseCode for all 4xx or 5xx errors. *

    *
  • *
  • *

    * You might want to return a 200 status code (OK) and static website so your customers don't know that * your website is down. *

    *
  • *
*

* If you specify a value for ResponseCode, you must also specify a value for * ResponsePagePath. *

* * @return The HTTP status code that you want CloudFront to return to the viewer along with the custom error page. * There are a variety of reasons that you might want CloudFront to return a status code different from the * status code that your origin returned to CloudFront, for example:

*
    *
  • *

    * Some Internet devices (some firewalls and corporate proxies, for example) intercept HTTP 4xx and 5xx and * prevent the response from being returned to the viewer. If you substitute 200, the response * typically won't be intercepted. *

    *
  • *
  • *

    * If you don't care about distinguishing among different client errors or server errors, you can specify * 400 or 500 as the ResponseCode for all 4xx or 5xx errors. *

    *
  • *
  • *

    * You might want to return a 200 status code (OK) and static website so your customers don't * know that your website is down. *

    *
  • *
*

* If you specify a value for ResponseCode, you must also specify a value for * ResponsePagePath. */ public String responseCode() { return responseCode; } /** *

* The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code specified in * ErrorCode. When this time period has elapsed, CloudFront queries your origin to see whether the * problem that caused the error has been resolved and the requested object is now available. *

*

* For more information, see Customizing * Error Responses in the Amazon CloudFront Developer Guide. *

* * @return The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code specified * in ErrorCode. When this time period has elapsed, CloudFront queries your origin to see * whether the problem that caused the error has been resolved and the requested object is now * available.

*

* For more information, see Customizing Error Responses in the Amazon CloudFront Developer Guide. */ public Long errorCachingMinTTL() { return errorCachingMinTTL; } @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(errorCode()); hashCode = 31 * hashCode + Objects.hashCode(responsePagePath()); hashCode = 31 * hashCode + Objects.hashCode(responseCode()); hashCode = 31 * hashCode + Objects.hashCode(errorCachingMinTTL()); return hashCode; } @Override public boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof CustomErrorResponse)) { return false; } CustomErrorResponse other = (CustomErrorResponse) obj; return Objects.equals(errorCode(), other.errorCode()) && Objects.equals(responsePagePath(), other.responsePagePath()) && Objects.equals(responseCode(), other.responseCode()) && Objects.equals(errorCachingMinTTL(), other.errorCachingMinTTL()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("CustomErrorResponse").add("ErrorCode", errorCode()).add("ResponsePagePath", responsePagePath()) .add("ResponseCode", responseCode()).add("ErrorCachingMinTTL", errorCachingMinTTL()).build(); } public Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "ErrorCode": return Optional.ofNullable(clazz.cast(errorCode())); case "ResponsePagePath": return Optional.ofNullable(clazz.cast(responsePagePath())); case "ResponseCode": return Optional.ofNullable(clazz.cast(responseCode())); case "ErrorCachingMinTTL": return Optional.ofNullable(clazz.cast(errorCachingMinTTL())); default: return Optional.empty(); } } @Override public List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((CustomErrorResponse) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* The HTTP status code for which you want to specify a custom error page and/or a caching duration. *

* * @param errorCode * The HTTP status code for which you want to specify a custom error page and/or a caching duration. * @return Returns a reference to this object so that method calls can be chained together. */ Builder errorCode(Integer errorCode); /** *

* The path to the custom error page that you want CloudFront to return to a viewer when your origin returns the * HTTP status code specified by ErrorCode, for example, * /4xx-errors/403-forbidden.html. If you want to store your objects and your custom error pages in * different locations, your distribution must include a cache behavior for which the following is true: *

*
    *
  • *

    * The value of PathPattern matches the path to your custom error messages. For example, suppose * you saved custom error pages for 4xx errors in an Amazon S3 bucket in a directory named * /4xx-errors. Your distribution must include a cache behavior for which the path pattern routes * requests for your custom error pages to that location, for example, /4xx-errors/*. *

    *
  • *
  • *

    * The value of TargetOriginId specifies the value of the ID element for the origin * that contains your custom error pages. *

    *
  • *
*

* If you specify a value for ResponsePagePath, you must also specify a value for * ResponseCode. *

*

* We recommend that you store custom error pages in an Amazon S3 bucket. If you store custom error pages on an * HTTP server and the server starts to return 5xx errors, CloudFront can't get the files that you want to * return to viewers because the origin server is unavailable. *

* * @param responsePagePath * The path to the custom error page that you want CloudFront to return to a viewer when your origin * returns the HTTP status code specified by ErrorCode, for example, * /4xx-errors/403-forbidden.html. If you want to store your objects and your custom error * pages in different locations, your distribution must include a cache behavior for which the following * is true:

*
    *
  • *

    * The value of PathPattern matches the path to your custom error messages. For example, * suppose you saved custom error pages for 4xx errors in an Amazon S3 bucket in a directory named * /4xx-errors. Your distribution must include a cache behavior for which the path pattern * routes requests for your custom error pages to that location, for example, /4xx-errors/*. *

    *
  • *
  • *

    * The value of TargetOriginId specifies the value of the ID element for the * origin that contains your custom error pages. *

    *
  • *
*

* If you specify a value for ResponsePagePath, you must also specify a value for * ResponseCode. *

*

* We recommend that you store custom error pages in an Amazon S3 bucket. If you store custom error pages * on an HTTP server and the server starts to return 5xx errors, CloudFront can't get the files that you * want to return to viewers because the origin server is unavailable. * @return Returns a reference to this object so that method calls can be chained together. */ Builder responsePagePath(String responsePagePath); /** *

* The HTTP status code that you want CloudFront to return to the viewer along with the custom error page. There * are a variety of reasons that you might want CloudFront to return a status code different from the status * code that your origin returned to CloudFront, for example: *

*
    *
  • *

    * Some Internet devices (some firewalls and corporate proxies, for example) intercept HTTP 4xx and 5xx and * prevent the response from being returned to the viewer. If you substitute 200, the response * typically won't be intercepted. *

    *
  • *
  • *

    * If you don't care about distinguishing among different client errors or server errors, you can specify * 400 or 500 as the ResponseCode for all 4xx or 5xx errors. *

    *
  • *
  • *

    * You might want to return a 200 status code (OK) and static website so your customers don't know * that your website is down. *

    *
  • *
*

* If you specify a value for ResponseCode, you must also specify a value for * ResponsePagePath. *

* * @param responseCode * The HTTP status code that you want CloudFront to return to the viewer along with the custom error * page. There are a variety of reasons that you might want CloudFront to return a status code different * from the status code that your origin returned to CloudFront, for example:

*
    *
  • *

    * Some Internet devices (some firewalls and corporate proxies, for example) intercept HTTP 4xx and 5xx * and prevent the response from being returned to the viewer. If you substitute 200, the * response typically won't be intercepted. *

    *
  • *
  • *

    * If you don't care about distinguishing among different client errors or server errors, you can specify * 400 or 500 as the ResponseCode for all 4xx or 5xx errors. *

    *
  • *
  • *

    * You might want to return a 200 status code (OK) and static website so your customers * don't know that your website is down. *

    *
  • *
*

* If you specify a value for ResponseCode, you must also specify a value for * ResponsePagePath. * @return Returns a reference to this object so that method calls can be chained together. */ Builder responseCode(String responseCode); /** *

* The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code specified in * ErrorCode. When this time period has elapsed, CloudFront queries your origin to see whether the * problem that caused the error has been resolved and the requested object is now available. *

*

* For more information, see Customizing * Error Responses in the Amazon CloudFront Developer Guide. *

* * @param errorCachingMinTTL * The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code * specified in ErrorCode. When this time period has elapsed, CloudFront queries your origin * to see whether the problem that caused the error has been resolved and the requested object is now * available.

*

* For more information, see Customizing Error Responses in the Amazon CloudFront Developer Guide. * @return Returns a reference to this object so that method calls can be chained together. */ Builder errorCachingMinTTL(Long errorCachingMinTTL); } static final class BuilderImpl implements Builder { private Integer errorCode; private String responsePagePath; private String responseCode; private Long errorCachingMinTTL; private BuilderImpl() { } private BuilderImpl(CustomErrorResponse model) { errorCode(model.errorCode); responsePagePath(model.responsePagePath); responseCode(model.responseCode); errorCachingMinTTL(model.errorCachingMinTTL); } public final Integer getErrorCode() { return errorCode; } @Override public final Builder errorCode(Integer errorCode) { this.errorCode = errorCode; return this; } public final void setErrorCode(Integer errorCode) { this.errorCode = errorCode; } public final String getResponsePagePath() { return responsePagePath; } @Override public final Builder responsePagePath(String responsePagePath) { this.responsePagePath = responsePagePath; return this; } public final void setResponsePagePath(String responsePagePath) { this.responsePagePath = responsePagePath; } public final String getResponseCode() { return responseCode; } @Override public final Builder responseCode(String responseCode) { this.responseCode = responseCode; return this; } public final void setResponseCode(String responseCode) { this.responseCode = responseCode; } public final Long getErrorCachingMinTTL() { return errorCachingMinTTL; } @Override public final Builder errorCachingMinTTL(Long errorCachingMinTTL) { this.errorCachingMinTTL = errorCachingMinTTL; return this; } public final void setErrorCachingMinTTL(Long errorCachingMinTTL) { this.errorCachingMinTTL = errorCachingMinTTL; } @Override public CustomErrorResponse build() { return new CustomErrorResponse(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy