• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.http;
17 
18 import java.util.Optional;
19 import software.amazon.awssdk.annotations.SdkPublicApi;
20 import software.amazon.awssdk.metrics.MetricCollector;
21 
22 /**
23  * Request object containing the parameters necessary to make a synchronous HTTP request.
24  *
25  * @see SdkHttpClient
26  */
27 @SdkPublicApi
28 public final class HttpExecuteRequest {
29 
30     private final SdkHttpRequest request;
31     private final Optional<ContentStreamProvider> contentStreamProvider;
32     private final MetricCollector metricCollector;
33 
HttpExecuteRequest(BuilderImpl builder)34     private HttpExecuteRequest(BuilderImpl builder) {
35         this.request = builder.request;
36         this.contentStreamProvider = builder.contentStreamProvider;
37         this.metricCollector = builder.metricCollector;
38     }
39 
40     /**
41      * @return The HTTP request.
42      */
httpRequest()43     public SdkHttpRequest httpRequest() {
44         return request;
45     }
46 
47     /**
48      * @return The {@link ContentStreamProvider}.
49      */
contentStreamProvider()50     public Optional<ContentStreamProvider> contentStreamProvider() {
51         return contentStreamProvider;
52     }
53 
54     /**
55      * @return The {@link MetricCollector}.
56      */
metricCollector()57     public Optional<MetricCollector> metricCollector() {
58         return Optional.ofNullable(metricCollector);
59     }
60 
builder()61     public static Builder builder() {
62         return new BuilderImpl();
63     }
64 
65     public interface Builder {
66         /**
67          * Set the HTTP request to be executed by the client.
68          *
69          * @param request The request.
70          * @return This builder for method chaining.
71          */
request(SdkHttpRequest request)72         Builder request(SdkHttpRequest request);
73 
74         /**
75          * Set the {@link ContentStreamProvider} to be executed by the client.
76          * @param contentStreamProvider The content stream provider
77          * @return This builder for method chaining
78          */
contentStreamProvider(ContentStreamProvider contentStreamProvider)79         Builder contentStreamProvider(ContentStreamProvider contentStreamProvider);
80 
81         /**
82          * Set the {@link MetricCollector} to be used by the HTTP client to
83          * report metrics collected for this request.
84          *
85          * @param metricCollector The metric collector.
86          * @return This builder for method chaining.
87          */
metricCollector(MetricCollector metricCollector)88         Builder metricCollector(MetricCollector metricCollector);
89 
build()90         HttpExecuteRequest build();
91     }
92 
93     private static class BuilderImpl implements Builder {
94         private SdkHttpRequest request;
95         private Optional<ContentStreamProvider> contentStreamProvider = Optional.empty();
96         private MetricCollector metricCollector;
97 
98         @Override
request(SdkHttpRequest request)99         public Builder request(SdkHttpRequest request) {
100             this.request = request;
101             return this;
102         }
103 
104         @Override
contentStreamProvider(ContentStreamProvider contentStreamProvider)105         public Builder contentStreamProvider(ContentStreamProvider contentStreamProvider) {
106             this.contentStreamProvider = Optional.ofNullable(contentStreamProvider);
107             return this;
108         }
109 
110         @Override
metricCollector(MetricCollector metricCollector)111         public Builder metricCollector(MetricCollector metricCollector) {
112             this.metricCollector = metricCollector;
113             return this;
114         }
115 
116         @Override
build()117         public HttpExecuteRequest build() {
118             return new HttpExecuteRequest(this);
119         }
120     }
121 }
122