Skip to content

Commit 892f924

Browse files
committed
Improve Java HTTP client integration
Use buffers as-is without copying, add support for direct buffers to Jackson codec, improve HTTP header wrapper to use underlying data more, improve how we send data to Java client by adding a small adapter to avoid double-wrapping the publisher
1 parent 8173842 commit 892f924

21 files changed

Lines changed: 523 additions & 388 deletions

File tree

aws/client/aws-client-awsjson/src/main/java/software/amazon/smithy/java/aws/client/awsjson/AwsJsonProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ private EventDecoderFactory<AwsEventFrame> getEventDecoderFactory(ApiOperation<?
141141
private static DataStream bodyDataStream(HttpResponse response) {
142142
var contentType = response.headers().contentType();
143143
var contentLength = response.headers().contentLength();
144-
return DataStream.withMetadata(response.body(), contentType, contentLength, null);
144+
return DataStream.withMetadata(response.body(), contentType, contentLength == null ? -1 : contentLength);
145145
}
146146
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.java.client.http;
7+
8+
import java.net.http.HttpRequest;
9+
import java.nio.ByteBuffer;
10+
import java.util.concurrent.Flow;
11+
import software.amazon.smithy.java.io.datastream.DataStream;
12+
13+
/**
14+
* Adapts a Smithy {@link DataStream} to the JDK HttpClient's {@link HttpRequest.BodyPublisher} contract.
15+
*/
16+
final class DataStreamBodyPublisher implements HttpRequest.BodyPublisher {
17+
private final DataStream dataStream;
18+
19+
DataStreamBodyPublisher(DataStream dataStream) {
20+
this.dataStream = dataStream;
21+
}
22+
23+
@Override
24+
public long contentLength() {
25+
return dataStream.contentLength();
26+
}
27+
28+
@Override
29+
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) {
30+
dataStream.subscribe(subscriber);
31+
}
32+
}

client/client-http/src/main/java/software/amazon/smithy/java/client/http/JavaHttpClientReplayableByteBufferPublisher.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

client/client-http/src/main/java/software/amazon/smithy/java/client/http/JavaHttpClientSmallBodySubscriber.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)