Skip to content

Commit 3339700

Browse files
committed
Revert "Move CrtRequestBodyAdapter to crt-core"
This reverts commit f5876e0.
1 parent f5876e0 commit 3339700

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

core/http-auth-aws/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@
6969
<artifactId>checksums</artifactId>
7070
<version>${awsjavasdk.version}</version>
7171
</dependency>
72-
<dependency>
73-
<groupId>software.amazon.awssdk</groupId>
74-
<artifactId>crt-core</artifactId>
75-
<version>${awsjavasdk.version}</version>
76-
<optional>true</optional>
77-
</dependency>
7872
<dependency>
7973
<groupId>software.amazon.awssdk</groupId>
8074
<artifactId>http-auth-aws-crt</artifactId>

core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtRequestBodyAdapter.java renamed to core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/crt/internal/signer/CrtRequestBodyAdapter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.crtcore;
16+
package software.amazon.awssdk.http.auth.aws.crt.internal.signer;
1717

1818
import java.nio.ByteBuffer;
1919
import org.reactivestreams.Publisher;
@@ -29,14 +29,10 @@ public final class CrtRequestBodyAdapter implements HttpRequestBodyStream {
2929
private final long contentLength;
3030
private ByteBufferStoringSubscriber requestBodySubscriber;
3131

32-
public CrtRequestBodyAdapter(Publisher<ByteBuffer> requestPublisher, long contentLength, long readLimit) {
32+
public CrtRequestBodyAdapter(Publisher<ByteBuffer> requestPublisher, long contentLength) {
3333
this.requestPublisher = requestPublisher;
3434
this.contentLength = contentLength;
35-
this.requestBodySubscriber = new ByteBufferStoringSubscriber(readLimit);
36-
}
37-
38-
public CrtRequestBodyAdapter(Publisher<ByteBuffer> requestPublisher, long contentLength) {
39-
this(requestPublisher, contentLength, BUFFER_SIZE);
35+
this.requestBodySubscriber = new ByteBufferStoringSubscriber(BUFFER_SIZE);
4036
}
4137

4238
@Override

core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/crt/internal/util/CrtHttpRequestConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import software.amazon.awssdk.crt.http.HttpHeader;
2929
import software.amazon.awssdk.crt.http.HttpRequest;
3030
import software.amazon.awssdk.crt.http.HttpRequestBodyStream;
31-
import software.amazon.awssdk.crtcore.CrtRequestBodyAdapter;
3231
import software.amazon.awssdk.http.ContentStreamProvider;
3332
import software.amazon.awssdk.http.SdkHttpRequest;
3433
import software.amazon.awssdk.http.auth.aws.crt.internal.io.CrtInputStream;
34+
import software.amazon.awssdk.http.auth.aws.crt.internal.signer.CrtRequestBodyAdapter;
3535
import software.amazon.awssdk.utils.StringUtils;
3636
import software.amazon.awssdk.utils.http.SdkHttpUtils;
3737
import software.amazon.awssdk.utils.uri.SdkUri;

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/request/CrtRequestAdapter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
import software.amazon.awssdk.annotations.SdkInternalApi;
2323
import software.amazon.awssdk.crt.http.HttpHeader;
2424
import software.amazon.awssdk.crt.http.HttpRequest;
25-
import software.amazon.awssdk.crtcore.CrtRequestBodyAdapter;
2625
import software.amazon.awssdk.http.Header;
2726
import software.amazon.awssdk.http.HttpExecuteRequest;
2827
import software.amazon.awssdk.http.SdkHttpRequest;
2928
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
30-
import software.amazon.awssdk.http.async.SdkHttpContentPublisher;
3129
import software.amazon.awssdk.http.crt.internal.CrtAsyncRequestContext;
3230
import software.amazon.awssdk.http.crt.internal.CrtRequestContext;
3331

@@ -52,13 +50,10 @@ public static HttpRequest toAsyncCrtRequest(CrtAsyncRequestContext request) {
5250

5351
HttpHeader[] crtHeaderArray = asArray(createAsyncHttpHeaderList(sdkRequest.getUri(), sdkExecuteRequest));
5452

55-
SdkHttpContentPublisher contentPublisher = sdkExecuteRequest.requestContentPublisher();
56-
5753
return new HttpRequest(method,
5854
encodedPath + encodedQueryString,
5955
crtHeaderArray,
60-
new CrtRequestBodyAdapter(contentPublisher,
61-
contentPublisher.contentLength().orElse(0L),
56+
new CrtRequestBodyAdapter(sdkExecuteRequest.requestContentPublisher(),
6257
request.readBufferSize()));
6358
}
6459

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.crt.internal.request;
17+
18+
import java.nio.ByteBuffer;
19+
import java.util.concurrent.atomic.AtomicBoolean;
20+
import software.amazon.awssdk.annotations.SdkInternalApi;
21+
import software.amazon.awssdk.crt.http.HttpRequestBodyStream;
22+
import software.amazon.awssdk.http.async.SdkHttpContentPublisher;
23+
import software.amazon.awssdk.utils.async.ByteBufferStoringSubscriber;
24+
import software.amazon.awssdk.utils.async.ByteBufferStoringSubscriber.TransferResult;
25+
26+
@SdkInternalApi
27+
final class CrtRequestBodyAdapter implements HttpRequestBodyStream {
28+
private final SdkHttpContentPublisher requestPublisher;
29+
private final ByteBufferStoringSubscriber requestBodySubscriber;
30+
private final AtomicBoolean subscribed = new AtomicBoolean(false);
31+
32+
CrtRequestBodyAdapter(SdkHttpContentPublisher requestPublisher, long readLimit) {
33+
this.requestPublisher = requestPublisher;
34+
this.requestBodySubscriber = new ByteBufferStoringSubscriber(readLimit);
35+
}
36+
37+
@Override
38+
public boolean sendRequestBody(ByteBuffer bodyBytesOut) {
39+
if (subscribed.compareAndSet(false, true)) {
40+
requestPublisher.subscribe(requestBodySubscriber);
41+
}
42+
43+
return requestBodySubscriber.transferTo(bodyBytesOut) == TransferResult.END_OF_STREAM;
44+
}
45+
46+
@Override
47+
public long getLength() {
48+
return requestPublisher.contentLength().orElse(0L);
49+
}
50+
}

0 commit comments

Comments
 (0)