Skip to content

Commit c727e98

Browse files
authored
Remove the use of S3NativeClient and integrate with S3Client (#2990)
* Revert "Revert "Remove the use of S3NativeClient and integrate with S3Client (#2976)"" This reverts commit cf0d833. * Fix region issue
1 parent 2a566c8 commit c727e98

35 files changed

+1205
-1721
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/SdkInternalExecutionAttribute.java

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import software.amazon.awssdk.annotations.SdkProtectedApi;
1919
import software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired;
20+
import software.amazon.awssdk.http.SdkHttpExecutionAttributes;
2021

2122
/**
2223
* Attributes that can be applied to all sdk requests. Only generated code from the SDK clients should set these values.
@@ -47,6 +48,12 @@ public final class SdkInternalExecutionAttribute extends SdkExecutionAttribute {
4748
public static final ExecutionAttribute<Boolean> DISABLE_HOST_PREFIX_INJECTION =
4849
new ExecutionAttribute<>("DisableHostPrefixInjection");
4950

51+
/**
52+
* The SDK HTTP attributes that can be passed to the HTTP client
53+
*/
54+
public static final ExecutionAttribute<SdkHttpExecutionAttributes> SDK_HTTP_EXECUTION_ATTRIBUTES =
55+
new ExecutionAttribute<>("SdkHttpExecutionAttributes");
56+
5057
private SdkInternalExecutionAttribute() {
5158
}
5259
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/MakeAsyncHttpRequestStage.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.core.internal.http.pipeline.stages;
1717

18+
import static software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute.SDK_HTTP_EXECUTION_ATTRIBUTES;
1819
import static software.amazon.awssdk.core.internal.http.timers.TimerUtils.resolveTimeoutInMillis;
1920
import static software.amazon.awssdk.http.Header.CONTENT_LENGTH;
2021

@@ -180,15 +181,19 @@ private CompletableFuture<Response<OutputT>> executeHttpRequest(SdkHttpFullReque
180181

181182
MetricCollector httpMetricCollector = MetricUtils.createHttpMetricsCollector(context);
182183

183-
AsyncExecuteRequest executeRequest = AsyncExecuteRequest.builder()
184+
AsyncExecuteRequest.Builder executeRequestBuilder = AsyncExecuteRequest.builder()
184185
.request(requestWithContentLength)
185186
.requestContentPublisher(requestProvider)
186187
.responseHandler(wrappedResponseHandler)
187188
.fullDuplex(isFullDuplex(context.executionAttributes()))
188-
.metricCollector(httpMetricCollector)
189-
.build();
189+
.metricCollector(httpMetricCollector);
190+
if (context.executionAttributes().getAttribute(SDK_HTTP_EXECUTION_ATTRIBUTES) != null) {
191+
executeRequestBuilder.httpExecutionAttributes(
192+
context.executionAttributes()
193+
.getAttribute(SDK_HTTP_EXECUTION_ATTRIBUTES));
194+
}
190195

191-
CompletableFuture<Void> httpClientFuture = doExecuteHttpRequest(context, executeRequest);
196+
CompletableFuture<Void> httpClientFuture = doExecuteHttpRequest(context, executeRequestBuilder.build());
192197

193198
TimeoutTracker timeoutTracker = setupAttemptTimer(responseFuture, context);
194199
context.apiCallAttemptTimeoutTracker(timeoutTracker);

http-client-spi/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@
8080
<artifactId>reactive-streams-tck</artifactId>
8181
<scope>test</scope>
8282
</dependency>
83+
<dependency>
84+
<groupId>nl.jqno.equalsverifier</groupId>
85+
<artifactId>equalsverifier</artifactId>
86+
<scope>test</scope>
87+
</dependency>
8388
</dependencies>
8489

8590
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
20+
import software.amazon.awssdk.utils.AttributeMap;
21+
22+
/**
23+
* An attribute attached to a particular HTTP request execution, stored in {@link SdkHttpExecutionAttributes}. It can be
24+
* configured on an {@link AsyncExecuteRequest} via
25+
* {@link AsyncExecuteRequest.Builder#putHttpExecutionAttribute(SdkHttpExecutionAttribute,
26+
* Object)}
27+
*
28+
* @param <T> The type of data associated with this attribute.
29+
*/
30+
@SdkPublicApi
31+
public abstract class SdkHttpExecutionAttribute<T> extends AttributeMap.Key<T> {
32+
33+
protected SdkHttpExecutionAttribute(Class<T> valueType) {
34+
super(valueType);
35+
}
36+
37+
protected SdkHttpExecutionAttribute(UnsafeValueType unsafeValueType) {
38+
super(unsafeValueType);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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.Map;
19+
import java.util.Objects;
20+
import software.amazon.awssdk.annotations.SdkPublicApi;
21+
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
22+
import software.amazon.awssdk.utils.AttributeMap;
23+
import software.amazon.awssdk.utils.Validate;
24+
import software.amazon.awssdk.utils.builder.CopyableBuilder;
25+
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
26+
27+
/**
28+
* An immutable collection of {@link SdkHttpExecutionAttribute}s that can be configured on an {@link AsyncExecuteRequest} via
29+
* {@link AsyncExecuteRequest.Builder#httpExecutionAttributes(SdkHttpExecutionAttributes)}
30+
*/
31+
@SdkPublicApi
32+
public final class SdkHttpExecutionAttributes implements ToCopyableBuilder<SdkHttpExecutionAttributes.Builder,
33+
SdkHttpExecutionAttributes> {
34+
private final AttributeMap attributes;
35+
36+
private SdkHttpExecutionAttributes(Builder builder) {
37+
this.attributes = builder.sdkHttpExecutionAttributes.build();
38+
}
39+
40+
/**
41+
* Retrieve the current value of the provided attribute in this collection of attributes. This will return null if the value
42+
* is not set.
43+
*/
44+
public <T> T getAttribute(SdkHttpExecutionAttribute<T> attribute) {
45+
return attributes.get(attribute);
46+
}
47+
48+
public static Builder builder() {
49+
return new Builder();
50+
}
51+
52+
@Override
53+
public Builder toBuilder() {
54+
return new Builder(attributes);
55+
}
56+
57+
@Override
58+
public boolean equals(Object o) {
59+
if (this == o) {
60+
return true;
61+
}
62+
63+
if (o == null || getClass() != o.getClass()) {
64+
return false;
65+
}
66+
67+
SdkHttpExecutionAttributes that = (SdkHttpExecutionAttributes) o;
68+
69+
return Objects.equals(attributes, that.attributes);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
return attributes.hashCode();
75+
}
76+
77+
public static final class Builder implements CopyableBuilder<SdkHttpExecutionAttributes.Builder, SdkHttpExecutionAttributes> {
78+
private AttributeMap.Builder sdkHttpExecutionAttributes = AttributeMap.builder();
79+
80+
private Builder(AttributeMap attributes) {
81+
sdkHttpExecutionAttributes = attributes.toBuilder();
82+
}
83+
84+
private Builder() {
85+
}
86+
87+
/**
88+
* Add a mapping between the provided key and value.
89+
*/
90+
public <T> SdkHttpExecutionAttributes.Builder put(SdkHttpExecutionAttribute<T> key, T value) {
91+
Validate.notNull(key, "Key to set must not be null.");
92+
sdkHttpExecutionAttributes.put(key, value);
93+
return this;
94+
}
95+
96+
/**
97+
* Adds all the attributes from the map provided.
98+
*/
99+
public SdkHttpExecutionAttributes.Builder putAll(Map<? extends SdkHttpExecutionAttribute<?>, ?> attributes) {
100+
sdkHttpExecutionAttributes.putAll(attributes);
101+
return this;
102+
}
103+
104+
@Override
105+
public SdkHttpExecutionAttributes build() {
106+
return new SdkHttpExecutionAttributes(this);
107+
}
108+
}
109+
}

http-client-spi/src/main/java/software/amazon/awssdk/http/async/AsyncExecuteRequest.java

+46
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717

1818
import java.util.Optional;
1919
import software.amazon.awssdk.annotations.SdkPublicApi;
20+
import software.amazon.awssdk.http.SdkHttpExecutionAttribute;
21+
import software.amazon.awssdk.http.SdkHttpExecutionAttributes;
2022
import software.amazon.awssdk.http.SdkHttpRequest;
2123
import software.amazon.awssdk.metrics.MetricCollector;
24+
import software.amazon.awssdk.utils.Validate;
2225

2326
/**
2427
* Request object containing the parameters necessary to make an asynchronous HTTP request.
@@ -32,13 +35,15 @@ public final class AsyncExecuteRequest {
3235
private final SdkAsyncHttpResponseHandler responseHandler;
3336
private final MetricCollector metricCollector;
3437
private final boolean isFullDuplex;
38+
private final SdkHttpExecutionAttributes sdkHttpExecutionAttributes;
3539

3640
private AsyncExecuteRequest(BuilderImpl builder) {
3741
this.request = builder.request;
3842
this.requestContentPublisher = builder.requestContentPublisher;
3943
this.responseHandler = builder.responseHandler;
4044
this.metricCollector = builder.metricCollector;
4145
this.isFullDuplex = builder.isFullDuplex;
46+
this.sdkHttpExecutionAttributes = builder.executionAttributesBuilder.build();
4247
}
4348

4449
/**
@@ -76,6 +81,13 @@ public boolean fullDuplex() {
7681
return isFullDuplex;
7782
}
7883

84+
/**
85+
* @return the SDK HTTP execution attributes associated with this request
86+
*/
87+
public SdkHttpExecutionAttributes httpExecutionAttributes() {
88+
return sdkHttpExecutionAttributes;
89+
}
90+
7991
public static Builder builder() {
8092
return new BuilderImpl();
8193
}
@@ -125,6 +137,25 @@ public interface Builder {
125137
*/
126138
Builder fullDuplex(boolean fullDuplex);
127139

140+
/**
141+
* Put an HTTP execution attribute into to the collection of HTTP execution attributes for this request
142+
*
143+
* @param attribute The execution attribute object
144+
* @param value The value of the execution attribute.
145+
*/
146+
<T> Builder putHttpExecutionAttribute(SdkHttpExecutionAttribute<T> attribute, T value);
147+
148+
/**
149+
* Sets the additional HTTP execution attributes collection for this request.
150+
* <p>
151+
* This will override the attributes configured through
152+
* {@link #putHttpExecutionAttribute(SdkHttpExecutionAttribute, Object)}
153+
*
154+
* @param executionAttributes Execution attributes map for this request.
155+
* @return This object for method chaining.
156+
*/
157+
Builder httpExecutionAttributes(SdkHttpExecutionAttributes executionAttributes);
158+
128159
AsyncExecuteRequest build();
129160
}
130161

@@ -134,6 +165,7 @@ private static class BuilderImpl implements Builder {
134165
private SdkAsyncHttpResponseHandler responseHandler;
135166
private MetricCollector metricCollector;
136167
private boolean isFullDuplex;
168+
private SdkHttpExecutionAttributes.Builder executionAttributesBuilder = SdkHttpExecutionAttributes.builder();
137169

138170
@Override
139171
public Builder request(SdkHttpRequest request) {
@@ -165,6 +197,20 @@ public Builder fullDuplex(boolean fullDuplex) {
165197
return this;
166198
}
167199

200+
@Override
201+
public <T> Builder putHttpExecutionAttribute(SdkHttpExecutionAttribute<T> attribute, T value) {
202+
this.executionAttributesBuilder.put(attribute, value);
203+
return this;
204+
}
205+
206+
@Override
207+
public Builder httpExecutionAttributes(SdkHttpExecutionAttributes executionAttributes) {
208+
Validate.paramNotNull(executionAttributes, "executionAttributes");
209+
this.executionAttributesBuilder = executionAttributes.toBuilder();
210+
return this;
211+
}
212+
213+
168214
@Override
169215
public AsyncExecuteRequest build() {
170216
return new AsyncExecuteRequest(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
19+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
20+
21+
import nl.jqno.equalsverifier.EqualsVerifier;
22+
import org.junit.jupiter.api.Test;
23+
24+
class SdkHttpExecutionAttributesTest {
25+
26+
@Test
27+
void equalsAndHashcode() {
28+
EqualsVerifier.forClass(SdkHttpExecutionAttributes.class)
29+
.withNonnullFields("attributes")
30+
.verify();
31+
}
32+
33+
@Test
34+
void getAttribute_shouldReturnCorrectValue() {
35+
SdkHttpExecutionAttributes attributes = SdkHttpExecutionAttributes.builder()
36+
.put(TestExecutionAttribute.TEST_KEY_FOO, "test")
37+
.build();
38+
assertThat(attributes.getAttribute(TestExecutionAttribute.TEST_KEY_FOO)).isEqualTo("test");
39+
}
40+
41+
private static final class TestExecutionAttribute<T> extends SdkHttpExecutionAttribute<T> {
42+
43+
private static final TestExecutionAttribute<String> TEST_KEY_FOO = new TestExecutionAttribute<>(String.class);
44+
45+
private TestExecutionAttribute(Class valueType) {
46+
super(valueType);
47+
}
48+
}
49+
}

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<rxjava.version>2.2.21</rxjava.version>
115115
<commons-codec.verion>1.10</commons-codec.verion>
116116
<jmh.version>1.29</jmh.version>
117-
<awscrt.version>0.15.8</awscrt.version>
117+
<awscrt.version>0.15.15</awscrt.version>
118118

119119
<!--Test dependencies -->
120120
<junit5.version>5.8.1</junit5.version>

services-custom/s3-transfer-manager/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@
101101
<artifactId>aws-core</artifactId>
102102
<version>${awsjavasdk.version}</version>
103103
</dependency>
104-
<dependency>
105-
<groupId>software.amazon.awssdk</groupId>
106-
<artifactId>metrics-spi</artifactId>
107-
<version>${awsjavasdk.version}</version>
108-
</dependency>
109104
<dependency>
110105
<groupId>software.amazon.awssdk</groupId>
111106
<artifactId>service-test-utils</artifactId>

0 commit comments

Comments
 (0)