Skip to content

Commit 6e9939f

Browse files
authored
Phase 2 , getting Apache 5 compilation and Junit ready along with clearing Checkstyles and spotbug issues (#6100)
* Phase 2 , getting Apache 5 compilation and Junit ready along with clearing Checkstyles and spotbug issues * Handle comments from review * Handle comments from Zoe
1 parent 5092cc4 commit 6e9939f

33 files changed

+502
-605
lines changed

build-tools/src/main/resources/software/amazon/awssdk/spotbugs-suppressions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
<Class name="software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap"/>
286286
<Class name="software.amazon.awssdk.http.nio.netty.internal.http2.FlushOnReadHandler"/>
287287
<Class name="software.amazon.awssdk.http.apache.internal.conn.IdleConnectionReaper"/>
288+
<Class name="software.amazon.awssdk.http.apache5.internal.conn.IdleConnectionReaper"/>
288289
<Class name="software.amazon.awssdk.eventnotifications.s3.internal.DefaultS3EventNotificationWriter"/>
289290
<Class name="software.amazon.awssdk.policybuilder.iam.internal.DefaultIamPolicyWriter"/>
290291
</Or>
@@ -337,6 +338,7 @@
337338
<Class name="~software\.amazon\.awssdk\.utils\.CompletableFutureUtils" />
338339
<Class name="~software\.amazon\.awssdk\.metrics\.publishers\.cloudwatch\.CloudWatchMetricPublisher" />
339340
<Class name="~software\.amazon\.awssdk\.http\.apache\.internal\.conn\.IdleConnectionReaper\$ReaperTask" />
341+
<Class name="~software\.amazon\.awssdk\.http\.apache5\.internal\.conn\.IdleConnectionReaper\$ReaperTask" />
340342
<Class name="~software\.amazon\.awssdk\.core\.internal\.retry\.RateLimitingTokenBucket" />
341343
<Class name="~software\.amazon\.awssdk\.core\.internal\.waiters\.WaiterExecutor" />
342344
<Class name="~software\.amazon\.awssdk\.regions\.internal\.util\.EC2MetadataUtils" />

http-clients/apache5-client/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,51 @@
4343
<artifactId>httpcore5</artifactId>
4444
<version>5.3.4</version>
4545
</dependency>
46+
<dependency>
47+
<groupId>software.amazon.awssdk</groupId>
48+
<artifactId>utils</artifactId>
49+
<version>${awsjavasdk.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>software.amazon.awssdk</groupId>
53+
<artifactId>metrics-spi</artifactId>
54+
<version>${awsjavasdk.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>software.amazon.awssdk</groupId>
58+
<artifactId>annotations</artifactId>
59+
<version>${awsjavasdk.version}</version>
60+
</dependency>
61+
4662
<dependency>
4763
<groupId>software.amazon.awssdk</groupId>
4864
<artifactId>http-client-tests</artifactId>
4965
<version>${awsjavasdk.version}</version>
5066
<scope>test</scope>
5167
</dependency>
68+
<!-- Added for WIRE logging details while testing-->
69+
<dependency>
70+
<groupId>org.apache.logging.log4j</groupId>
71+
<artifactId>log4j-api</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.apache.logging.log4j</groupId>
76+
<artifactId>log4j-core</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.apache.logging.log4j</groupId>
81+
<artifactId>log4j-slf4j-impl</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.slf4j</groupId>
86+
<artifactId>jcl-over-slf4j</artifactId>
87+
<scope>test</scope>
88+
<version>${slf4j.version}</version>
89+
</dependency>
90+
5291
<dependency>
5392
<groupId>org.junit.jupiter</groupId>
5493
<artifactId>junit-jupiter</artifactId>

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java

Lines changed: 67 additions & 56 deletions
Large diffs are not rendered by default.

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/RepeatableInputStreamRequestEntity.java

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.io.IOException;
2323
import java.io.InputStream;
2424
import java.io.OutputStream;
25-
import java.util.Optional;
25+
import org.apache.hc.core5.http.ContentType;
2626
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
2727
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
2828
import software.amazon.awssdk.annotations.SdkInternalApi;
@@ -47,10 +47,6 @@ public class RepeatableInputStreamRequestEntity extends BasicHttpEntity {
4747
*/
4848
private boolean firstAttempt = true;
4949

50-
/**
51-
* True if the "Transfer-Encoding:chunked" header is present
52-
*/
53-
private boolean isChunked;
5450

5551
/**
5652
* The underlying InputStreamEntity being delegated to
@@ -80,33 +76,32 @@ public class RepeatableInputStreamRequestEntity extends BasicHttpEntity {
8076
* @param request The details of the request being written out (content type,
8177
* content length, and content).
8278
*/
83-
public RepeatableInputStreamRequestEntity(final HttpExecuteRequest request) {
84-
isChunked = request.httpRequest().matchingHeaders(TRANSFER_ENCODING).contains(CHUNKED);
85-
setChunked(isChunked);
86-
87-
/*
88-
* If we don't specify a content length when we instantiate our
89-
* InputStreamRequestEntity, then HttpClient will attempt to
90-
* buffer the entire stream contents into memory to determine
91-
* the content length.
92-
*/
93-
long contentLength = request.httpRequest().firstMatchingHeader("Content-Length")
94-
.map(this::parseContentLength)
95-
.orElse(-1L);
96-
97-
content = getContent(request.contentStreamProvider());
98-
// TODO v2 MetricInputStreamEntity
99-
inputStreamRequestEntity = new InputStreamEntity(content, contentLength);
100-
setContent(content);
101-
setContentLength(contentLength);
102-
103-
request.httpRequest().firstMatchingHeader("Content-Type").ifPresent(contentType -> {
104-
inputStreamRequestEntity.setContentType(contentType);
105-
setContentType(contentType);
106-
});
79+
public RepeatableInputStreamRequestEntity(HttpExecuteRequest request) {
80+
super(request.contentStreamProvider().map(ContentStreamProvider::newStream)
81+
.orElseGet(() -> new ByteArrayInputStream(new byte[0])),
82+
getContentLengthFromRequest(request),
83+
getContentTypeFromRequest(request),
84+
null,
85+
request.httpRequest().matchingHeaders(TRANSFER_ENCODING).contains(CHUNKED));
86+
InputStream inputStream = getContent();
87+
this.content = inputStream;
88+
inputStreamRequestEntity = new InputStreamEntity(inputStream,
89+
getContentLengthFromRequest(request),
90+
getContentTypeFromRequest(request));
91+
}
92+
93+
94+
private static ContentType getContentTypeFromRequest(HttpExecuteRequest request) {
95+
return request.httpRequest().firstMatchingHeader("Content-Type").map(ContentType::create).orElse(null);
10796
}
10897

109-
private long parseContentLength(String contentLength) {
98+
private static Long getContentLengthFromRequest(HttpExecuteRequest request) {
99+
return request.httpRequest().firstMatchingHeader("Content-Length")
100+
.map(RepeatableInputStreamRequestEntity::parseContentLength)
101+
.orElse(-1L);
102+
}
103+
104+
private static long parseContentLength(String contentLength) {
110105
try {
111106
return Long.parseLong(contentLength);
112107
} catch (NumberFormatException nfe) {
@@ -115,25 +110,9 @@ private long parseContentLength(String contentLength) {
115110
}
116111
}
117112

118-
/**
119-
* @return The request content input stream or an empty input stream if there is no content.
120-
*/
121-
private InputStream getContent(Optional<ContentStreamProvider> contentStreamProvider) {
122-
return contentStreamProvider.map(ContentStreamProvider::newStream).orElseGet(() -> new ByteArrayInputStream(new byte[0]));
123-
}
124-
125-
@Override
126-
public boolean isChunked() {
127-
return isChunked;
128-
}
129113

130-
/**
131-
* Returns true if the underlying InputStream supports marking/reseting or
132-
* if the underlying InputStreamRequestEntity is repeatable.
133-
*/
134-
@Override
135-
public boolean isRepeatable() {
136-
return content.markSupported() || inputStreamRequestEntity.isRepeatable();
114+
private boolean isRepeatableStream() {
115+
return getContent().markSupported() || inputStreamRequestEntity.isRepeatable();
137116
}
138117

139118
/**
@@ -149,7 +128,8 @@ public boolean isRepeatable() {
149128
@Override
150129
public void writeTo(OutputStream output) throws IOException {
151130
try {
152-
if (!firstAttempt && isRepeatable()) {
131+
if (!firstAttempt && isRepeatableStream()) {
132+
153133
content.reset();
154134
}
155135

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/SdkProxyRoutePlanner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner;
2323
import org.apache.hc.core5.http.HttpException;
2424
import org.apache.hc.core5.http.HttpHost;
25-
import org.apache.hc.core5.http.HttpRequest;
2625
import org.apache.hc.core5.http.protocol.HttpContext;
2726
import software.amazon.awssdk.annotations.SdkInternalApi;
2827

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/conn/ClientConnectionManagerFactory.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
package software.amazon.awssdk.http.apache5.internal.conn;
1717

1818
import java.io.IOException;
19-
import java.util.concurrent.TimeUnit;
20-
import org.apache.hc.client5.http.ConnectionRequest;
2119
import org.apache.hc.client5.http.HttpRoute;
20+
import org.apache.hc.client5.http.io.ConnectionEndpoint;
2221
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
23-
import org.apache.hc.core5.http.io.HttpClientConnection;
22+
import org.apache.hc.client5.http.io.LeaseRequest;
2423
import org.apache.hc.core5.http.protocol.HttpContext;
24+
import org.apache.hc.core5.io.CloseMode;
25+
import org.apache.hc.core5.util.TimeValue;
26+
import org.apache.hc.core5.util.Timeout;
2527
import software.amazon.awssdk.annotations.SdkInternalApi;
2628

2729
@SdkInternalApi
2830
public final class ClientConnectionManagerFactory {
2931

32+
3033
private ClientConnectionManagerFactory() {
3134
}
3235

@@ -44,7 +47,7 @@ public static HttpClientConnectionManager wrap(HttpClientConnectionManager orig)
4447
}
4548

4649
/**
47-
* Further wraps {@link ConnectionRequest} to capture performance metrics.
50+
* Further wraps {@link LeaseRequest} to capture performance metrics.
4851
*/
4952
private static class InstrumentedHttpClientConnectionManager extends DelegatingHttpClientConnectionManager {
5053

@@ -53,10 +56,12 @@ private InstrumentedHttpClientConnectionManager(HttpClientConnectionManager dele
5356
}
5457

5558
@Override
56-
public ConnectionRequest requestConnection(HttpRoute route, Object state) {
57-
ConnectionRequest connectionRequest = super.requestConnection(route, state);
59+
public LeaseRequest lease(String id, HttpRoute route, Timeout requestTimeout, Object state) {
60+
LeaseRequest connectionRequest = super.lease(id, route, requestTimeout, state);
5861
return ClientConnectionRequestFactory.wrap(connectionRequest);
5962
}
63+
64+
6065
}
6166

6267
/**
@@ -71,44 +76,37 @@ protected DelegatingHttpClientConnectionManager(HttpClientConnectionManager dele
7176
}
7277

7378
@Override
74-
public ConnectionRequest requestConnection(HttpRoute route, Object state) {
75-
return delegate.requestConnection(route, state);
79+
public LeaseRequest lease(String id, HttpRoute route, Timeout requestTimeout, Object state) {
80+
return delegate.lease(id, route, requestTimeout, state);
7681
}
7782

7883
@Override
79-
public void releaseConnection(HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit) {
80-
delegate.releaseConnection(conn, newState, validDuration, timeUnit);
81-
}
84+
public void release(ConnectionEndpoint endpoint, Object newState, TimeValue validDuration) {
85+
delegate.release(endpoint, newState, validDuration);
8286

83-
@Override
84-
public void connect(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context)
85-
throws IOException {
86-
delegate.connect(conn, route, connectTimeout, context);
8787
}
8888

8989
@Override
90-
public void upgrade(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException {
91-
delegate.upgrade(conn, route, context);
92-
}
90+
public void connect(ConnectionEndpoint endpoint, TimeValue connectTimeout, HttpContext context) throws IOException {
91+
delegate.connect(endpoint, connectTimeout, context);
9392

94-
@Override
95-
public void routeComplete(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException {
96-
delegate.routeComplete(conn, route, context);
9793
}
9894

9995
@Override
100-
public void closeIdleConnections(long idletime, TimeUnit timeUnit) {
101-
delegate.closeIdleConnections(idletime, timeUnit);
96+
public void upgrade(ConnectionEndpoint endpoint, HttpContext context) throws IOException {
97+
delegate.upgrade(endpoint, context);
10298
}
10399

104100
@Override
105-
public void closeExpiredConnections() {
106-
delegate.closeExpiredConnections();
101+
public void close(CloseMode closeMode) {
102+
delegate.close(closeMode);
103+
107104
}
108105

109106
@Override
110-
public void shutdown() {
111-
delegate.shutdown();
107+
public void close() throws IOException {
108+
delegate.close();
109+
112110
}
113111
}
114112
}

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/conn/ClientConnectionRequestFactory.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import java.time.Duration;
2020
import java.time.Instant;
2121
import java.util.concurrent.ExecutionException;
22-
import java.util.concurrent.TimeUnit;
23-
import org.apache.hc.client5.http.ConnectionPoolTimeoutException;
24-
import org.apache.hc.client5.http.ConnectionRequest;
25-
import org.apache.hc.core5.http.io.HttpClientConnection;
22+
import java.util.concurrent.TimeoutException;
23+
import org.apache.hc.client5.http.io.ConnectionEndpoint;
24+
import org.apache.hc.client5.http.io.LeaseRequest;
25+
import org.apache.hc.core5.util.Timeout;
2626
import software.amazon.awssdk.annotations.SdkInternalApi;
2727
import software.amazon.awssdk.http.HttpMetric;
2828
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
@@ -40,61 +40,61 @@ private ClientConnectionRequestFactory() {
4040
}
4141

4242
/**
43-
* Returns a wrapped instance of {@link ConnectionRequest}
43+
* Returns a wrapped instance of {@link LeaseRequest}
4444
* to capture the necessary performance metrics.
4545
*
4646
* @param orig the target instance to be wrapped
4747
*/
48-
static ConnectionRequest wrap(ConnectionRequest orig) {
48+
static LeaseRequest wrap(LeaseRequest orig) {
4949
if (orig instanceof DelegatingConnectionRequest) {
5050
throw new IllegalArgumentException();
5151
}
5252
return new InstrumentedConnectionRequest(orig);
5353
}
5454

5555
/**
56-
* Measures the latency of {@link ConnectionRequest#get(long, TimeUnit)}.
56+
* Measures the latency of {@link LeaseRequest#get(Timeout)}.
5757
*/
5858
private static class InstrumentedConnectionRequest extends DelegatingConnectionRequest {
5959

60-
private InstrumentedConnectionRequest(ConnectionRequest delegate) {
60+
private InstrumentedConnectionRequest(LeaseRequest delegate) {
6161
super(delegate);
6262
}
6363

64+
6465
@Override
65-
public HttpClientConnection get(long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
66-
ConnectionPoolTimeoutException {
66+
public ConnectionEndpoint get(Timeout timeout) throws InterruptedException, ExecutionException, TimeoutException {
6767
Instant startTime = Instant.now();
6868
try {
69-
return super.get(timeout, timeUnit);
69+
return super.get(timeout);
7070
} finally {
7171
Duration elapsed = Duration.between(startTime, Instant.now());
7272
MetricCollector metricCollector = THREAD_LOCAL_REQUEST_METRIC_COLLECTOR.get();
7373
metricCollector.reportMetric(HttpMetric.CONCURRENCY_ACQUIRE_DURATION, elapsed);
7474
}
7575
}
76+
7677
}
7778

7879
/**
79-
* Delegates all methods to {@link ConnectionRequest}. Subclasses can override select methods to change behavior.
80+
* Delegates all methods to {@link LeaseRequest}. Subclasses can override select methods to change behavior.
8081
*/
81-
private static class DelegatingConnectionRequest implements ConnectionRequest {
82+
private static class DelegatingConnectionRequest implements LeaseRequest {
8283

83-
private final ConnectionRequest delegate;
84+
private final LeaseRequest delegate;
8485

85-
private DelegatingConnectionRequest(ConnectionRequest delegate) {
86+
private DelegatingConnectionRequest(LeaseRequest delegate) {
8687
this.delegate = delegate;
8788
}
8889

8990
@Override
90-
public HttpClientConnection get(long timeout, TimeUnit timeUnit)
91-
throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
92-
return delegate.get(timeout, timeUnit);
91+
public boolean cancel() {
92+
return delegate.cancel();
9393
}
9494

9595
@Override
96-
public boolean cancel() {
97-
return delegate.cancel();
96+
public ConnectionEndpoint get(Timeout timeout) throws InterruptedException, ExecutionException, TimeoutException {
97+
return delegate.get(timeout);
9898
}
9999
}
100100
}

0 commit comments

Comments
 (0)