
software.amazon.awssdk.services.wafv2.model.HTTPRequest 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.wafv2.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
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.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
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.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
*
* This is the latest version of AWS WAF, named AWS WAFV2, released in November, 2019. For information, including
* how to migrate your AWS WAF resources from the prior release, see the AWS WAF Developer Guide.
*
*
*
* Part of the response from GetSampledRequests. This is a complex type that appears as Request
in
* the response syntax. HTTPRequest
contains information about one of the web requests.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class HTTPRequest implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField CLIENT_IP_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ClientIP").getter(getter(HTTPRequest::clientIP)).setter(setter(Builder::clientIP))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ClientIP").build()).build();
private static final SdkField COUNTRY_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Country")
.getter(getter(HTTPRequest::country)).setter(setter(Builder::country))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Country").build()).build();
private static final SdkField URI_FIELD = SdkField. builder(MarshallingType.STRING).memberName("URI")
.getter(getter(HTTPRequest::uri)).setter(setter(Builder::uri))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("URI").build()).build();
private static final SdkField METHOD_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Method")
.getter(getter(HTTPRequest::method)).setter(setter(Builder::method))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Method").build()).build();
private static final SdkField HTTP_VERSION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("HTTPVersion").getter(getter(HTTPRequest::httpVersion)).setter(setter(Builder::httpVersion))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("HTTPVersion").build()).build();
private static final SdkField> HEADERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Headers")
.getter(getter(HTTPRequest::headers))
.setter(setter(Builder::headers))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Headers").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(HTTPHeader::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(CLIENT_IP_FIELD,
COUNTRY_FIELD, URI_FIELD, METHOD_FIELD, HTTP_VERSION_FIELD, HEADERS_FIELD));
private static final long serialVersionUID = 1L;
private final String clientIP;
private final String country;
private final String uri;
private final String method;
private final String httpVersion;
private final List headers;
private HTTPRequest(BuilderImpl builder) {
this.clientIP = builder.clientIP;
this.country = builder.country;
this.uri = builder.uri;
this.method = builder.method;
this.httpVersion = builder.httpVersion;
this.headers = builder.headers;
}
/**
*
* The IP address that the request originated from. If the web ACL is associated with a CloudFront distribution,
* this is the value of one of the following fields in CloudFront access logs:
*
*
* -
*
* c-ip
, if the viewer did not use an HTTP proxy or a load balancer to send the request
*
*
* -
*
* x-forwarded-for
, if the viewer did use an HTTP proxy or a load balancer to send the request
*
*
*
*
* @return The IP address that the request originated from. If the web ACL is associated with a CloudFront
* distribution, this is the value of one of the following fields in CloudFront access logs:
*
* -
*
* c-ip
, if the viewer did not use an HTTP proxy or a load balancer to send the request
*
*
* -
*
* x-forwarded-for
, if the viewer did use an HTTP proxy or a load balancer to send the request
*
*
*/
public String clientIP() {
return clientIP;
}
/**
*
* The two-letter country code for the country that the request originated from. For a current list of country
* codes, see the Wikipedia entry ISO 3166-1 alpha-2.
*
*
* @return The two-letter country code for the country that the request originated from. For a current list of
* country codes, see the Wikipedia entry ISO
* 3166-1 alpha-2.
*/
public String country() {
return country;
}
/**
*
* The URI path of the request, which identifies the resource, for example, /images/daily-ad.jpg
.
*
*
* @return The URI path of the request, which identifies the resource, for example,
* /images/daily-ad.jpg
.
*/
public String uri() {
return uri;
}
/**
*
* The HTTP method specified in the sampled web request.
*
*
* @return The HTTP method specified in the sampled web request.
*/
public String method() {
return method;
}
/**
*
* The HTTP version specified in the sampled web request, for example, HTTP/1.1
.
*
*
* @return The HTTP version specified in the sampled web request, for example, HTTP/1.1
.
*/
public String httpVersion() {
return httpVersion;
}
/**
* Returns true if the Headers property was specified by the sender (it may be empty), or false if the sender did
* not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
*/
public boolean hasHeaders() {
return headers != null && !(headers instanceof SdkAutoConstructList);
}
/**
*
* A complex type that contains the name and value for each header in the sampled web request.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasHeaders()} to see if a value was sent in this field.
*
*
* @return A complex type that contains the name and value for each header in the sampled web request.
*/
public List headers() {
return headers;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(clientIP());
hashCode = 31 * hashCode + Objects.hashCode(country());
hashCode = 31 * hashCode + Objects.hashCode(uri());
hashCode = 31 * hashCode + Objects.hashCode(method());
hashCode = 31 * hashCode + Objects.hashCode(httpVersion());
hashCode = 31 * hashCode + Objects.hashCode(headers());
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 HTTPRequest)) {
return false;
}
HTTPRequest other = (HTTPRequest) obj;
return Objects.equals(clientIP(), other.clientIP()) && Objects.equals(country(), other.country())
&& Objects.equals(uri(), other.uri()) && Objects.equals(method(), other.method())
&& Objects.equals(httpVersion(), other.httpVersion()) && Objects.equals(headers(), other.headers());
}
/**
* 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("HTTPRequest").add("ClientIP", clientIP()).add("Country", country()).add("URI", uri())
.add("Method", method()).add("HTTPVersion", httpVersion()).add("Headers", headers()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ClientIP":
return Optional.ofNullable(clazz.cast(clientIP()));
case "Country":
return Optional.ofNullable(clazz.cast(country()));
case "URI":
return Optional.ofNullable(clazz.cast(uri()));
case "Method":
return Optional.ofNullable(clazz.cast(method()));
case "HTTPVersion":
return Optional.ofNullable(clazz.cast(httpVersion()));
case "Headers":
return Optional.ofNullable(clazz.cast(headers()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function