From 6badfd5cd61d6776e78fd415e3292418644989cd Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Mon, 12 Jun 2023 12:08:19 +0200 Subject: [PATCH 01/32] Apply patch received from Christoph --- pom.xml | 2 +- .../zalando/riptide/capture/CaptureTest.java | 6 +- .../riptide/chaos/ErrorResponseInjection.java | 5 +- .../riptide/chaos/ChaosPluginTest.java | 34 +++----- riptide-compatibility/pom.xml | 11 +-- ...tMessageAsyncClientHttpRequestAdapter.java | 43 ---------- ...OutputMessageClientHttpRequestAdapter.java | 6 -- ...sageAsyncClientHttpRequestAdapterTest.java | 37 -------- .../RequestCompressionPluginTest.java | 10 +-- riptide-core/pom.xml | 18 ++-- .../zalando/riptide/DefaultHttpBuilder.java | 7 -- .../zalando/riptide/DefaultMessageReader.java | 4 +- .../riptide/ForwardingClientHttpResponse.java | 6 +- .../main/java/org/zalando/riptide/Http.java | 2 - .../riptide/HttpResponseException.java | 2 +- .../org/zalando/riptide/NonBlockingIO.java | 38 -------- .../org/zalando/riptide/SeriesNavigator.java | 3 +- .../zalando/riptide/StatusCodeNavigator.java | 2 +- .../org/zalando/riptide/StatusNavigator.java | 2 +- .../java/org/zalando/riptide/CallTest.java | 7 +- .../ForwardingClientHttpResponseTest.java | 5 +- .../riptide/HttpResponseExceptionTest.java | 2 + .../org/zalando/riptide/HttpStatuses.java | 5 +- .../java/org/zalando/riptide/NIOTest.java | 86 ------------------- .../zalando/riptide/NestedDispatchTest.java | 27 ++---- .../org/zalando/riptide/RequestUriTest.java | 8 +- .../java/org/zalando/riptide/RouteTest.java | 15 +--- .../zalando/riptide/SeriesDispatchTest.java | 8 +- .../riptide/StatusCodeDispatchTest.java | 2 +- .../zalando/riptide/ThreadAffinityTest.java | 40 +-------- .../FailsafePluginBackupRequestTest.java | 8 +- .../FailsafePluginCircuitBreakerTest.java | 18 ++-- .../failsafe/FailsafePluginNoPolicyTest.java | 18 ++-- .../failsafe/FailsafePluginRetriesTest.java | 24 +++--- .../FailsafePluginRetryListenerTest.java | 14 +-- .../failsafe/FailsafePluginTimeoutTest.java | 8 +- .../RateLimitResetDelayFunctionTest.java | 18 ++-- .../failsafe/RetryAfterDelayFunctionTest.java | 18 ++-- riptide-httpclient/pom.xml | 11 +-- .../ApacheClientHttpRequestFactory.java | 21 +---- .../httpclient/ApacheClientHttpResponse.java | 33 +++---- .../BufferingApacheClientHttpRequest.java | 42 +++++---- .../zalando/riptide/httpclient/Headers.java | 2 +- .../StreamingApacheClientHttpRequest.java | 68 +++++++-------- .../metrics/HttpConnectionPoolMetrics.java | 4 +- ...actApacheClientHttpRequestFactoryTest.java | 32 +++---- .../ApacheClientHttpResponseBodyTest.java | 29 ++----- .../StreamingApacheClientHttpRequestTest.java | 22 ++--- .../HttpConnectionPoolMetricsTest.java | 12 ++- .../DefaultIdempotencyDetector.java | 19 ++-- .../idempotency/IdempotencyPredicateTest.java | 30 +++++-- .../riptide/logbook/RemoteResponse.java | 6 +- riptide-micrometer/pom.xml | 11 +-- .../micrometer/MicrometerPluginTest.java | 17 ++-- riptide-opentelemetry/pom.xml | 4 +- .../OpenTelemetryPluginTest.java | 29 ++----- riptide-opentracing/pom.xml | 11 +-- .../opentracing/OpenTracingPluginTest.java | 22 ++--- riptide-parent/pom.xml | 20 ++--- .../soap/SOAPFaultHttpMessageConverter.java | 10 +-- .../soap/SOAPHttpMessageConverter.java | 23 +++-- .../org/zalando/riptide/soap/SOAPRoute.java | 5 +- .../zalando/riptide/soap/HelloService.java | 6 +- .../riptide/soap/IllegalProtocolReadTest.java | 2 +- .../soap/IllegalProtocolWriteTest.java | 2 +- .../zalando/riptide/soap/InvalidSayHello.java | 3 +- .../riptide/soap/InvalidSayHelloResponse.java | 2 +- .../org/zalando/riptide/soap/SOAPTest.java | 8 +- .../org/zalando/riptide/soap/SayHello.java | 3 +- .../riptide/soap/SayHelloResponse.java | 5 +- riptide-spring-boot-autoconfigure/pom.xml | 16 ++-- .../DefaultRiptideRegistrar.java | 27 ++---- 72 files changed, 347 insertions(+), 779 deletions(-) delete mode 100644 riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapter.java delete mode 100644 riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapterTest.java delete mode 100644 riptide-core/src/main/java/org/zalando/riptide/NonBlockingIO.java delete mode 100644 riptide-core/src/test/java/org/zalando/riptide/NIOTest.java diff --git a/pom.xml b/pom.xml index 33152d7b0..fdf9ffb98 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ 17 17 - 5.3.27 + 6.0.9 diff --git a/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java b/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java index 4dd411075..a69ea7796 100644 --- a/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java +++ b/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java @@ -19,9 +19,7 @@ import java.util.concurrent.Executors; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.OK; @@ -122,7 +120,7 @@ void shouldNotAllowSecondCaptures() { } private void fail(final ClientHttpResponse response) throws IOException { - throw new AssertionError(response.getRawStatusCode()); + throw new AssertionError(response.getStatusCode().value()); } } diff --git a/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java b/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java index b26dc21a6..3657d9d54 100644 --- a/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java +++ b/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java @@ -5,6 +5,7 @@ import org.apiguardian.api.API; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.RequestExecution; @@ -39,9 +40,9 @@ public RequestExecution inject(final RequestExecution execution) { private ClientHttpResponse injectIfNecessary( final ClientHttpResponse response) throws IOException { - final HttpStatus statusCode = response.getStatusCode(); + final HttpStatusCode statusCode = response.getStatusCode(); - if (isError(statusCode)) { + if (statusCode.isError()) { // only inject error response if not failed already return response; } diff --git a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java index e3fdef4fa..9fa37ae15 100644 --- a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java +++ b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java @@ -2,9 +2,11 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -25,24 +27,14 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anEmptyMap; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.hamcrest.Matchers.oneOf; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; -import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; +import static org.springframework.http.HttpStatus.*; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.chaos.FailureInjection.composite; -import static org.zalando.riptide.chaos.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.chaos.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.chaos.MockWebServerUtil.verify; +import static org.zalando.riptide.chaos.MockWebServerUtil.*; final class ChaosPluginTest { @@ -53,8 +45,10 @@ final class ChaosPluginTest { private final Probability errorResponseProbability = mock(Probability.class); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(1500) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(1500)) + .build()) .build()) .build(); @@ -145,7 +139,7 @@ void shouldInjectErrorResponse() throws IOException { response.close(); assertThat(response.getStatusCode(), is(oneOf(INTERNAL_SERVER_ERROR, SERVICE_UNAVAILABLE))); - assertThat(response.getRawStatusCode(), is(oneOf(500, 503))); + assertThat(response.getStatusCode().value(), is(oneOf(500, 503))); assertThat(response.getStatusText(), is(oneOf("Internal Server Error", "Service Unavailable"))); assertThat(response.getHeaders(), is(anEmptyMap())); // TODO can we do better? verify(server, 1, "/foo"); @@ -215,7 +209,7 @@ void shouldInjectLatencyAndErrorResponse() throws IOException { final Instant end = clock.instant(); assertThat(Duration.between(start, end), is(greaterThanOrEqualTo(Duration.ofSeconds(1)))); - assertThat(response.getRawStatusCode(), is(oneOf(500, 503))); + assertThat(response.getStatusCode().value(), is(oneOf(500, 503))); verify(server, 1, "/foo"); } diff --git a/riptide-compatibility/pom.xml b/riptide-compatibility/pom.xml index 7dbb986b4..fcfa76c09 100644 --- a/riptide-compatibility/pom.xml +++ b/riptide-compatibility/pom.xml @@ -39,16 +39,9 @@ test - org.apache.httpcomponents - httpclient - 4.5.14 + org.apache.httpcomponents.client5 + httpclient5 test - - - commons-logging - commons-logging - - diff --git a/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapter.java b/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapter.java deleted file mode 100644 index 335feac75..000000000 --- a/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapter.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.zalando.riptide.compatibility; - -import lombok.AllArgsConstructor; -import lombok.experimental.Delegate; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpOutputMessage; -import org.springframework.http.client.AsyncClientHttpRequest; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.concurrent.ListenableFuture; - -import javax.annotation.Nonnull; -import java.net.URI; - -@AllArgsConstructor -final class HttpOutputMessageAsyncClientHttpRequestAdapter implements AsyncClientHttpRequest { - - @Delegate - private final HttpOutputMessage message; - - @Nonnull - @Override - public ListenableFuture executeAsync() { - throw new UnsupportedOperationException(); - } - - @Nonnull - @Override - public String getMethodValue() { - throw new UnsupportedOperationException(); - } - - @Override - public HttpMethod getMethod() { - throw new UnsupportedOperationException(); - } - - @Nonnull - @Override - public URI getURI() { - throw new UnsupportedOperationException(); - } - -} diff --git a/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageClientHttpRequestAdapter.java b/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageClientHttpRequestAdapter.java index 01ddb17d4..c92bd1b78 100644 --- a/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageClientHttpRequestAdapter.java +++ b/riptide-compatibility/src/main/java/org/zalando/riptide/compatibility/HttpOutputMessageClientHttpRequestAdapter.java @@ -22,12 +22,6 @@ public ClientHttpResponse execute() { throw new UnsupportedOperationException(); } - @Nonnull - @Override - public String getMethodValue() { - throw new UnsupportedOperationException(); - } - @Override public HttpMethod getMethod() { throw new UnsupportedOperationException(); diff --git a/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapterTest.java b/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapterTest.java deleted file mode 100644 index d3f90ce52..000000000 --- a/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOutputMessageAsyncClientHttpRequestAdapterTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.zalando.riptide.compatibility; - -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpOutputMessage; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; - -class HttpOutputMessageAsyncClientHttpRequestAdapterTest { - - private final HttpOutputMessage message = mock(HttpOutputMessage.class); - - // need concrete type here to see both getMethod and getMethodValue - private final HttpOutputMessageAsyncClientHttpRequestAdapter unit = - new HttpOutputMessageAsyncClientHttpRequestAdapter(message); - - @Test - void executeAsync() { - assertThrows(UnsupportedOperationException.class, unit::executeAsync); - } - - @Test - void getMethodValue() { - assertThrows(UnsupportedOperationException.class, unit::getMethodValue); - } - - @Test - void getMethod() { - assertThrows(UnsupportedOperationException.class, unit::getMethod); - } - - @Test - void getURI() { - assertThrows(UnsupportedOperationException.class, unit::getURI); - } - -} diff --git a/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java b/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java index c859b8d92..b4203394d 100644 --- a/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java +++ b/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java @@ -4,7 +4,7 @@ import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import okio.Buffer; -import org.apache.http.impl.client.HttpClients; +import org.apache.hc.client5.http.impl.classic.HttpClients; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.ParameterizedTest; @@ -31,14 +31,10 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static java.util.concurrent.Executors.newSingleThreadExecutor; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.HttpHeaders.CONTENT_ENCODING; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.compression.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.compression.MockWebServerUtil.getRecordedRequest; -import static org.zalando.riptide.compression.MockWebServerUtil.textMockResponse; +import static org.zalando.riptide.compression.MockWebServerUtil.*; class RequestCompressionPluginTest { diff --git a/riptide-core/pom.xml b/riptide-core/pom.xml index 5bda79408..fd026052f 100644 --- a/riptide-core/pom.xml +++ b/riptide-core/pom.xml @@ -48,16 +48,8 @@ test - org.apache.httpcomponents - httpasyncclient - 4.1.5 - test - - - commons-logging - commons-logging - - + org.apache.httpcomponents.client5 + httpclient5 io.netty @@ -66,9 +58,9 @@ test - javax.xml.bind - jaxb-api - 2.3.1 + jakarta.platform + jakarta.jakartaee-api + 9.1.0 test diff --git a/riptide-core/src/main/java/org/zalando/riptide/DefaultHttpBuilder.java b/riptide-core/src/main/java/org/zalando/riptide/DefaultHttpBuilder.java index 106baab64..623de6d52 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/DefaultHttpBuilder.java +++ b/riptide-core/src/main/java/org/zalando/riptide/DefaultHttpBuilder.java @@ -5,7 +5,6 @@ import lombok.With; import org.organicdesign.fp.collections.ImList; import org.organicdesign.fp.collections.PersistentVector; -import org.springframework.http.client.AsyncClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.client.RestTemplate; @@ -73,12 +72,6 @@ public ConfigurationStage requestFactory(final ClientHttpRequestFactory factory) return withIo(new BlockingIO(factory)); } - @Override - @SuppressWarnings("deprecation") - public ConfigurationStage asyncRequestFactory(final AsyncClientHttpRequestFactory factory) { - return withIo(new NonBlockingIO(factory)); - } - @Override public ConfigurationStage defaultConverters() { return converters(Converters.DEFAULT); diff --git a/riptide-core/src/main/java/org/zalando/riptide/DefaultMessageReader.java b/riptide-core/src/main/java/org/zalando/riptide/DefaultMessageReader.java index 378b4c091..47a5c84c6 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/DefaultMessageReader.java +++ b/riptide-core/src/main/java/org/zalando/riptide/DefaultMessageReader.java @@ -3,7 +3,7 @@ import com.google.common.reflect.TypeToken; import lombok.AllArgsConstructor; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; @@ -32,7 +32,7 @@ public I read(final TypeToken type, final ClientHttpResponse response) th final I body = readBody(bodyType, response); closeIfNecessary(body, response); final HttpHeaders headers = response.getHeaders(); - final HttpStatus statusCode = response.getStatusCode(); + final HttpStatusCode statusCode = response.getStatusCode(); return cast(new ResponseEntity<>(body, headers, statusCode)); } else { final I body = readBody(type.getType(), response); diff --git a/riptide-core/src/main/java/org/zalando/riptide/ForwardingClientHttpResponse.java b/riptide-core/src/main/java/org/zalando/riptide/ForwardingClientHttpResponse.java index 4c314f798..c9cddcd55 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/ForwardingClientHttpResponse.java +++ b/riptide-core/src/main/java/org/zalando/riptide/ForwardingClientHttpResponse.java @@ -2,7 +2,7 @@ import com.google.common.collect.ForwardingObject; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import java.io.IOException; @@ -20,11 +20,11 @@ public void close() { @Override public int getRawStatusCode() throws IOException { - return delegate().getRawStatusCode(); + return getStatusCode().value(); } @Override - public HttpStatus getStatusCode() throws IOException { + public HttpStatusCode getStatusCode() throws IOException { return delegate().getStatusCode(); } diff --git a/riptide-core/src/main/java/org/zalando/riptide/Http.java b/riptide-core/src/main/java/org/zalando/riptide/Http.java index 22c0e8408..8b1c9c96c 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/Http.java +++ b/riptide-core/src/main/java/org/zalando/riptide/Http.java @@ -1,7 +1,6 @@ package org.zalando.riptide; import org.apiguardian.api.API; -import org.springframework.http.client.AsyncClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.client.RestTemplate; @@ -33,7 +32,6 @@ static ExecutorStage builder() { interface ExecutorStage extends RequestFactoryStage { RequestFactoryStage executor(Executor executor); - ConfigurationStage asyncRequestFactory(AsyncClientHttpRequestFactory asyncRequestFactory); } interface RequestFactoryStage { diff --git a/riptide-core/src/main/java/org/zalando/riptide/HttpResponseException.java b/riptide-core/src/main/java/org/zalando/riptide/HttpResponseException.java index 61c1ea319..a671c6d20 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/HttpResponseException.java +++ b/riptide-core/src/main/java/org/zalando/riptide/HttpResponseException.java @@ -30,7 +30,7 @@ public abstract class HttpResponseException extends RestClientException { private final byte[] responseBody; public HttpResponseException(final String message, final ClientHttpResponse response) throws IOException { - this(message, response.getRawStatusCode(), response.getStatusText(), response.getHeaders(), + this(message, response.getStatusCode().value(), response.getStatusText(), response.getHeaders(), extractCharset(response), tryWith(response, HttpResponseException::readFromBody)); } diff --git a/riptide-core/src/main/java/org/zalando/riptide/NonBlockingIO.java b/riptide-core/src/main/java/org/zalando/riptide/NonBlockingIO.java deleted file mode 100644 index e889934fc..000000000 --- a/riptide-core/src/main/java/org/zalando/riptide/NonBlockingIO.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.zalando.riptide; - -import lombok.AllArgsConstructor; -import org.springframework.http.HttpMethod; -import org.springframework.http.client.AsyncClientHttpRequest; -import org.springframework.http.client.AsyncClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.concurrent.ListenableFuture; - -import java.io.IOException; -import java.net.URI; -import java.util.concurrent.CompletableFuture; - -@AllArgsConstructor -final class NonBlockingIO implements IO { - - private final AsyncClientHttpRequestFactory requestFactory; - - @Override - public CompletableFuture execute(final RequestArguments arguments) throws IOException { - final URI uri = arguments.getRequestUri(); - final HttpMethod method = arguments.getMethod(); - - final AsyncClientHttpRequest request = requestFactory.createAsyncRequest(uri, method); - - copyTo(arguments.getHeaders(), request.getHeaders()); - arguments.getEntity().writeTo(request); - - return toCompletable(request.executeAsync()); - } - - private CompletableFuture toCompletable(final ListenableFuture original) { - final CompletableFuture future = new CompletableFuture<>(); - original.addCallback(future::complete, future::completeExceptionally); - return future; - } - -} diff --git a/riptide-core/src/main/java/org/zalando/riptide/SeriesNavigator.java b/riptide-core/src/main/java/org/zalando/riptide/SeriesNavigator.java index f07a48883..e3ac815db 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/SeriesNavigator.java +++ b/riptide-core/src/main/java/org/zalando/riptide/SeriesNavigator.java @@ -1,5 +1,6 @@ package org.zalando.riptide; +import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus.Series; import org.springframework.http.client.ClientHttpResponse; @@ -14,7 +15,7 @@ enum SeriesNavigator implements EqualityNavigator { @Override public Series attributeOf(final ClientHttpResponse response) throws IOException { - return response.getStatusCode().series(); + return HttpStatus.resolve(response.getStatusCode().value()).series(); } } diff --git a/riptide-core/src/main/java/org/zalando/riptide/StatusCodeNavigator.java b/riptide-core/src/main/java/org/zalando/riptide/StatusCodeNavigator.java index 29dd0109d..a21b86ea8 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/StatusCodeNavigator.java +++ b/riptide-core/src/main/java/org/zalando/riptide/StatusCodeNavigator.java @@ -13,7 +13,7 @@ enum StatusCodeNavigator implements EqualityNavigator { @Override public Integer attributeOf(final ClientHttpResponse response) throws IOException { - return response.getRawStatusCode(); + return response.getStatusCode().value(); } } diff --git a/riptide-core/src/main/java/org/zalando/riptide/StatusNavigator.java b/riptide-core/src/main/java/org/zalando/riptide/StatusNavigator.java index 43e0a566e..ee82d2f23 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/StatusNavigator.java +++ b/riptide-core/src/main/java/org/zalando/riptide/StatusNavigator.java @@ -14,7 +14,7 @@ enum StatusNavigator implements EqualityNavigator { @Override public HttpStatus attributeOf(final ClientHttpResponse response) throws IOException { - return response.getStatusCode(); + return HttpStatus.resolve(response.getStatusCode().value()); } } diff --git a/riptide-core/src/test/java/org/zalando/riptide/CallTest.java b/riptide-core/src/test/java/org/zalando/riptide/CallTest.java index f1f4c300f..d2b823fa9 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/CallTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/CallTest.java @@ -15,10 +15,7 @@ import java.util.concurrent.CompletionException; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anEmptyMap; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -130,7 +127,7 @@ private void validateEntity(final AccountBody account) throws IOException { } private void fail(final ClientHttpResponse response) throws IOException { - throw new AssertionError(response.getRawStatusCode()); + throw new AssertionError(response.getStatusCode().value()); } } diff --git a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java index 7fefa63f4..6f6439c9b 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java @@ -11,9 +11,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.springframework.http.HttpStatus.OK; final class ForwardingClientHttpResponseTest { @@ -21,7 +19,6 @@ final class ForwardingClientHttpResponseTest { @Test void shouldDelegateAccessors() throws IOException { final ClientHttpResponse response = mock(ClientHttpResponse.class); - when(response.getRawStatusCode()).thenReturn(200); when(response.getStatusCode()).thenReturn(OK); when(response.getStatusText()).thenReturn("OK"); when(response.getBody()).thenReturn(new ByteArrayInputStream("Hello World!".getBytes(UTF_8))); diff --git a/riptide-core/src/test/java/org/zalando/riptide/HttpResponseExceptionTest.java b/riptide-core/src/test/java/org/zalando/riptide/HttpResponseExceptionTest.java index d6f1a1c4b..c8368d15a 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/HttpResponseExceptionTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/HttpResponseExceptionTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import java.io.IOException; @@ -15,6 +16,7 @@ final class HttpResponseExceptionTest { @SuppressWarnings("ThrowableNotThrown") void shouldNotFailOnNullBody() throws IOException { final ClientHttpResponse response = mock(ClientHttpResponse.class); + when(response.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST); when(response.getHeaders()).thenReturn(new HttpHeaders()); new HttpResponseException("foo", response) {}; diff --git a/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java b/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java index 3bcfa24dd..6e690d4a4 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java +++ b/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java @@ -7,14 +7,13 @@ import java.util.function.Predicate; import java.util.stream.Stream; -import static org.springframework.http.HttpStatus.MOVED_TEMPORARILY; -import static org.springframework.http.HttpStatus.REQUEST_ENTITY_TOO_LARGE; -import static org.springframework.http.HttpStatus.REQUEST_URI_TOO_LONG; +import static org.springframework.http.HttpStatus.*; final class HttpStatuses { @SuppressWarnings("deprecation") private static final ImmutableSet DEPRECATED = Sets.immutableEnumSet( + CHECKPOINT, // duplicate with EARLY_HINTS MOVED_TEMPORARILY, // duplicate with FOUND REQUEST_ENTITY_TOO_LARGE, // duplicate with PAYLOAD_TOO_LARGE REQUEST_URI_TOO_LONG // duplicate with URI_TOO_LONG diff --git a/riptide-core/src/test/java/org/zalando/riptide/NIOTest.java b/riptide-core/src/test/java/org/zalando/riptide/NIOTest.java deleted file mode 100644 index 8980eb26c..000000000 --- a/riptide-core/src/test/java/org/zalando/riptide/NIOTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.zalando.riptide; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.SneakyThrows; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.http.client.AsyncClientHttpRequestFactory; -import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.atomic.AtomicReference; - -import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NON_PRIVATE; -import static java.util.stream.Collectors.toList; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasItems; -import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; -import static org.zalando.riptide.Bindings.on; -import static org.zalando.riptide.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.MockWebServerUtil.jsonMockResponseFromResource; -import static org.zalando.riptide.MockWebServerUtil.verify; -import static org.zalando.riptide.Navigators.series; -import static org.zalando.riptide.Types.listOf; - -final class NIOTest { - - private final MockWebServer server = new MockWebServer(); - - @JsonAutoDetect(fieldVisibility = NON_PRIVATE) - static class User { - String login; - - String getLogin() { - return login; - } - } - - @SneakyThrows - @AfterEach - void shutdownServer() { - server.shutdown(); - } - - private final AsyncClientHttpRequestFactory requestFactory = new HttpComponentsAsyncClientHttpRequestFactory(); - - private final Http http = Http.builder() - .asyncRequestFactory(requestFactory) - .baseUrl(getBaseUrl(server)) - .converter(createJsonConverter()) - .build(); - - private static MappingJackson2HttpMessageConverter createJsonConverter() { - final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); - converter.setObjectMapper(new ObjectMapper().findAndRegisterModules() - .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); - return converter; - } - - @Test - void shouldRead() throws IOException { - shouldReadContributors(); - } - - private void shouldReadContributors() throws IOException { - server.enqueue(jsonMockResponseFromResource("contributors.json")); - - final AtomicReference> reference = new AtomicReference<>(); - - http.get("/repos/{org}/{repo}/contributors", "zalando", "riptide") - .dispatch(series(), - on(SUCCESSFUL).call(listOf(User.class), reference::set)).join(); - - final List users = reference.get().stream() - .map(User::getLogin) - .collect(toList()); - - assertThat(users, hasItems("jhorstmann", "lukasniemeier-zalando", "whiskeysierra")); - verify(server, 1, "/repos/zalando/riptide/contributors"); - } - -} diff --git a/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java b/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java index c34e2bd86..79d98e430 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java @@ -20,31 +20,16 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; import static org.hobsoft.hamcrest.compose.ComposeMatchers.hasFeature; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.springframework.http.HttpStatus.ACCEPTED; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.MOVED_PERMANENTLY; -import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR; -import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; -import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; -import static org.springframework.http.HttpStatus.UNAUTHORIZED; -import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.HttpStatus.Series.*; import static org.springframework.http.MediaType.parseMediaType; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.zalando.riptide.Bindings.anyContentType; -import static org.zalando.riptide.Bindings.anySeries; -import static org.zalando.riptide.Bindings.anyStatus; -import static org.zalando.riptide.Bindings.anyStatusCode; -import static org.zalando.riptide.Bindings.on; -import static org.zalando.riptide.Navigators.contentType; -import static org.zalando.riptide.Navigators.series; -import static org.zalando.riptide.Navigators.status; -import static org.zalando.riptide.Navigators.statusCode; +import static org.zalando.riptide.Bindings.*; +import static org.zalando.riptide.Navigators.*; import static org.zalando.riptide.RoutingTree.dispatch; import static org.zalando.riptide.Types.listOf; import static org.zalando.riptide.model.MediaTypes.ERROR; @@ -111,7 +96,7 @@ HttpStatus getStatus() { } private void fail(final ClientHttpResponse response) throws IOException { - throw new Failure(response.getStatusCode()); + throw new Failure(HttpStatus.resolve(response.getStatusCode().value())); } @Test diff --git a/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java b/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java index 93529c659..8cebeaa64 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java @@ -22,10 +22,8 @@ import java.util.function.Consumer; import java.util.stream.Stream; -import static java.util.EnumSet.allOf; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; +import static java.util.Arrays.stream; +import static java.util.stream.Collectors.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; @@ -41,7 +39,7 @@ final class RequestUriTest { static List data() { - final Set methods = allOf(HttpMethod.class).stream() + final Set methods = stream(HttpMethod.values()) .map(Arguments::of) .collect(toSet()); diff --git a/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java b/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java index 266ecbf6b..21cd0cc08 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java @@ -12,17 +12,10 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.springframework.http.HttpStatus.CONFLICT; -import static org.springframework.http.HttpStatus.NO_CONTENT; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.http.MediaType.TEXT_PLAIN; -import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; +import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.MediaType.*; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -107,7 +100,7 @@ void shouldAllowToCaptureBody() throws Exception { } private void fail(final ClientHttpResponse response) throws IOException { - throw new AssertionError(response.getRawStatusCode()); + throw new AssertionError(response.getStatusCode().value()); } } diff --git a/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java b/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java index c86fde719..6e2c8b9ce 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java @@ -13,11 +13,7 @@ import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR; -import static org.springframework.http.HttpStatus.Series.INFORMATIONAL; -import static org.springframework.http.HttpStatus.Series.REDIRECTION; -import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; -import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; +import static org.springframework.http.HttpStatus.Series.*; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; import static org.zalando.riptide.Bindings.on; @@ -47,7 +43,7 @@ void shouldDispatch(final HttpStatus expected) { server.expect(requestTo(url)).andRespond(withStatus(expected)); final ClientHttpResponseConsumer verifier = response -> - assertThat(response.getStatusCode().series(), is(expected.series())); + assertThat(HttpStatus.resolve(response.getStatusCode().value()).series(), is(expected.series())); unit.get(url) .dispatch(series(), diff --git a/riptide-core/src/test/java/org/zalando/riptide/StatusCodeDispatchTest.java b/riptide-core/src/test/java/org/zalando/riptide/StatusCodeDispatchTest.java index 4f49f4019..546ad2c03 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/StatusCodeDispatchTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/StatusCodeDispatchTest.java @@ -38,7 +38,7 @@ void shouldDispatch(final int expected) { server.expect(requestTo(url)).andRespond(withStatus(HttpStatus.valueOf(expected))); final ClientHttpResponseConsumer verifier = response -> - assertThat(response.getRawStatusCode(), is(expected)); + assertThat(response.getStatusCode().value(), is(expected)); @SuppressWarnings("unchecked") final Binding[] bindings = HttpStatuses.supported() diff --git a/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java b/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java index f065d2cf3..b8cd6fc52 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java @@ -1,12 +1,8 @@ package org.zalando.riptide; -import io.netty.channel.nio.NioEventLoopGroup; import lombok.SneakyThrows; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.junit.jupiter.api.Test; -import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory; -import org.springframework.http.client.Netty4ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.zalando.riptide.Http.ConfigurationStage; @@ -18,9 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; import static org.zalando.riptide.Bindings.on; -import static org.zalando.riptide.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.MockWebServerUtil.verify; +import static org.zalando.riptide.MockWebServerUtil.*; import static org.zalando.riptide.Navigators.series; final class ThreadAffinityTest { @@ -43,38 +37,6 @@ void asyncBlocking() { test(stage, "process", "process", "process"); } - @Test - void syncNonBlockingApache() throws Exception { - final HttpComponentsAsyncClientHttpRequestFactory requestFactory = - new HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClientBuilder.create() - .setThreadFactory(threadFactory("io")) - .build()); - - try { - final ConfigurationStage stage = Http.builder() - .asyncRequestFactory(requestFactory); - - test(stage, "main", "io", "io"); - } finally { - requestFactory.destroy(); - } - } - - @Test - void syncNonBlockingNetty() throws Exception { - final Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory( - new NioEventLoopGroup(0, threadFactory("io"))); - - try { - final ConfigurationStage stage = Http.builder() - .asyncRequestFactory(requestFactory); - - test(stage, "main", "io", "io"); - } finally { - requestFactory.destroy(); - } - } - @SneakyThrows void test(final ConfigurationStage stage, final String request, final String dispatch, final String callback) { final MockWebServer server = new MockWebServer(); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java index fd0ebff38..23d33a5fb 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java @@ -3,8 +3,8 @@ import com.google.common.collect.ImmutableMap; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpRequestFactory; @@ -28,9 +28,7 @@ import static org.zalando.riptide.Bindings.on; import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; final class FailsafePluginBackupRequestTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java index e249cc622..8dec006a4 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java @@ -5,9 +5,11 @@ import dev.failsafe.CircuitBreaker; import dev.failsafe.CircuitBreakerOpenException; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -30,9 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zalando.fauxpas.FauxPas.partially; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; import static org.zalando.riptide.failsafe.TaskDecorator.composite; final class FailsafePluginCircuitBreakerTest { @@ -40,8 +40,10 @@ final class FailsafePluginCircuitBreakerTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(500) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(500)) + .build()) .build()) .build(); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java index da0d24d03..fc59a26bd 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java @@ -3,9 +3,11 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -22,17 +24,17 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.zalando.fauxpas.FauxPas.partially; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; final class FailsafePluginNoPolicyTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(500) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(500)) + .build()) .build()) .build(); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java index a5382f295..83a6dfea5 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java @@ -5,13 +5,13 @@ import dev.failsafe.CircuitBreaker; import dev.failsafe.RetryPolicy; import lombok.SneakyThrows; -import okhttp3.mockwebserver.Dispatcher; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; @@ -40,9 +40,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTimeout; +import static org.junit.jupiter.api.Assertions.*; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; @@ -54,9 +52,7 @@ import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.Route.call; import static org.zalando.riptide.failsafe.CheckedPredicateConverter.toCheckedPredicate; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; import static org.zalando.riptide.failsafe.RetryRoute.retry; import static org.zalando.riptide.faults.Predicates.alwaysTrue; import static org.zalando.riptide.faults.TransientFaults.transientConnectionFaults; @@ -67,8 +63,10 @@ final class FailsafePluginRetriesTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(500) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(500)) + .build()) .build()) .build(); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java index 09b60d919..68cc25af0 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java @@ -8,9 +8,11 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -46,8 +48,10 @@ final class FailsafePluginRetryListenerTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(500) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(500)) + .build()) .build()) .build(); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java index 7fcb69477..eb95651f9 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java @@ -5,8 +5,8 @@ import dev.failsafe.Timeout; import dev.failsafe.TimeoutExceededException; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -24,9 +24,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; final class FailsafePluginTimeoutTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java index 130be541f..da2205a4e 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java @@ -7,9 +7,11 @@ import dev.failsafe.RetryPolicy; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; @@ -35,9 +37,7 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.Navigators.status; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; import static org.zalando.riptide.failsafe.RetryRoute.retry; final class RateLimitResetDelayFunctionTest { @@ -45,8 +45,10 @@ final class RateLimitResetDelayFunctionTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(1000) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(1000)) + .build()) .build()) .build(); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java index c20c3a4e3..3db5ce2dd 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java @@ -7,9 +7,11 @@ import dev.failsafe.RetryPolicy; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; @@ -35,9 +37,7 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.Navigators.status; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; +import static org.zalando.riptide.failsafe.MockWebServerUtil.*; import static org.zalando.riptide.failsafe.RetryRoute.retry; final class RetryAfterDelayFunctionTest { @@ -45,8 +45,10 @@ final class RetryAfterDelayFunctionTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(1000) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setSocketTimeout(Timeout.ofMilliseconds(1000)) + .build()) .build()) .build(); diff --git a/riptide-httpclient/pom.xml b/riptide-httpclient/pom.xml index a72c94a29..83d21b2d5 100644 --- a/riptide-httpclient/pom.xml +++ b/riptide-httpclient/pom.xml @@ -31,15 +31,8 @@ spring-web - org.apache.httpcomponents - httpclient - 4.5.14 - - - commons-logging - commons-logging - - + org.apache.httpcomponents.client5 + httpclient5 org.zalando diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java index e925d0740..b1a4e3f74 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java @@ -2,16 +2,8 @@ import com.google.common.collect.ImmutableMap; import lombok.AllArgsConstructor; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpOptions; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpTrace; -import org.apache.http.client.methods.HttpUriRequest; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.*; import org.apiguardian.api.API; import org.springframework.beans.factory.DisposableBean; import org.springframework.http.HttpMethod; @@ -25,14 +17,7 @@ import java.util.function.Function; import static org.apiguardian.api.API.Status.STABLE; -import static org.springframework.http.HttpMethod.DELETE; -import static org.springframework.http.HttpMethod.GET; -import static org.springframework.http.HttpMethod.HEAD; -import static org.springframework.http.HttpMethod.OPTIONS; -import static org.springframework.http.HttpMethod.PATCH; -import static org.springframework.http.HttpMethod.POST; -import static org.springframework.http.HttpMethod.PUT; -import static org.springframework.http.HttpMethod.TRACE; +import static org.springframework.http.HttpMethod.*; @API(status = STABLE) @AllArgsConstructor diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpResponse.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpResponse.java index ff55485e2..97d0d7654 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpResponse.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpResponse.java @@ -1,10 +1,10 @@ package org.zalando.riptide.httpclient; import lombok.extern.slf4j.Slf4j; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.conn.ConnectionReleaseTrigger; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpEntityContainer; +import org.apache.hc.core5.http.HttpResponse; import org.springframework.http.HttpHeaders; import org.springframework.http.client.AbstractClientHttpResponse; @@ -27,45 +27,36 @@ final class ApacheClientHttpResponse extends AbstractClientHttpResponse { this.response = response; this.body = getBody(response); - for (final Header header : response.getAllHeaders()) { + for (final Header header : response.getHeaders()) { this.headers.add(header.getName(), header.getValue()); } } private static InputStream getBody(final HttpResponse response) throws IOException { - @Nullable final HttpEntity entity = response.getEntity(); + @Nullable HttpEntity entity = null; + + if (response instanceof HttpEntityContainer) { + entity = ((HttpEntityContainer) response).getEntity(); + } if (entity == null) { return EMPTY; } return new EndOfStreamAwareInputStream(entity.getContent(), (body, endOfStreamDetected) -> { - if (body instanceof ConnectionReleaseTrigger) { - // effectively releasing the connection back to the pool in order to prevent starvation - final ConnectionReleaseTrigger trigger = (ConnectionReleaseTrigger) body; - - if (endOfStreamDetected) { - // Stream was fully consumed, connection can therefore be reused. - trigger.releaseConnection(); - } else { - // Stream was not fully consumed, connection needs to be discarded. - // We can't just consume the remaining bytes since the stream could be endless. - trigger.abortConnection(); - } - } body.close(); }); } @Override public int getRawStatusCode() { - return response.getStatusLine().getStatusCode(); + return response.getCode(); } @Nonnull @Override public String getStatusText() { - return response.getStatusLine().getReasonPhrase(); + return response.getReasonPhrase(); } @Nonnull diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java index af11a942b..53d3bb05a 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java @@ -1,21 +1,24 @@ package org.zalando.riptide.httpclient; import lombok.AllArgsConstructor; -import org.apache.http.HttpEntityEnclosingRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.ByteArrayEntity; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.io.entity.ByteArrayEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URI; +import java.net.URISyntaxException; @AllArgsConstructor final class BufferingApacheClientHttpRequest implements ClientHttpRequest { @@ -26,22 +29,19 @@ final class BufferingApacheClientHttpRequest implements ClientHttpRequest { private final HttpClient client; private final HttpUriRequest request; - @Nonnull - @SuppressWarnings("WeakerAccess") - @Override - public String getMethodValue() { - return request.getMethod(); - } - @Override public HttpMethod getMethod() { - return HttpMethod.valueOf(getMethodValue()); + return HttpMethod.valueOf(request.getMethod()); } @Nonnull @Override public URI getURI() { - return request.getURI(); + try { + return request.getUri(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); + } } @Nonnull @@ -59,14 +59,18 @@ public OutputStream getBody() { @Override public ClientHttpResponse execute() throws IOException { Headers.writeHeaders(headers, request); - - if (request instanceof HttpEntityEnclosingRequest) { - final HttpEntityEnclosingRequest enclosing = (HttpEntityEnclosingRequest) request; - enclosing.setEntity(new ByteArrayEntity(output.toByteArray())); - } + request.setEntity(new ByteArrayEntity(output.toByteArray(), toContentType(headers.getContentType()))); final HttpResponse response = client.execute(request); return new ApacheClientHttpResponse(response); } + @Nullable + private ContentType toContentType(@Nullable MediaType mediaType) { + if (mediaType == null) { + return null; + } + return ContentType.create(mediaType.toString()); + } + } diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/Headers.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/Headers.java index 27734f2d7..4c2fcf40a 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/Headers.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/Headers.java @@ -1,6 +1,6 @@ package org.zalando.riptide.httpclient; -import org.apache.http.client.methods.HttpUriRequest; +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; import org.springframework.http.HttpHeaders; import static org.springframework.http.HttpHeaders.CONTENT_LENGTH; diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java index 230de2e80..afb859e23 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java @@ -1,13 +1,12 @@ package org.zalando.riptide.httpclient; import lombok.AllArgsConstructor; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpEntityEnclosingRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.message.BasicHeader; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; +import org.apache.hc.core5.function.Supplier; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpResponse; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.StreamingHttpOutputMessage; @@ -20,11 +19,12 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; import java.util.Objects; -import java.util.Optional; +import java.util.Set; import static org.springframework.http.HttpHeaders.CONTENT_ENCODING; -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; @AllArgsConstructor final class StreamingApacheClientHttpRequest implements ClientHttpRequest, StreamingHttpOutputMessage { @@ -34,22 +34,19 @@ final class StreamingApacheClientHttpRequest implements ClientHttpRequest, Strea private final HttpClient client; private final HttpUriRequest request; - @Nonnull - @SuppressWarnings("WeakerAccess") - @Override - public String getMethodValue() { - return request.getMethod(); - } - @Override public HttpMethod getMethod() { - return HttpMethod.valueOf(getMethodValue()); + return HttpMethod.valueOf(request.getMethod()); } @Nonnull @Override public URI getURI() { - return request.getURI(); + try { + return request.getUri(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); + } } @Nonnull @@ -66,12 +63,7 @@ public OutputStream getBody() { @Override public void setBody(final Body body) { - if (request instanceof HttpEntityEnclosingRequest) { - final HttpEntityEnclosingRequest enclosing = (HttpEntityEnclosingRequest) request; - enclosing.setEntity(new StreamingHttpEntity(body)); - } else { - throw new IllegalStateException(getMethodValue() + " doesn't support a body"); - } + request.setEntity(new StreamingHttpEntity(body)); } @Override @@ -96,6 +88,11 @@ public boolean isChunked() { return false; } + @Override + public Set getTrailerNames() { + return null; + } + @Override public long getContentLength() { return headers.getContentLength(); @@ -103,19 +100,14 @@ public long getContentLength() { @Override @Nullable - public Header getContentType() { - return Optional.ofNullable(headers.getContentType()) - .map(Objects::toString) - .map(type -> new BasicHeader(CONTENT_TYPE, type)) - .orElse(null); + public String getContentType() { + return Objects.toString(headers.getContentType()); } @Override @Nullable - public Header getContentEncoding() { - return Optional.ofNullable(headers.getFirst(CONTENT_ENCODING)) - .map(encoding -> new BasicHeader(CONTENT_ENCODING, encoding)) - .orElse(null); + public String getContentEncoding() { + return headers.getFirst(CONTENT_ENCODING); } @Override @@ -134,9 +126,13 @@ public boolean isStreaming() { } @Override - @Deprecated - public void consumeContent() { - throw new UnsupportedOperationException(); + public Supplier> getTrailers() { + return null; + } + + @Override + public void close() throws IOException { + } } diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetrics.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetrics.java index ac17b3431..e01c05e01 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetrics.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetrics.java @@ -6,8 +6,8 @@ import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.binder.MeterBinder; import lombok.AllArgsConstructor; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.pool.PoolStats; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.pool.PoolStats; import org.apiguardian.api.API; import java.util.function.Supplier; diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java index 9869c34ee..a50b8970d 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java @@ -5,10 +5,12 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.core.ParameterizedTypeReference; @@ -39,14 +41,7 @@ import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anEmptyMap; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.hasToString; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeout; import static org.mockito.Mockito.mock; @@ -59,19 +54,18 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.Types.listOf; -import static org.zalando.riptide.httpclient.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.httpclient.MockWebServerUtil.jsonMockResponseFromResource; -import static org.zalando.riptide.httpclient.MockWebServerUtil.textMockResponse; -import static org.zalando.riptide.httpclient.MockWebServerUtil.verify; +import static org.zalando.riptide.httpclient.MockWebServerUtil.*; public abstract class AbstractApacheClientHttpRequestFactoryTest { private final MockWebServer server = new MockWebServer(); private final CloseableHttpClient client = HttpClientBuilder.create() - .setMaxConnTotal(1) - .setMaxConnPerRoute(1) - .setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(10).build()) + .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create() + .setMaxConnTotal(1) + .setMaxConnPerRoute(1) + .build()) + .setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(Timeout.ofSeconds(10)).build()) .build(); private final ApacheClientHttpRequestFactory factory = new ApacheClientHttpRequestFactory(client, getMode()); diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java index 1702190b4..b52ee2c52 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java @@ -1,42 +1,27 @@ package org.zalando.riptide.httpclient; -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.conn.EofSensorInputStream; -import org.apache.http.entity.InputStreamEntity; +import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.io.entity.InputStreamEntity; import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; final class ApacheClientHttpResponseBodyTest { @Test void shouldCallCloseOnNormalStreams() throws IOException { final InputStream stream = mock(InputStream.class); - final HttpResponse response = mock(HttpResponse.class); - when(response.getEntity()).thenReturn(new InputStreamEntity(stream)); - when(response.getAllHeaders()).thenReturn(new Header[0]); + final ClassicHttpResponse response = mock(ClassicHttpResponse.class); + when(response.getEntity()).thenReturn(new InputStreamEntity(stream, null)); + when(response.getHeaders()).thenReturn(new Header[0]); new ApacheClientHttpResponse(response).close(); verify(stream).close(); } - @Test - void shouldCallAbortAndCloseOnConnectionReleaseTrigger() throws IOException { - final EofSensorInputStream stream = mock(EofSensorInputStream.class); - final HttpResponse response = mock(HttpResponse.class); - when(response.getEntity()).thenReturn(new InputStreamEntity(stream)); - when(response.getAllHeaders()).thenReturn(new Header[0]); - - new ApacheClientHttpResponse(response).close(); - - verify(stream).abortConnection(); - verify(stream).close(); - } } diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java index 64f373f67..326a379be 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java @@ -1,11 +1,9 @@ package org.zalando.riptide.httpclient; -import org.apache.http.HttpEntity; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpPost; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.core5.http.HttpEntity; import org.junit.jupiter.api.Test; -import org.springframework.http.StreamingHttpOutputMessage; import org.springframework.http.StreamingHttpOutputMessage.Body; import org.springframework.http.client.ClientHttpRequest; @@ -18,7 +16,7 @@ final class StreamingApacheClientHttpRequestTest { @Test void shouldUseStreamingEntity() { final HttpClient client = mock(HttpClient.class); - final HttpPost request = new HttpPost(); + final HttpPost request = new HttpPost("https://example.org"); final StreamingApacheClientHttpRequest unit = new StreamingApacheClientHttpRequest(client, request); @@ -28,26 +26,16 @@ void shouldUseStreamingEntity() { assertFalse(entity.isStreaming()); assertThrows(UnsupportedOperationException.class, entity::getContent); - assertThrows(UnsupportedOperationException.class, entity::consumeContent); } @Test void shouldNotSupportGetBody() { final HttpClient client = mock(HttpClient.class); - final HttpPost request = new HttpPost(); + final HttpPost request = new HttpPost("https://example.org"); final ClientHttpRequest unit = new StreamingApacheClientHttpRequest(client, request); assertThrows(UnsupportedOperationException.class, unit::getBody); } - @Test - void shouldFailOnNonBodyRequests() { - final HttpClient client = mock(HttpClient.class); - - final StreamingHttpOutputMessage unit = new StreamingApacheClientHttpRequest(client, new HttpDelete()); - - assertThrows(IllegalStateException.class, () -> unit.setBody(mock(Body.class))); - } - } diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java index f655bb67e..fb2b4487f 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java @@ -5,9 +5,9 @@ import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpRequestFactory; @@ -21,9 +21,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.zalando.riptide.Route.call; -import static org.zalando.riptide.httpclient.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.httpclient.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.httpclient.MockWebServerUtil.verify; +import static org.zalando.riptide.httpclient.MockWebServerUtil.*; final class HttpConnectionPoolMetricsTest { @@ -67,7 +65,7 @@ void shouldRecordConnectionPoolMetrics() { assertThat(gauge("connection-pool.leased").value(), is(0.0)); assertThat(gauge("connection-pool.total").value(), is(1.0)); assertThat(gauge("connection-pool.min").value(), is(0.0)); - assertThat(gauge("connection-pool.max").value(), is(20.0)); + assertThat(gauge("connection-pool.max").value(), is(25.0)); assertThat(gauge("connection-pool.queued").value(), is(0.0)); verify(server, 1, "/"); diff --git a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java index 7f7e993b7..080550e2a 100644 --- a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java +++ b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java @@ -1,9 +1,13 @@ package org.zalando.riptide.idempotency; import org.apiguardian.api.API; +import org.springframework.http.HttpMethod; import org.zalando.riptide.RequestArguments; +import java.util.Set; + import static org.apiguardian.api.API.Status.EXPERIMENTAL; +import static org.springframework.http.HttpMethod.*; /** * @see Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content, Section 4.2.1 @@ -11,20 +15,15 @@ */ @API(status = EXPERIMENTAL) public final class DefaultIdempotencyDetector implements IdempotencyDetector { + private final Set ACCEPTED_METHODS = Set.of(DELETE, GET, HEAD, OPTIONS, PUT, TRACE); @Override public Decision test(final RequestArguments arguments, final Test root) { - switch (arguments.getMethod()) { - case DELETE: - case GET: - case HEAD: - case OPTIONS: - case PUT: - case TRACE: - return Decision.ACCEPT; - default: - return Decision.NEUTRAL; + if (ACCEPTED_METHODS.contains(arguments.getMethod())) { + return Decision.ACCEPT; } + + return Decision.NEUTRAL; } } diff --git a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java index 248deaaf1..37164cdca 100644 --- a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java +++ b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java @@ -3,32 +3,40 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.http.HttpMethod; import org.zalando.riptide.RequestArguments; import java.util.function.Predicate; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.springframework.http.HttpMethod.GET; -import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.*; import static org.zalando.riptide.Attributes.IDEMPOTENT; final class IdempotencyPredicateTest { private final Predicate unit = new IdempotencyPredicate(); + private static Stream shouldDetectIdempotentMethods() { + return Stream.of(DELETE, GET, HEAD, OPTIONS, PUT, TRACE); + } + @ParameterizedTest - @EnumSource(value = HttpMethod.class, names = {"DELETE", "GET", "HEAD", "OPTIONS", "PUT", "TRACE"}) + @MethodSource void shouldDetectIdempotentMethods(final HttpMethod method) { assertTrue(unit.test(RequestArguments.create() .withMethod(method))); } + private static Stream shouldNotDetectNonIdempotentMethods() { + return Stream.of(POST, PATCH); + } + @ParameterizedTest - @EnumSource(value = HttpMethod.class, names = {"POST", "PATCH"}) + @MethodSource void shouldNotDetectNonIdempotentMethods(final HttpMethod method) { assertFalse(unit.test(RequestArguments.create() .withMethod(method))); @@ -77,8 +85,12 @@ void shouldDetectIdempotencyKeyCaseInsensitive() { .withHeader("idempotency-key", "xPkDYMOzZNdBoJ2l"))); } + private static Stream shouldDetectOverriddenSafeMethod() { + return Stream.of(GET, HEAD, OPTIONS, TRACE); + } + @ParameterizedTest - @EnumSource(value = HttpMethod.class, names = {"GET", "HEAD", "OPTIONS", "TRACE"}) + @MethodSource void shouldDetectOverriddenSafeMethod(final HttpMethod override) { assertTrue(unit.test(RequestArguments.create() .withMethod(POST) @@ -114,8 +126,12 @@ void shouldDetectMethodOverriddenNonIdempotentMethod(final String override) { .withHeader("X-HTTP-Method-Override", override))); } + private static Stream shouldOnlyDetectMethodOverrideForPostMethod() { + return Stream.of(PATCH); + } + @ParameterizedTest - @EnumSource(value = HttpMethod.class, names = "PATCH") + @MethodSource void shouldOnlyDetectMethodOverrideForPostMethod(final HttpMethod method) { assertFalse(unit.test(RequestArguments.create() .withMethod(method) diff --git a/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java b/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java index 7b978832a..a5c723477 100644 --- a/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java +++ b/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java @@ -3,7 +3,7 @@ import com.google.common.io.ByteStreams; import lombok.AllArgsConstructor; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import org.zalando.logbook.HttpResponse; import org.zalando.logbook.Origin; @@ -187,13 +187,13 @@ private final class ClientHttpResponseAdapter implements ClientHttpResponse { @Nonnull @Override - public HttpStatus getStatusCode() throws IOException { + public HttpStatusCode getStatusCode() throws IOException { return response.getStatusCode(); } @Override public int getRawStatusCode() throws IOException { - return response.getRawStatusCode(); + return response.getStatusCode().value(); } @Nonnull diff --git a/riptide-micrometer/pom.xml b/riptide-micrometer/pom.xml index 3384c523e..6579cba7a 100644 --- a/riptide-micrometer/pom.xml +++ b/riptide-micrometer/pom.xml @@ -41,16 +41,9 @@ test - org.apache.httpcomponents - httpclient - 4.5.14 + org.apache.httpcomponents.client5 + httpclient5 test - - - commons-logging - commons-logging - - diff --git a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java index f2a57971f..65d45bb8a 100644 --- a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java +++ b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java @@ -9,8 +9,9 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpRequestFactory; @@ -31,11 +32,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.iterableWithSize; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.OK; @@ -45,9 +42,7 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.failsafe.CheckedPredicateConverter.toCheckedPredicate; -import static org.zalando.riptide.micrometer.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.micrometer.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.micrometer.MockWebServerUtil.verify; +import static org.zalando.riptide.micrometer.MockWebServerUtil.*; final class MicrometerPluginTest { @@ -56,7 +51,7 @@ final class MicrometerPluginTest { private final ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(500) + .setConnectTimeout(Timeout.ofMilliseconds(500)) .build()) .build()); diff --git a/riptide-opentelemetry/pom.xml b/riptide-opentelemetry/pom.xml index 0cce62df0..6c290f80f 100644 --- a/riptide-opentelemetry/pom.xml +++ b/riptide-opentelemetry/pom.xml @@ -49,8 +49,8 @@ test - org.apache.httpcomponents - httpclient + org.apache.httpcomponents.client5 + httpclient5 test diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java index 386b377c8..868bbb65f 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java @@ -14,8 +14,9 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -27,12 +28,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.zalando.riptide.AttributeStage; -import org.zalando.riptide.Bindings; -import org.zalando.riptide.Http; -import org.zalando.riptide.Navigators; -import org.zalando.riptide.RequestArguments; -import org.zalando.riptide.RequestExecution; +import org.zalando.riptide.*; import org.zalando.riptide.opentelemetry.span.HttpHostSpanDecorator; import org.zalando.riptide.opentelemetry.span.SpanDecorator; import org.zalando.riptide.opentelemetry.span.StaticSpanDecorator; @@ -51,21 +47,12 @@ import static java.util.Collections.singletonMap; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.zalando.riptide.NoRoute.noRoute; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.textMockResponse; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.verify; +import static org.zalando.riptide.opentelemetry.MockWebServerUtil.*; class OpenTelemetryPluginTest { @RegisterExtension @@ -83,7 +70,7 @@ class OpenTelemetryPluginTest { HttpClientBuilder.create() .setDefaultRequestConfig( RequestConfig.custom() - .setSocketTimeout(500) + .setConnectTimeout(Timeout.ofMilliseconds(500)) .build()) .build())) .baseUrl(getBaseUrl(server)) @@ -282,7 +269,7 @@ void shouldOverwriteDefaultSetOfDecorators() { HttpClientBuilder.create() .setDefaultRequestConfig( RequestConfig.custom() - .setSocketTimeout(500) + .setConnectTimeout(Timeout.ofMilliseconds(500)) .build()) .build())) .baseUrl(getBaseUrl(server)) diff --git a/riptide-opentracing/pom.xml b/riptide-opentracing/pom.xml index 4119bebd3..9267a0d84 100644 --- a/riptide-opentracing/pom.xml +++ b/riptide-opentracing/pom.xml @@ -54,16 +54,9 @@ test - org.apache.httpcomponents - httpclient - 4.5.14 + org.apache.httpcomponents.client5 + httpclient5 test - - - commons-logging - commons-logging - - diff --git a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java index 6b6f8bb39..efe9faf7b 100644 --- a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java +++ b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java @@ -7,8 +7,9 @@ import io.opentracing.mock.MockTracer; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -30,24 +31,13 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.hasKey; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; -import static org.springframework.http.HttpStatus.OK; import static org.zalando.riptide.NoRoute.noRoute; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.opentracing.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.opentracing.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.opentracing.MockWebServerUtil.textMockResponse; -import static org.zalando.riptide.opentracing.MockWebServerUtil.verify; +import static org.zalando.riptide.opentracing.MockWebServerUtil.*; final class OpenTracingPluginTest { @@ -58,7 +48,7 @@ final class OpenTracingPluginTest { .executor(new TracedExecutorService(newSingleThreadExecutor(), tracer)) .requestFactory(new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create() .setDefaultRequestConfig(RequestConfig.custom() - .setSocketTimeout(500) + .setConnectTimeout(Timeout.ofMilliseconds(500)) .build()) .build())) .baseUrl(getBaseUrl(server)) diff --git a/riptide-parent/pom.xml b/riptide-parent/pom.xml index bb76596a4..f1b64f318 100644 --- a/riptide-parent/pom.xml +++ b/riptide-parent/pom.xml @@ -21,11 +21,11 @@ 2.14.2 5.9.3 3.0.0 - 1.10.4 - 4.11.0 + 1.11.0 + 5.3.1 0.27.1 - 1.7.36 - 2.7.12 + 2.0.7 + 3.1.0 @@ -179,15 +179,9 @@ - org.apache.httpcomponents - httpclient - 4.5.14 - - - commons-logging - commons-logging - - + org.apache.httpcomponents.client5 + httpclient5 + 5.2.1 diff --git a/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPFaultHttpMessageConverter.java b/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPFaultHttpMessageConverter.java index 447b6e1a3..1a148182d 100644 --- a/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPFaultHttpMessageConverter.java +++ b/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPFaultHttpMessageConverter.java @@ -1,5 +1,9 @@ package org.zalando.riptide.soap; +import jakarta.xml.soap.MessageFactory; +import jakarta.xml.soap.SOAPException; +import jakarta.xml.soap.SOAPFault; +import jakarta.xml.soap.SOAPMessage; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; @@ -8,14 +12,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.xml.soap.MessageFactory; -import javax.xml.soap.SOAPException; -import javax.xml.soap.SOAPFault; -import javax.xml.soap.SOAPMessage; import java.io.IOException; +import static jakarta.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL; import static java.lang.ThreadLocal.withInitial; -import static javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL; import static org.springframework.http.MediaType.TEXT_XML; import static org.zalando.fauxpas.FauxPas.throwingSupplier; diff --git a/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPHttpMessageConverter.java b/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPHttpMessageConverter.java index fc17f0b7b..646d0cb2c 100644 --- a/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPHttpMessageConverter.java +++ b/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPHttpMessageConverter.java @@ -3,6 +3,15 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Marshaller; +import jakarta.xml.bind.Unmarshaller; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.soap.MessageFactory; +import jakarta.xml.soap.SOAPException; +import jakarta.xml.soap.SOAPMessage; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.converter.AbstractHttpMessageConverter; @@ -11,21 +20,12 @@ import org.w3c.dom.Document; import javax.annotation.Nonnull; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.soap.MessageFactory; -import javax.xml.soap.SOAPException; -import javax.xml.soap.SOAPMessage; import java.io.IOException; +import static jakarta.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL; import static java.lang.ThreadLocal.withInitial; -import static javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL; import static org.springframework.http.MediaType.TEXT_XML; import static org.zalando.fauxpas.FauxPas.throwingSupplier; @@ -67,8 +67,7 @@ protected Object readInternal(final Class type, final Unmarshaller unmarshaller = contexts.getUnchecked(type).createUnmarshaller(); return unmarshaller.unmarshal(document); } catch (final SOAPException | JAXBException e) { - // TODO should ideally pass message when running against Spring 5 - throw new HttpMessageNotReadableException(e.getMessage(), e); + throw new HttpMessageNotReadableException(e.getMessage(), e, message); } } diff --git a/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPRoute.java b/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPRoute.java index c0e4ff2af..45ed05c19 100644 --- a/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPRoute.java +++ b/riptide-soap/src/main/java/org/zalando/riptide/soap/SOAPRoute.java @@ -1,11 +1,10 @@ package org.zalando.riptide.soap; +import jakarta.xml.soap.SOAPFault; +import jakarta.xml.ws.soap.SOAPFaultException; import org.zalando.fauxpas.ThrowingConsumer; import org.zalando.riptide.Route; -import javax.xml.soap.SOAPFault; -import javax.xml.ws.soap.SOAPFaultException; - import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.OK; import static org.zalando.riptide.Bindings.on; diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/HelloService.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/HelloService.java index dcb3d2909..ae738b35a 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/HelloService.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/HelloService.java @@ -1,8 +1,8 @@ package org.zalando.riptide.soap; -import javax.jws.WebMethod; -import javax.jws.WebParam; -import javax.jws.WebService; +import jakarta.jws.WebMethod; +import jakarta.jws.WebParam; +import jakarta.jws.WebService; @WebService public class HelloService { diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolReadTest.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolReadTest.java index d61fa9840..b9a5b6b00 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolReadTest.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolReadTest.java @@ -1,5 +1,6 @@ package org.zalando.riptide.soap; +import jakarta.xml.ws.Endpoint; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -7,7 +8,6 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.zalando.riptide.Http; -import javax.xml.ws.Endpoint; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.Executors; diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolWriteTest.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolWriteTest.java index ac7f982fd..e4edf307a 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolWriteTest.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/IllegalProtocolWriteTest.java @@ -1,5 +1,6 @@ package org.zalando.riptide.soap; +import jakarta.xml.ws.Endpoint; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -7,7 +8,6 @@ import org.springframework.http.converter.HttpMessageNotWritableException; import org.zalando.riptide.Http; -import javax.xml.ws.Endpoint; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.Executors; diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHello.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHello.java index 26349891a..23eae8bc9 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHello.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHello.java @@ -1,11 +1,10 @@ package org.zalando.riptide.soap; +import jakarta.xml.bind.annotation.XmlType; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import javax.xml.bind.annotation.XmlType; - @XmlType @Data @NoArgsConstructor diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHelloResponse.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHelloResponse.java index 77f90030a..c81ccc64b 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHelloResponse.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/InvalidSayHelloResponse.java @@ -1,6 +1,6 @@ package org.zalando.riptide.soap; -import javax.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlRootElement; @XmlRootElement public class InvalidSayHelloResponse { diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/SOAPTest.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/SOAPTest.java index 8ab7428e3..218452305 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/SOAPTest.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/SOAPTest.java @@ -1,6 +1,9 @@ package org.zalando.riptide.soap; -import org.apache.http.impl.client.HttpClients; +import jakarta.xml.soap.SOAPFault; +import jakarta.xml.ws.Endpoint; +import jakarta.xml.ws.soap.SOAPFaultException; +import org.apache.hc.client5.http.impl.classic.HttpClients; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -11,9 +14,6 @@ import org.zalando.riptide.capture.Capture; import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory; -import javax.xml.soap.SOAPFault; -import javax.xml.ws.Endpoint; -import javax.xml.ws.soap.SOAPFaultException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.Executors; diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHello.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHello.java index b5f10e3c7..61b1ee044 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHello.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHello.java @@ -1,11 +1,10 @@ package org.zalando.riptide.soap; +import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import javax.xml.bind.annotation.XmlRootElement; - @XmlRootElement(name = "sayHello", namespace = "http://soap.riptide.zalando.org/") @Data @NoArgsConstructor diff --git a/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHelloResponse.java b/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHelloResponse.java index 325aee43f..c9f02da1c 100644 --- a/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHelloResponse.java +++ b/riptide-soap/src/test/java/org/zalando/riptide/soap/SayHelloResponse.java @@ -1,11 +1,10 @@ package org.zalando.riptide.soap; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - @XmlRootElement(name = "sayHelloResponse", namespace = "http://soap.riptide.zalando.org/") @NoArgsConstructor @AllArgsConstructor diff --git a/riptide-spring-boot-autoconfigure/pom.xml b/riptide-spring-boot-autoconfigure/pom.xml index ee863c807..8c7d50ac4 100644 --- a/riptide-spring-boot-autoconfigure/pom.xml +++ b/riptide-spring-boot-autoconfigure/pom.xml @@ -98,17 +98,11 @@ riptide-httpclient - org.apache.httpcomponents - httpclient-cache - 4.5.14 + org.apache.httpcomponents.client5 + httpclient5 + 5.2.1 true - - - commons-logging - commons-logging - - org.zalando @@ -304,7 +298,8 @@ **/NoCachingTest.java - org.apache.httpcomponents:httpclient-cache + org.apache.httpcomponents.client5:httpclient5-cache + @@ -327,4 +322,3 @@ - diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java index bd2bcf8f2..3f6c4917c 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java @@ -3,13 +3,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import dev.failsafe.CircuitBreaker; +import dev.failsafe.Timeout; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; import io.opentracing.contrib.concurrent.TracedExecutorService; +import jakarta.xml.soap.SOAPConstants; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import dev.failsafe.CircuitBreaker; -import dev.failsafe.Timeout; import org.apache.http.client.HttpClient; import org.apache.http.client.cache.HttpCacheStorage; import org.apache.http.conn.HttpClientConnectionManager; @@ -20,7 +21,6 @@ import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.client.AsyncRestOperations; import org.springframework.web.client.RestOperations; import org.zalando.riptide.Http; import org.zalando.riptide.OriginalStackTracePlugin; @@ -30,11 +30,7 @@ import org.zalando.riptide.auth.PlatformCredentialsAuthorizationProvider; import org.zalando.riptide.autoconfigure.RiptideProperties.Chaos; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; -import org.zalando.riptide.chaos.ChaosPlugin; -import org.zalando.riptide.chaos.ErrorResponseInjection; -import org.zalando.riptide.chaos.ExceptionInjection; -import org.zalando.riptide.chaos.LatencyInjection; -import org.zalando.riptide.chaos.Probability; +import org.zalando.riptide.chaos.*; import org.zalando.riptide.compatibility.HttpOperations; import org.zalando.riptide.compression.RequestCompressionPlugin; import org.zalando.riptide.failsafe.BackupRequest; @@ -55,15 +51,10 @@ import org.zalando.riptide.soap.SOAPHttpMessageConverter; import org.zalando.riptide.stream.Streams; -import javax.xml.soap.SOAPConstants; import java.net.SocketTimeoutException; import java.net.URI; import java.time.Clock; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.function.Supplier; import java.util.stream.Stream; @@ -77,12 +68,8 @@ import static org.zalando.riptide.autoconfigure.Registry.list; import static org.zalando.riptide.autoconfigure.Registry.ref; import static org.zalando.riptide.autoconfigure.RiptideProperties.Auth; -import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.ErrorResponses; -import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.Exceptions; -import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.Latency; -import static org.zalando.riptide.autoconfigure.ValueConstants.LOGBOOK_REF; -import static org.zalando.riptide.autoconfigure.ValueConstants.METER_REGISTRY_REF; -import static org.zalando.riptide.autoconfigure.ValueConstants.TRACER_REF; +import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.*; +import static org.zalando.riptide.autoconfigure.ValueConstants.*; @Slf4j @AllArgsConstructor From 3741be99f774fde5ead6334241fc9dd40cfd3de6 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:08:14 +0200 Subject: [PATCH 02/32] Fix failsafe tests HTTP Client 5 has a DefaultHttpRequestRetryStrategy, which by default retries 1 time after receiving a 503 status. The mock servers were changed to return a 500 status, so that this behavior does not kick in. --- .../riptide/failsafe/FailsafePluginBackupRequestTest.java | 4 ++-- .../riptide/failsafe/FailsafePluginRetryListenerTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java index 23d33a5fb..2127cbc7d 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; -import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; import static org.zalando.riptide.Bindings.on; @@ -88,7 +88,7 @@ void shouldUseOriginalRequest() throws Throwable { @Test void shouldUseFailedBackupRequest() { server.enqueue(emptyMockResponse().setHeadersDelay(2, SECONDS)); - server.enqueue(new MockResponse().setResponseCode(SERVICE_UNAVAILABLE.value())); + server.enqueue(new MockResponse().setResponseCode(INTERNAL_SERVER_ERROR.value())); final CompletionException exception = assertThrows(CompletionException.class, () -> unit.get("/bar") diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java index 68cc25af0..a4a516874 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetryListenerTest.java @@ -34,7 +34,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.hamcrest.MockitoHamcrest.argThat; import static org.springframework.http.HttpStatus.BAD_GATEWAY; -import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.zalando.riptide.Bindings.anyStatus; import static org.zalando.riptide.Bindings.on; import static org.zalando.riptide.Navigators.status; @@ -130,12 +130,12 @@ void shouldInvokeListenersOnRetryableResult() { @Test void shouldInvokeListenersOnExplicitRetry() { - server.enqueue(new MockResponse().setResponseCode(SERVICE_UNAVAILABLE.value())); + server.enqueue(new MockResponse().setResponseCode(INTERNAL_SERVER_ERROR.value())); server.enqueue(emptyMockResponse()); unit.get("/baz") .dispatch(status(), - on(SERVICE_UNAVAILABLE).call(retry()), + on(INTERNAL_SERVER_ERROR).call(retry()), anyStatus().call(pass())) .join(); From 1602549f5f4880b71feffb249eb9d8da66857c35 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:26:25 +0200 Subject: [PATCH 03/32] Fix Micrometer tests - HTTP Client 5 has a DefaultHttpRequestRetryStrategy, which by default retries 1 time after receiving a 503 status. The mock servers were changed to return a 500 status, so that this behavior does not kick in. - Use setSocketTimeout instead of setConnectTimeout --- .../micrometer/MicrometerPluginTest.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java index 65d45bb8a..508839783 100644 --- a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java +++ b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java @@ -9,9 +9,9 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.core5.util.Timeout; +import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpRequestFactory; @@ -27,6 +27,7 @@ import java.net.URI; import java.util.concurrent.CompletionException; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import static java.util.Collections.singleton; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -48,12 +49,20 @@ final class MicrometerPluginTest { private final MockWebServer server = new MockWebServer(); + private final ConnectionConfig connConfig = ConnectionConfig.custom() + .setSocketTimeout(500, TimeUnit.MILLISECONDS) + .build(); + + private final BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(); + + { + cm.setConnectionConfig(connConfig); + } + private final ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setConnectTimeout(Timeout.ofMilliseconds(500)) - .build()) - .build()); + .setConnectionManager(cm) + .build()); private final MeterRegistry registry = new SimpleMeterRegistry(); @@ -68,12 +77,13 @@ final class MicrometerPluginTest { new StaticTagDecorator(singleton(Tag.of("test", "true")))) .withAdditionalTagGenerators(new RetryTagGenerator())) .plugin(new FailsafePlugin() - .withPolicy(RetryPolicy.builder() - .handleIf(error -> false) - .handleResultIf(toCheckedPredicate(throwingPredicate(response -> response.getStatusCode() - .is5xxServerError()))) - .build())) + .withPolicy(RetryPolicy.builder() + .handleIf(error -> false) + .handleResultIf(toCheckedPredicate(throwingPredicate(response -> response.getStatusCode() + .is5xxServerError()))) + .build())) .build(); + @AfterEach @SneakyThrows void shutdownServer() { @@ -143,7 +153,7 @@ void shouldRecordRetryNumberMetricTag() { @Test void shouldRecordErrorResponseMetric() { - server.enqueue(new MockResponse().setResponseCode(503)); + server.enqueue(new MockResponse().setResponseCode(500)); unit.post(URI.create("/bar")) .dispatch(series(), @@ -156,7 +166,7 @@ void shouldRecordErrorResponseMetric() { assertThat(timer, is(notNullValue())); assertThat(timer.getId().getTag("http.method"), is("POST")); assertThat(timer.getId().getTag("http.path"), is("")); - assertThat(timer.getId().getTag("http.status_code"), is("503")); + assertThat(timer.getId().getTag("http.status_code"), is("500")); assertThat(timer.getId().getTag("peer.hostname"), is("localhost")); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("client"), is("example")); From 029071c72bf979a7e4eb0817b15c5e2aad56f990 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:30:14 +0200 Subject: [PATCH 04/32] Fix OpenTracing tests Use setSocketTimeout instead of setConnectTimeout --- .../opentracing/OpenTracingPluginTest.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java index efe9faf7b..6cd3f119e 100644 --- a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java +++ b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java @@ -7,9 +7,9 @@ import io.opentracing.mock.MockTracer; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.core5.util.Timeout; +import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; @@ -26,6 +26,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import java.util.concurrent.TimeUnit; import static java.util.Collections.singletonMap; import static java.util.concurrent.Executors.newSingleThreadExecutor; @@ -44,12 +45,20 @@ final class OpenTracingPluginTest { private final MockWebServer server = new MockWebServer(); private final MockTracer tracer = new MockTracer(); + private final ConnectionConfig connConfig = ConnectionConfig.custom() + .setSocketTimeout(500, TimeUnit.MILLISECONDS) + .build(); + + private final BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(); + + { + cm.setConnectionConfig(connConfig); + } + private final Http unit = Http.builder() .executor(new TracedExecutorService(newSingleThreadExecutor(), tracer)) .requestFactory(new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setConnectTimeout(Timeout.ofMilliseconds(500)) - .build()) + .setConnectionManager(cm) .build())) .baseUrl(getBaseUrl(server)) .plugin(new OpenTracingPlugin(tracer) @@ -217,23 +226,14 @@ void shouldTraceRequestAndNetworkError() { final LogEntry log = logs.get(i); switch (i) { - case 0: { + case 0 -> { assertThat(log.fields(), hasEntry("error.kind", "SocketTimeoutException")); assertThat(log.fields(), hasEntry(is("error.object"), is(instanceOf(SocketTimeoutException.class)))); - break; - } - case 1: { - assertThat(log.fields().get("stack").toString(), - containsString("java.net.SocketTimeoutException: Read timed out")); - break; - } - case 2: { - assertThat(log.fields(), hasEntry("message", "Read timed out")); - break; - } - default: { - throw new AssertionError(); } + case 1 -> assertThat(log.fields().get("stack").toString(), + containsString("java.net.SocketTimeoutException: Read timed out")); + case 2 -> assertThat(log.fields(), hasEntry("message", "Read timed out")); + default -> throw new AssertionError(); } } From 810791294e8d82f734f44962a42089993860c41a Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:33:25 +0200 Subject: [PATCH 05/32] Fix OpenTelemetry tests Use setSocketTimeout instead of setConnectTimeout --- .../OpenTelemetryPluginTest.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java index 868bbb65f..d9a92a5d5 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java @@ -14,9 +14,9 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.core5.util.Timeout; +import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -41,6 +41,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Stream; @@ -64,14 +65,21 @@ class OpenTelemetryPluginTest { private final SpanDecorator environmentDecorator = new StaticSpanDecorator(singletonMap("env", "unittest")); + private final ConnectionConfig connConfig = ConnectionConfig.custom() + .setSocketTimeout(500, TimeUnit.MILLISECONDS) + .build(); + + private final BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(); + + { + cm.setConnectionConfig(connConfig); + } + private final Http unit = Http.builder() .executor(Executors.newCachedThreadPool()) .requestFactory(new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() - .setDefaultRequestConfig( - RequestConfig.custom() - .setConnectTimeout(Timeout.ofMilliseconds(500)) - .build()) + .setConnectionManager(cm) .build())) .baseUrl(getBaseUrl(server)) .plugin(new OpenTelemetryPlugin(otelTesting.getOpenTelemetry(), @@ -267,10 +275,7 @@ void shouldOverwriteDefaultSetOfDecorators() { .executor(Executors.newCachedThreadPool()) .requestFactory(new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() - .setDefaultRequestConfig( - RequestConfig.custom() - .setConnectTimeout(Timeout.ofMilliseconds(500)) - .build()) + .setConnectionManager(cm) .build())) .baseUrl(getBaseUrl(server)) .plugin(new OpenTelemetryPlugin(otelTesting.getOpenTelemetry()) From 8c6dc4bae406541e6e06a4730315a33fd5d5902d Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:50:37 +0200 Subject: [PATCH 06/32] Fix SOAP tests Use newer version of jaxws-rt dependency --- riptide-soap/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riptide-soap/pom.xml b/riptide-soap/pom.xml index fb6f4cf3f..e1fee2d25 100644 --- a/riptide-soap/pom.xml +++ b/riptide-soap/pom.xml @@ -42,7 +42,7 @@ com.sun.xml.ws jaxws-rt - 2.3.6 + 4.0.1 test From 4b7b7416e6b6dba6fb82d30435c411d45618cfc2 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:54:08 +0200 Subject: [PATCH 07/32] Fix test compilation issues - wip --- .../logbook/LogbookPluginStreamingTest.java | 6 ++---- .../OpenTelemetryPluginRetryTest.java | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java index 589ef81a3..d46a5dc46 100644 --- a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java +++ b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java @@ -3,7 +3,7 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.impl.client.HttpClients; +import org.apache.hc.client5.http.impl.classic.HttpClients; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,9 +29,7 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.OK; import static org.zalando.riptide.PassRoute.pass; diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java index 3c3b7e59c..f1785a0de 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java @@ -11,8 +11,9 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -26,6 +27,7 @@ import java.util.Comparator; import java.util.List; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; @@ -46,14 +48,21 @@ public class OpenTelemetryPluginRetryTest { private final SpanDecorator retryDecorator = new RetrySpanDecorator(); + private final ConnectionConfig connConfig = ConnectionConfig.custom() + .setSocketTimeout(500, TimeUnit.MILLISECONDS) + .build(); + + private final BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(); + + { + cm.setConnectionConfig(connConfig); + } + private final Http unit = Http.builder() .executor(Executors.newCachedThreadPool()) .requestFactory(new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() - .setDefaultRequestConfig( - RequestConfig.custom() - .setSocketTimeout(500) - .build()) + .setConnectionManager(cm) .build())) .baseUrl(getBaseUrl(server)) .plugin(new OpenTelemetryPlugin(otelTesting.getOpenTelemetry(), retryDecorator)) From 3c8f8d553b5eb0a6c830573645154abe4ab733c7 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Mon, 12 Jun 2023 19:28:08 +0200 Subject: [PATCH 08/32] Fix imports for riptide-spring-boot-autoconfigure --- riptide-spring-boot-autoconfigure/pom.xml | 8 +++++- .../DefaultRiptideRegistrar.java | 2 +- .../autoconfigure/HttpClientFactory.java | 15 +++++----- .../autoconfigure/RiptideProperties.java | 4 +-- .../riptide/autoconfigure/TimeSpan.java | 5 ++++ .../riptide/autoconfigure/CachingTest.java | 6 ++-- .../ClientConfigurationTest.java | 5 +--- .../autoconfigure/ManualConfiguration.java | 28 +++++-------------- 8 files changed, 33 insertions(+), 40 deletions(-) diff --git a/riptide-spring-boot-autoconfigure/pom.xml b/riptide-spring-boot-autoconfigure/pom.xml index 8c7d50ac4..b82505a42 100644 --- a/riptide-spring-boot-autoconfigure/pom.xml +++ b/riptide-spring-boot-autoconfigure/pom.xml @@ -100,10 +100,16 @@ org.apache.httpcomponents.client5 httpclient5 - 5.2.1 true + + org.apache.httpcomponents.client5 + httpclient5-cache + + true + + org.zalando riptide-logbook diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java index 3f6c4917c..5bc3fcdc9 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java @@ -11,8 +11,8 @@ import jakarta.xml.soap.SOAPConstants; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.hc.client5.http.cache.HttpCacheStorage; import org.apache.http.client.HttpClient; -import org.apache.http.client.cache.HttpCacheStorage; import org.apache.http.conn.HttpClientConnectionManager; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.config.BeanDefinition; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java index f4ea6c3d4..0eba87dae 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java @@ -2,8 +2,11 @@ import com.google.gag.annotation.remark.Hack; import lombok.extern.slf4j.Slf4j; +import org.apache.hc.client5.http.cache.HttpCacheStorage; +import org.apache.hc.client5.http.impl.cache.CacheConfig; +import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder; +import org.apache.hc.client5.http.impl.cache.CachingHttpClients; import org.apache.http.HttpRequestInterceptor; -import org.apache.http.client.cache.HttpCacheStorage; import org.apache.http.client.config.RequestConfig; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.HttpClientConnectionManager; @@ -12,9 +15,6 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.cache.CacheConfig; -import org.apache.http.impl.client.cache.CachingHttpClientBuilder; -import org.apache.http.impl.client.cache.CachingHttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.ssl.SSLContexts; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching; @@ -24,6 +24,8 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Client; import org.zalando.riptide.autoconfigure.RiptideProperties.Connections; +import javax.annotation.Nullable; +import javax.net.ssl.SSLContext; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; @@ -31,10 +33,7 @@ import java.security.GeneralSecurityException; import java.util.List; import java.util.Optional; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import javax.annotation.Nullable; -import javax.net.ssl.SSLContext; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -110,7 +109,7 @@ private static HttpClientBuilder configureCaching(final Caching caching, if (heuristic.getEnabled()) { config.setHeuristicCachingEnabled(true); config.setHeuristicCoefficient(heuristic.getCoefficient()); - config.setHeuristicDefaultLifetime(heuristic.getDefaultLifeTime().to(TimeUnit.SECONDS)); + config.setHeuristicDefaultLifetime(heuristic.getDefaultLifeTime().toTimeValue()); } @Hack("return cast tricks classloader in case of missing httpclient-cache") diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java index b580340cf..270dca29c 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java @@ -4,7 +4,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.apache.http.impl.client.cache.CacheConfig; +import org.apache.hc.client5.http.impl.cache.CacheConfig; import org.apiguardian.api.API; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -117,7 +117,7 @@ public static final class Defaults { new Heuristic( false, CacheConfig.DEFAULT_HEURISTIC_COEFFICIENT, - TimeSpan.of(CacheConfig.DEFAULT_HEURISTIC_LIFETIME, SECONDS) + TimeSpan.of(CacheConfig.DEFAULT_HEURISTIC_LIFETIME.toSeconds(), SECONDS) ) ); diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java index cdc2f382c..f09daba17 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableBiMap; import lombok.AllArgsConstructor; import lombok.Getter; +import org.apache.hc.core5.util.TimeValue; import java.time.Duration; import java.time.temporal.ChronoUnit; @@ -58,6 +59,10 @@ Duration toDuration() { return Duration.of(amount, UNIT_MAPPING.get(unit)); } + TimeValue toTimeValue() { + return TimeValue.of(amount, unit); + } + void applyTo(final BiConsumer consumer) { consumer.accept(amount, unit); } diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java index 4825f0ea5..6116a4590 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java @@ -3,9 +3,9 @@ import lombok.SneakyThrows; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; -import org.apache.http.client.cache.HttpCacheStorage; -import org.apache.http.impl.client.cache.BasicHttpCacheStorage; -import org.apache.http.impl.client.cache.CacheConfig; +import org.apache.hc.client5.http.cache.HttpCacheStorage; +import org.apache.hc.client5.http.impl.cache.BasicHttpCacheStorage; +import org.apache.hc.client5.http.impl.cache.CacheConfig; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java index 6ca3dc40c..85be2c220 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java @@ -9,14 +9,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.stereotype.Component; import org.springframework.test.context.TestPropertySource; -import org.springframework.web.client.AsyncRestOperations; import org.springframework.web.client.RestOperations; import org.zalando.riptide.Http; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; @SpringBootTest(classes = DefaultTestConfiguration.class, webEnvironment = NONE) diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java index 777390d49..dfe2fef0c 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java @@ -1,6 +1,9 @@ package org.zalando.riptide.autoconfigure; import com.fasterxml.jackson.databind.ObjectMapper; +import dev.failsafe.CircuitBreaker; +import dev.failsafe.RetryPolicy; +import dev.failsafe.Timeout; import dev.failsafe.function.CheckedPredicate; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; @@ -8,9 +11,6 @@ import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics; import io.opentracing.Tracer; import io.opentracing.contrib.concurrent.TracedExecutorService; -import dev.failsafe.CircuitBreaker; -import dev.failsafe.RetryPolicy; -import dev.failsafe.Timeout; import org.apache.http.client.config.RequestConfig; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.HttpClientBuilder; @@ -26,7 +26,6 @@ import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; -import org.springframework.web.client.AsyncRestOperations; import org.springframework.web.client.RestOperations; import org.zalando.logbook.Logbook; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; @@ -40,21 +39,11 @@ import org.zalando.riptide.auth.AuthorizationPlugin; import org.zalando.riptide.auth.PlatformCredentialsAuthorizationProvider; import org.zalando.riptide.autoconfigure.PluginTest.CustomPlugin; -import org.zalando.riptide.chaos.ChaosPlugin; -import org.zalando.riptide.chaos.ErrorResponseInjection; -import org.zalando.riptide.chaos.ExceptionInjection; -import org.zalando.riptide.chaos.LatencyInjection; -import org.zalando.riptide.chaos.Probability; +import org.zalando.riptide.chaos.*; import org.zalando.riptide.compatibility.HttpOperations; import org.zalando.riptide.compression.RequestCompressionPlugin; import org.zalando.riptide.concurrent.ThreadPoolExecutors; -import org.zalando.riptide.failsafe.BackupRequest; -import org.zalando.riptide.failsafe.CircuitBreakerListener; -import org.zalando.riptide.failsafe.CompositeDelayFunction; -import org.zalando.riptide.failsafe.FailsafePlugin; -import org.zalando.riptide.failsafe.RateLimitResetDelayFunction; -import org.zalando.riptide.failsafe.RetryAfterDelayFunction; -import org.zalando.riptide.failsafe.RetryRequestPolicy; +import org.zalando.riptide.failsafe.*; import org.zalando.riptide.failsafe.metrics.MetricsCircuitBreakerListener; import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory; import org.zalando.riptide.idempotency.IdempotencyPredicate; @@ -70,7 +59,6 @@ import java.net.SocketTimeoutException; import java.time.Clock; import java.time.Duration; -import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; @@ -81,9 +69,7 @@ import static java.time.temporal.ChronoUnit.MILLIS; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.MINUTES; -import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.concurrent.TimeUnit.*; import static javax.net.ssl.HttpsURLConnection.getDefaultHostnameVerifier; import static org.zalando.riptide.chaos.FailureInjection.composite; import static org.zalando.riptide.faults.Predicates.alwaysTrue; @@ -177,7 +163,7 @@ public List examplePlugins(final MeterRegistry meterRegistry, final Logb private RetryPolicy retryPolicy( final Predicate predicate) { - final CheckedPredicate checkedPredicate = t -> predicate.test(t); + final CheckedPredicate checkedPredicate = predicate::test; return RetryPolicy.builder() .handleIf(checkedPredicate) From 7374312bfaec5277302d9cd5627e9c477b45e7f6 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Tue, 13 Jun 2023 03:28:40 +0200 Subject: [PATCH 09/32] WIP - Initial changes to Spring Boot module --- .../ApacheClientHttpRequestFactory.java | 3 +- .../OpenTelemetryPluginRetryTest.java | 16 ++-- riptide-spring-boot-autoconfigure/pom.xml | 12 +++ .../riptide/autoconfigure/BaseURL.java | 5 +- .../ClientHttpMessageConverters.java | 3 +- .../DefaultRiptideConfigurer.java | 13 ++- .../DefaultRiptideRegistrar.java | 37 ++++--- .../riptide/autoconfigure/Defaulting.java | 13 ++- .../autoconfigure/FailsafePluginFactory.java | 18 ++-- .../autoconfigure/FlowAutoConfiguration.java | 37 +++++++ .../autoconfigure/HttpClientCustomizer.java | 2 +- .../autoconfigure/HttpClientFactory.java | 96 +++++++++---------- .../riptide/autoconfigure/HttpFactory.java | 7 +- .../MicrometerPluginFactory.java | 3 +- .../zalando/riptide/autoconfigure/Name.java | 5 +- .../OpenTracingPluginFactory.java | 7 +- .../zalando/riptide/autoconfigure/Ratio.java | 5 +- .../autoconfigure/RatioInTimeSpan.java | 3 +- .../riptide/autoconfigure/Registry.java | 9 +- .../RiptideAutoConfiguration.java | 2 +- .../autoconfigure/RiptideClientTest.java | 11 +-- .../autoconfigure/RiptidePostProcessor.java | 3 +- .../autoconfigure/RiptideProperties.java | 15 ++- .../autoconfigure/ThreadPoolFactory.java | 3 +- .../riptide/autoconfigure/TimeSpan.java | 12 ++- .../TracerAutoConfiguration.java | 12 +++ .../AccessTokensCredentialsDirectoryTest.java | 3 +- .../riptide/autoconfigure/BaseURLTest.java | 12 +-- .../autoconfigure/CircuitBreakerTest.java | 3 +- .../ClientConfigurationTest.java | 54 +++++++---- .../DefaultTestConfiguration.java | 3 +- .../riptide/autoconfigure/DefaultingTest.java | 3 +- .../autoconfigure/HttpClientFactoryTest.java | 5 +- .../HttpMessageConvertersTest.java | 3 +- .../KeystoreIntegrationTest.java | 3 +- .../autoconfigure/ManualConfiguration.java | 89 ++++++++++------- .../autoconfigure/MockWebServerUtil.java | 7 +- .../riptide/autoconfigure/NameTest.java | 9 +- .../riptide/autoconfigure/NoCachingTest.java | 3 +- .../riptide/autoconfigure/PluginTest.java | 6 +- .../autoconfigure/RatioInTimeSpanTest.java | 3 +- .../riptide/autoconfigure/RatioTest.java | 3 +- .../riptide/autoconfigure/TimeSpanTest.java | 3 +- .../autoconfigure/metrics/MetricsTest.java | 5 +- .../autoconfigure/retry/RetryTest.java | 3 +- 45 files changed, 325 insertions(+), 247 deletions(-) create mode 100644 riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java create mode 100644 riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java index b1a4e3f74..eb4ea04d0 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import org.apache.hc.client5.http.classic.HttpClient; import org.apache.hc.client5.http.classic.methods.*; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apiguardian.api.API; import org.springframework.beans.factory.DisposableBean; import org.springframework.http.HttpMethod; @@ -41,7 +42,7 @@ public enum Mode { private final HttpClient client; private final Mode mode; - public ApacheClientHttpRequestFactory(final HttpClient client) { + public ApacheClientHttpRequestFactory(final CloseableHttpClient client) { this(client, Mode.STREAMING); } diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java index f1785a0de..f00b5e894 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginRetryTest.java @@ -13,7 +13,8 @@ import okhttp3.mockwebserver.MockWebServer; import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -52,17 +53,15 @@ public class OpenTelemetryPluginRetryTest { .setSocketTimeout(500, TimeUnit.MILLISECONDS) .build(); - private final BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(); - - { - cm.setConnectionConfig(connConfig); - } + private final HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(connConfig) + .build(); private final Http unit = Http.builder() .executor(Executors.newCachedThreadPool()) .requestFactory(new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() - .setConnectionManager(cm) + .setConnectionManager(connectionManager) .build())) .baseUrl(getBaseUrl(server)) .plugin(new OpenTelemetryPlugin(otelTesting.getOpenTelemetry(), retryDecorator)) @@ -90,7 +89,8 @@ void shouldTraceRetries() { try (final Scope ignored = parent.makeCurrent()) { unit.get("/") .call(pass()) - .join(); + .join() + .close(); } finally { parent.end(); } diff --git a/riptide-spring-boot-autoconfigure/pom.xml b/riptide-spring-boot-autoconfigure/pom.xml index b82505a42..079bf8597 100644 --- a/riptide-spring-boot-autoconfigure/pom.xml +++ b/riptide-spring-boot-autoconfigure/pom.xml @@ -157,12 +157,24 @@ opentracing-flowid-starter 4.2.3 true + + + org.apache.httpcomponents + httpclient + + org.zalando logbook-spring-boot-autoconfigure ${logbook.version} true + + + org.zalando + logbook-httpclient + + diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java index aa2dbcb17..ddda9d3c8 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java @@ -1,10 +1,9 @@ package org.zalando.riptide.autoconfigure; -import org.apiguardian.api.API; - -import javax.annotation.Nullable; import java.net.URI; import java.util.function.Supplier; +import javax.annotation.Nullable; +import org.apiguardian.api.API; import static org.apiguardian.api.API.Status.EXPERIMENTAL; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java index efc922502..a5cb8063d 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java @@ -1,12 +1,11 @@ package org.zalando.riptide.autoconfigure; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; import org.apiguardian.api.API; import org.springframework.http.converter.HttpMessageConverter; -import java.util.List; - import static org.apiguardian.api.API.Status.STABLE; @API(status = STABLE) diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java index 991540cd7..03137638d 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java @@ -3,6 +3,12 @@ import com.google.common.annotations.VisibleForTesting; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Predicate; import lombok.AllArgsConstructor; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -13,13 +19,6 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder; import org.zalando.logbook.Logbook; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Predicate; - import static org.zalando.riptide.autoconfigure.ValueConstants.LOGBOOK_REF; import static org.zalando.riptide.autoconfigure.ValueConstants.METER_REGISTRY_REF; import static org.zalando.riptide.autoconfigure.ValueConstants.TRACER_REF; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java index 5bc3fcdc9..f5ab67674 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java @@ -9,11 +9,22 @@ import io.micrometer.core.instrument.Tags; import io.opentracing.contrib.concurrent.TracedExecutorService; import jakarta.xml.soap.SOAPConstants; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.time.Clock; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; +import java.util.stream.Stream; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.hc.client5.http.cache.HttpCacheStorage; -import org.apache.http.client.HttpClient; -import org.apache.http.conn.HttpClientConnectionManager; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanReference; @@ -30,7 +41,11 @@ import org.zalando.riptide.auth.PlatformCredentialsAuthorizationProvider; import org.zalando.riptide.autoconfigure.RiptideProperties.Chaos; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; -import org.zalando.riptide.chaos.*; +import org.zalando.riptide.chaos.ChaosPlugin; +import org.zalando.riptide.chaos.ErrorResponseInjection; +import org.zalando.riptide.chaos.ExceptionInjection; +import org.zalando.riptide.chaos.LatencyInjection; +import org.zalando.riptide.chaos.Probability; import org.zalando.riptide.compatibility.HttpOperations; import org.zalando.riptide.compression.RequestCompressionPlugin; import org.zalando.riptide.failsafe.BackupRequest; @@ -51,14 +66,6 @@ import org.zalando.riptide.soap.SOAPHttpMessageConverter; import org.zalando.riptide.stream.Streams; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.time.Clock; -import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.function.Supplier; -import java.util.stream.Stream; - import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toCollection; import static java.util.stream.Collectors.toList; @@ -68,8 +75,12 @@ import static org.zalando.riptide.autoconfigure.Registry.list; import static org.zalando.riptide.autoconfigure.Registry.ref; import static org.zalando.riptide.autoconfigure.RiptideProperties.Auth; -import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.*; -import static org.zalando.riptide.autoconfigure.ValueConstants.*; +import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.ErrorResponses; +import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.Exceptions; +import static org.zalando.riptide.autoconfigure.RiptideProperties.Chaos.Latency; +import static org.zalando.riptide.autoconfigure.ValueConstants.LOGBOOK_REF; +import static org.zalando.riptide.autoconfigure.ValueConstants.METER_REGISTRY_REF; +import static org.zalando.riptide.autoconfigure.ValueConstants.TRACER_REF; @Slf4j @AllArgsConstructor diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java index d829b352f..e963716b1 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java @@ -2,6 +2,12 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.function.BinaryOperator; +import javax.annotation.Nullable; import lombok.extern.slf4j.Slf4j; import org.zalando.riptide.autoconfigure.RiptideProperties.Auth; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching; @@ -24,13 +30,6 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Tracing; import org.zalando.riptide.autoconfigure.RiptideProperties.TransientFaultDetection; -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.function.BinaryOperator; - import static com.google.common.collect.Maps.transformValues; import static java.lang.Math.max; import static java.util.Objects.requireNonNull; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java index 53f343032..604742b49 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java @@ -5,15 +5,20 @@ import dev.failsafe.RetryPolicy; import dev.failsafe.RetryPolicyBuilder; import dev.failsafe.Timeout; -import dev.failsafe.function.CheckedPredicate; import dev.failsafe.function.ContextualSupplier; +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; +import javax.annotation.Nullable; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.Plugin; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; import org.zalando.riptide.autoconfigure.RiptideProperties.Retry; import org.zalando.riptide.autoconfigure.RiptideProperties.Retry.Backoff; import org.zalando.riptide.failsafe.BackupRequest; -import org.zalando.riptide.failsafe.CheckedPredicateConverter; import org.zalando.riptide.failsafe.CircuitBreakerListener; import org.zalando.riptide.failsafe.CompositeDelayFunction; import org.zalando.riptide.failsafe.FailsafePlugin; @@ -25,15 +30,6 @@ import org.zalando.riptide.failsafe.TaskDecorator; import org.zalando.riptide.idempotency.IdempotencyPredicate; -import javax.annotation.Nullable; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import java.util.function.Predicate; - import static java.time.Clock.systemUTC; import static java.time.temporal.ChronoUnit.MILLIS; import static java.util.concurrent.TimeUnit.MILLISECONDS; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java new file mode 100644 index 000000000..4499e7db8 --- /dev/null +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java @@ -0,0 +1,37 @@ +package org.zalando.riptide.autoconfigure; + +import io.opentracing.Tracer; +import org.apache.hc.core5.http.EntityDetails; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.HttpRequestInterceptor; +import org.apache.hc.core5.http.protocol.HttpContext; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.zalando.opentracing.flowid.Flow; + +public class FlowAutoConfiguration { + + @Bean + public Flow flow(final Tracer tracer) { + return Flow.create(tracer); + } + + static class FlowHttpRequestInterceptor implements HttpRequestInterceptor { + private final Flow flow; + + public FlowHttpRequestInterceptor(final Flow flow) { + this.flow = flow; + } + + @Override + public void process(HttpRequest httpRequest, EntityDetails entityDetails, HttpContext httpContext) { + this.flow.writeTo(httpRequest::addHeader); + } + } + + @Bean + @ConditionalOnMissingBean({FlowHttpRequestInterceptor.class}) + public FlowHttpRequestInterceptor flowHttpRequestInterceptor(final Flow flow) { + return new FlowHttpRequestInterceptor(flow); + } +} diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientCustomizer.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientCustomizer.java index 3278cf51d..df80aac63 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientCustomizer.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientCustomizer.java @@ -1,6 +1,6 @@ package org.zalando.riptide.autoconfigure; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apiguardian.api.API; import static org.apiguardian.api.API.Status.STABLE; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java index 0eba87dae..397b8d1c0 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java @@ -1,22 +1,33 @@ package org.zalando.riptide.autoconfigure; import com.google.gag.annotation.remark.Hack; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; +import javax.annotation.Nullable; +import javax.net.ssl.SSLContext; import lombok.extern.slf4j.Slf4j; import org.apache.hc.client5.http.cache.HttpCacheStorage; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.cache.CacheConfig; import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder; import org.apache.hc.client5.http.impl.cache.CachingHttpClients; -import org.apache.http.HttpRequestInterceptor; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.HttpClientConnectionManager; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.ssl.SSLContexts; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.socket.ConnectionSocketFactory; +import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.http.HttpRequestInterceptor; +import org.apache.hc.core5.http.config.RegistryBuilder; +import org.apache.hc.core5.ssl.SSLContexts; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching.Heuristic; import org.zalando.riptide.autoconfigure.RiptideProperties.CertificatePinning; @@ -24,19 +35,7 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Client; import org.zalando.riptide.autoconfigure.RiptideProperties.Connections; -import javax.annotation.Nullable; -import javax.net.ssl.SSLContext; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Path; -import java.security.GeneralSecurityException; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - import static java.lang.String.format; -import static java.util.concurrent.TimeUnit.MILLISECONDS; @SuppressWarnings("unused") @Slf4j @@ -55,12 +54,7 @@ public static HttpClientConnectionManager createHttpClientConnectionManager(fina RegistryBuilder.create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new SSLConnectionSocketFactory(createSSLContext(client))) - .build(), - null, // connection factory - null, // scheme port resolver - null, // dns resolver - connections.getTimeToLive().getAmount(), - connections.getTimeToLive().getUnit()); + .build()); manager.setMaxTotal(connections.getMaxTotal()); manager.setDefaultMaxPerRoute(connections.getMaxPerRoute()); @@ -69,28 +63,34 @@ public static HttpClientConnectionManager createHttpClientConnectionManager(fina } public static CloseableHttpClient createHttpClient(final Client client, - final List firstRequestInterceptors, - final HttpClientConnectionManager connectionManager, - @Nullable final HttpClientCustomizer customizer, - @Nullable final Object cacheStorage) { + final List firstRequestInterceptors, + final PoolingHttpClientConnectionManager connectionManager, + @Nullable final HttpClientCustomizer customizer, + @Nullable final Object cacheStorage) { final Caching caching = client.getCaching(); final HttpClientBuilder builder = caching.getEnabled() ? configureCaching(caching, cacheStorage) : HttpClientBuilder.create(); - final RequestConfig.Builder config = RequestConfig.custom(); + final Connections connections = client.getConnections(); + + final ConnectionConfig connectionConfig = ConnectionConfig.custom() + .setConnectTimeout(connections.getConnectTimeout().toTimeout()) + .setSocketTimeout(connections.getSocketTimeout().toTimeout()) + .build(); - firstRequestInterceptors.forEach(builder::addInterceptorFirst); + connectionManager.setDefaultConnectionConfig(connectionConfig); - final Connections connections = client.getConnections(); - config.setConnectionRequestTimeout((int) connections.getLeaseRequestTimeout().to(MILLISECONDS)); - config.setConnectTimeout((int) connections.getConnectTimeout().to(MILLISECONDS)); - config.setSocketTimeout((int) connections.getSocketTimeout().to(MILLISECONDS)); + firstRequestInterceptors.forEach(builder::addRequestInterceptorFirst); + + final RequestConfig reqConfig = RequestConfig.custom() + .setConnectionRequestTimeout(connections.getLeaseRequestTimeout().toTimeout()) + .build(); - builder.setConnectionManager(connectionManager); - builder.setDefaultRequestConfig(config.build()); - builder.disableAutomaticRetries(); + builder.setConnectionManager(connectionManager) + .setDefaultRequestConfig(reqConfig) + .disableAutomaticRetries(); Optional.ofNullable(customizer).ifPresent(customize(builder)); @@ -98,7 +98,7 @@ public static CloseableHttpClient createHttpClient(final Client client, } private static HttpClientBuilder configureCaching(final Caching caching, - @Nullable final Object cacheStorage) { + @Nullable final Object cacheStorage) { final Heuristic heuristic = caching.getHeuristic(); final CacheConfig.Builder config = CacheConfig.custom() @@ -114,11 +114,11 @@ private static HttpClientBuilder configureCaching(final Caching caching, @Hack("return cast tricks classloader in case of missing httpclient-cache") CachingHttpClientBuilder builder = CachingHttpClients.custom() - .setCacheConfig(config.build()) - .setHttpCacheStorage((HttpCacheStorage) cacheStorage) - .setCacheDir(Optional.ofNullable(caching.getDirectory()) - .map(Path::toFile) - .orElse(null)); + .setCacheConfig(config.build()) + .setHttpCacheStorage((HttpCacheStorage) cacheStorage) + .setCacheDir(Optional.ofNullable(caching.getDirectory()) + .map(Path::toFile) + .orElse(null)); return HttpClientBuilder.class.cast(builder); } diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java index 22bb35ee9..b3add26df 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java @@ -1,5 +1,8 @@ package org.zalando.riptide.autoconfigure; +import java.util.List; +import java.util.concurrent.Executor; +import javax.annotation.Nullable; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.zalando.riptide.Http; @@ -7,10 +10,6 @@ import org.zalando.riptide.Plugin; import org.zalando.riptide.UrlResolution; -import javax.annotation.Nullable; -import java.util.List; -import java.util.concurrent.Executor; - @SuppressWarnings("unused") final class HttpFactory { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java index a3aaf0517..f2c982d2f 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java @@ -2,12 +2,11 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; +import java.util.Collection; import org.zalando.riptide.Plugin; import org.zalando.riptide.micrometer.MicrometerPlugin; import org.zalando.riptide.micrometer.tag.TagGenerator; -import java.util.Collection; - final class MicrometerPluginFactory { private MicrometerPluginFactory() { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java index ba6f318e0..8dc9e0d0b 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java @@ -1,13 +1,12 @@ package org.zalando.riptide.autoconfigure; -import lombok.AllArgsConstructor; - -import javax.annotation.Nullable; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; +import javax.annotation.Nullable; +import lombok.AllArgsConstructor; import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.LOWER_HYPHEN; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java index 407f4b399..5bc024b0f 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java @@ -1,6 +1,9 @@ package org.zalando.riptide.autoconfigure; import io.opentracing.Tracer; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; import org.zalando.riptide.Plugin; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; import org.zalando.riptide.opentracing.OpenTracingPlugin; @@ -8,10 +11,6 @@ import org.zalando.riptide.opentracing.span.SpanDecorator; import org.zalando.riptide.opentracing.span.StaticSpanDecorator; -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - import static org.zalando.riptide.opentracing.span.CompositeSpanDecorator.composite; @SuppressWarnings("unused") diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java index 1a2b5c1bb..e591f04c9 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java @@ -1,12 +1,11 @@ package org.zalando.riptide.autoconfigure; -import lombok.AllArgsConstructor; -import lombok.Getter; - import java.util.Optional; import java.util.function.BiConsumer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.AllArgsConstructor; +import lombok.Getter; @AllArgsConstructor @Getter diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java index b6879f8c1..33cfaceef 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java @@ -1,10 +1,9 @@ package org.zalando.riptide.autoconfigure; -import lombok.Getter; - import java.time.Duration; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.Getter; @Getter final class RatioInTimeSpan { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java index d75fbbae7..7de9f880d 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java @@ -1,5 +1,9 @@ package org.zalando.riptide.autoconfigure; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.Supplier; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; @@ -11,11 +15,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.ManagedList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.function.Supplier; - import static org.zalando.riptide.autoconfigure.Name.name; @AllArgsConstructor diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java index c6f07fa4c..9c8fc9ae5 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java @@ -14,7 +14,7 @@ @AutoConfigureAfter(name = { "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration", "org.zalando.logbook.autoconfigure.LogbookAutoConfiguration", - "org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration", + "org.zalando.riptide.autoconfigure.FlowAutoConfiguration", "org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration", "org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration", }) diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java index 8a3f25017..e8c035151 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java @@ -1,17 +1,16 @@ package org.zalando.riptide.autoconfigure; -import org.apiguardian.api.API; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer; -import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; -import org.springframework.core.annotation.AliasFor; - import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.apiguardian.api.API; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer; +import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; +import org.springframework.core.annotation.AliasFor; import static org.apiguardian.api.API.Status.EXPERIMENTAL; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java index 147ae7551..944b48079 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java @@ -1,5 +1,6 @@ package org.zalando.riptide.autoconfigure; +import java.util.function.BiFunction; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -11,8 +12,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; -import java.util.function.BiFunction; - import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from; final class RiptidePostProcessor implements BeanDefinitionRegistryPostProcessor, EnvironmentAware { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java index 270dca29c..5c061f7f5 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java @@ -1,5 +1,12 @@ package org.zalando.riptide.autoconfigure; +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -17,14 +24,6 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Retry.Backoff; import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory.Mode; -import java.net.URI; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import static java.util.Collections.emptyMap; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java index d3150b6d3..a8a8c622a 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java @@ -1,11 +1,10 @@ package org.zalando.riptide.autoconfigure; +import java.util.concurrent.ThreadPoolExecutor; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.zalando.riptide.autoconfigure.RiptideProperties.Threads; import org.zalando.riptide.concurrent.ThreadPoolExecutors; -import java.util.concurrent.ThreadPoolExecutor; - import static org.zalando.riptide.concurrent.ThreadPoolExecutors.builder; @SuppressWarnings("unused") diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java index f09daba17..234c64cc2 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java @@ -2,10 +2,6 @@ import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.apache.hc.core5.util.TimeValue; - import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Arrays; @@ -16,6 +12,10 @@ import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; @@ -63,6 +63,10 @@ TimeValue toTimeValue() { return TimeValue.of(amount, unit); } + Timeout toTimeout() { + return Timeout.of(amount, unit); + } + void applyTo(final BiConsumer consumer) { consumer.accept(amount, unit); } diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java new file mode 100644 index 000000000..05bc965c5 --- /dev/null +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java @@ -0,0 +1,12 @@ +package org.zalando.riptide.autoconfigure; + +import io.opentracing.Tracer; +import io.opentracing.noop.NoopTracerFactory; +import org.springframework.context.annotation.Bean; + +public class TracerAutoConfiguration { + @Bean + public Tracer tracer() { + return NoopTracerFactory.create(); + } +} diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java index 926434445..65e9444db 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java @@ -1,5 +1,6 @@ package org.zalando.riptide.autoconfigure; +import java.io.IOException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -11,8 +12,6 @@ import org.springframework.test.context.ActiveProfiles; import org.zalando.riptide.auth.AuthorizationProvider; -import java.io.IOException; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java index fdc1c6fd3..b40655718 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java @@ -1,9 +1,9 @@ package org.zalando.riptide.autoconfigure; +import java.net.URI; +import java.util.concurrent.atomic.AtomicReference; import lombok.SneakyThrows; import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -14,12 +14,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ActiveProfiles; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.Http; -import java.net.URI; -import java.util.concurrent.atomic.AtomicReference; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; @@ -36,9 +32,9 @@ final class BaseURLTest { RiptideAutoConfiguration.class, JacksonAutoConfiguration.class, LogbookAutoConfiguration.class, - OpenTracingFlowIdAutoConfiguration.class, - OpenTracingTestAutoConfiguration.class, MetricsTestAutoConfiguration.class, + FlowAutoConfiguration.class, + TracerAutoConfiguration.class, }) public static class TestConfiguration { diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java index 7053faa2e..5645169f5 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java @@ -1,6 +1,7 @@ package org.zalando.riptide.autoconfigure; import dev.failsafe.CircuitBreaker; +import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -9,8 +10,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.stereotype.Component; -import java.util.List; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java index 85be2c220..8fbc6a9d1 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java @@ -1,8 +1,13 @@ package org.zalando.riptide.autoconfigure; -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.Configurable; +import java.lang.reflect.Field; +import java.util.concurrent.TimeUnit; +import org.apache.hc.client5.http.HttpRoute; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.function.Resolver; +import org.apache.hc.core5.util.Timeout; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -13,21 +18,22 @@ import org.zalando.riptide.Http; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; @SpringBootTest(classes = DefaultTestConfiguration.class, webEnvironment = NONE) @TestPropertySource(properties = { - "riptide.defaults.connections.connect-timeout: 1 second", - "riptide.defaults.connections.socket-timeout: 2 seconds", - "riptide.defaults.connections.time-to-live: 1 minute", - "riptide.defaults.connections.max-per-route: 12", - "riptide.defaults.connections.max-total: 12", - "riptide.clients.example.connections.connect-timeout: 12 minutes", - "riptide.clients.example.connections.socket-timeout: 34 hours", - "riptide.clients.example.connections.time-to-live: 1 day", - "riptide.clients.example.connections.max-per-route: 24", - "riptide.clients.example.connections.max-total: 24", + "riptide.defaults.connections.connect-timeout: 1 second", + "riptide.defaults.connections.socket-timeout: 2 seconds", + "riptide.defaults.connections.time-to-live: 1 minute", + "riptide.defaults.connections.max-per-route: 12", + "riptide.defaults.connections.max-total: 12", + "riptide.clients.example.connections.connect-timeout: 12 minutes", + "riptide.clients.example.connections.socket-timeout: 34 hours", + "riptide.clients.example.connections.time-to-live: 1 day", + "riptide.clients.example.connections.max-per-route: 24", + "riptide.clients.example.connections.max-total: 24", }) @Component final class ClientConfigurationTest { @@ -60,13 +66,23 @@ void shouldWireNonOAuthCorrectly() { } @Test - void shouldApplyTimeouts() { - assertThat("Configurable http client expected", exampleHttpClient, is(instanceOf(Configurable.class))); + void shouldApplyTimeouts() throws NoSuchFieldException, IllegalAccessException { + Field connManagerField = exampleHttpClient.getClass().getDeclaredField("connManager"); + connManagerField.setAccessible(true); + PoolingHttpClientConnectionManager connManager = + (PoolingHttpClientConnectionManager) connManagerField.get(exampleHttpClient); - final RequestConfig config = ((Configurable) exampleHttpClient).getConfig(); - assertThat(config.getSocketTimeout(), is(34 * 60 * 60 * 1000)); - assertThat(config.getConnectTimeout(), is(12 * 60 * 1000)); + Field connectionConfigResolverField = connManager.getClass().getDeclaredField("connectionConfigResolver"); + connectionConfigResolverField.setAccessible(true); + @SuppressWarnings("unchecked") + Resolver connectionConfigResolver = + (Resolver) connectionConfigResolverField.get(connManager); + + ConnectionConfig connectionConfig = connectionConfigResolver.resolve(null); + + assertThat(connectionConfig.getSocketTimeout(), is(Timeout.of(34, TimeUnit.HOURS))); + assertThat(connectionConfig.getConnectTimeout(), is(Timeout.of(12, TimeUnit.MINUTES))); } } diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java index a8a7fc848..b30684136 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java @@ -5,15 +5,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ActiveProfiles; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; @Configuration @ImportAutoConfiguration({ RiptideAutoConfiguration.class, JacksonAutoConfiguration.class, LogbookAutoConfiguration.class, - OpenTracingFlowIdAutoConfiguration.class, OpenTracingTestAutoConfiguration.class, + FlowAutoConfiguration.class, MetricsTestAutoConfiguration.class, }) @ActiveProfiles("default") diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java index f9dc3be3c..0103a52b9 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java @@ -1,5 +1,6 @@ package org.zalando.riptide.autoconfigure; +import java.nio.file.Paths; import org.junit.jupiter.api.Test; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching.Heuristic; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; @@ -7,8 +8,6 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Defaults; import org.zalando.riptide.autoconfigure.RiptideProperties.Threads; -import java.nio.file.Paths; - import static java.util.concurrent.TimeUnit.HOURS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java index b86db94d7..8920753b8 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java @@ -1,14 +1,13 @@ package org.zalando.riptide.autoconfigure; import com.google.common.collect.ImmutableMap; +import java.io.FileNotFoundException; +import java.io.IOException; import org.junit.jupiter.api.Test; import org.zalando.riptide.autoconfigure.RiptideProperties.CertificatePinning; import org.zalando.riptide.autoconfigure.RiptideProperties.CertificatePinning.Keystore; import org.zalando.riptide.autoconfigure.RiptideProperties.Defaults; -import java.io.FileNotFoundException; -import java.io.IOException; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java index 6bab0ed6c..cec729284 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java @@ -1,5 +1,6 @@ package org.zalando.riptide.autoconfigure; +import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -9,8 +10,6 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.stereotype.Component; -import java.util.List; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java index 08785a5e6..9039ec5e2 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java @@ -1,13 +1,12 @@ package org.zalando.riptide.autoconfigure; +import javax.net.ssl.SSLHandshakeException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.zalando.riptide.Http; -import javax.net.ssl.SSLHandshakeException; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java index dfe2fef0c..67af67ea5 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java @@ -11,10 +11,21 @@ import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics; import io.opentracing.Tracer; import io.opentracing.contrib.concurrent.TracedExecutorService; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.ssl.SSLContexts; +import io.opentracing.noop.NoopTracerFactory; +import java.net.SocketTimeoutException; +import java.time.Clock; +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.function.Predicate; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.ssl.SSLContexts; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -31,7 +42,6 @@ import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; import org.zalando.opentracing.flowid.Flow; import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; -import org.zalando.opentracing.flowid.httpclient.FlowHttpRequestInterceptor; import org.zalando.riptide.Http; import org.zalando.riptide.OriginalStackTracePlugin; import org.zalando.riptide.Plugin; @@ -39,11 +49,21 @@ import org.zalando.riptide.auth.AuthorizationPlugin; import org.zalando.riptide.auth.PlatformCredentialsAuthorizationProvider; import org.zalando.riptide.autoconfigure.PluginTest.CustomPlugin; -import org.zalando.riptide.chaos.*; +import org.zalando.riptide.chaos.ChaosPlugin; +import org.zalando.riptide.chaos.ErrorResponseInjection; +import org.zalando.riptide.chaos.ExceptionInjection; +import org.zalando.riptide.chaos.LatencyInjection; +import org.zalando.riptide.chaos.Probability; import org.zalando.riptide.compatibility.HttpOperations; import org.zalando.riptide.compression.RequestCompressionPlugin; import org.zalando.riptide.concurrent.ThreadPoolExecutors; -import org.zalando.riptide.failsafe.*; +import org.zalando.riptide.failsafe.BackupRequest; +import org.zalando.riptide.failsafe.CircuitBreakerListener; +import org.zalando.riptide.failsafe.CompositeDelayFunction; +import org.zalando.riptide.failsafe.FailsafePlugin; +import org.zalando.riptide.failsafe.RateLimitResetDelayFunction; +import org.zalando.riptide.failsafe.RetryAfterDelayFunction; +import org.zalando.riptide.failsafe.RetryRequestPolicy; import org.zalando.riptide.failsafe.metrics.MetricsCircuitBreakerListener; import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory; import org.zalando.riptide.idempotency.IdempotencyPredicate; @@ -56,21 +76,14 @@ import org.zalando.riptide.soap.SOAPHttpMessageConverter; import org.zalando.riptide.stream.Streams; -import java.net.SocketTimeoutException; -import java.time.Clock; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.function.Predicate; - import static java.time.Clock.systemUTC; import static java.time.temporal.ChronoUnit.MILLIS; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; -import static java.util.concurrent.TimeUnit.*; -import static javax.net.ssl.HttpsURLConnection.getDefaultHostnameVerifier; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.hc.client5.http.ssl.HttpsSupport.getDefaultHostnameVerifier; import static org.zalando.riptide.chaos.FailureInjection.composite; import static org.zalando.riptide.faults.Predicates.alwaysTrue; import static org.zalando.riptide.faults.TransientFaults.transientConnectionFaults; @@ -91,7 +104,7 @@ static class ExampleClientConfiguration { @Bean public Http exampleHttp(final Executor executor, final ClientHttpRequestFactory requestFactory, - final ClientHttpMessageConverters converters, final List plugins) { + final ClientHttpMessageConverters converters, final List plugins) { return Http.builder() .executor(executor) @@ -105,7 +118,7 @@ public Http exampleHttp(final Executor executor, final ClientHttpRequestFactory @Bean public List examplePlugins(final MeterRegistry meterRegistry, final Logbook logbook, - final Tracer tracer) { + final Tracer tracer) { final CircuitBreakerListener listener = new MetricsCircuitBreakerListener(meterRegistry) .withDefaultTags(Tag.of("clientId", "example")); @@ -186,16 +199,16 @@ public RestOperations exampleRestOperations(final Http http) { @Bean public ApacheClientHttpRequestFactory exampleAsyncClientHttpRequestFactory( final Flow flow) throws Exception { - return new ApacheClientHttpRequestFactory( - HttpClientBuilder.create() - .setDefaultRequestConfig(RequestConfig.custom() - .setConnectTimeout(5000) - .setSocketTimeout(5000) + + final PoolingHttpClientConnectionManager connectionManager = + PoolingHttpClientConnectionManagerBuilder.create() + .setDefaultConnectionConfig(ConnectionConfig.custom() + .setConnectTimeout(5, SECONDS) + .setSocketTimeout(5, SECONDS) + .setTimeToLive(30, SECONDS) .build()) - .setConnectionTimeToLive(30, SECONDS) .setMaxConnPerRoute(2) .setMaxConnTotal(20) - .addInterceptorFirst(new FlowHttpRequestInterceptor(flow)) .setSSLSocketFactory(new SSLConnectionSocketFactory( SSLContexts.custom() .loadTrustMaterial( @@ -203,18 +216,30 @@ public ApacheClientHttpRequestFactory exampleAsyncClientHttpRequestFactory( "password".toCharArray()) .build(), getDefaultHostnameVerifier())) + .build(); + + + return new ApacheClientHttpRequestFactory( + HttpClientBuilder.create() + .addRequestInterceptorFirst(new FlowAutoConfiguration.FlowHttpRequestInterceptor(flow)) + .setConnectionManager(connectionManager) .build()); } + @Bean + public Tracer tracer() { + return NoopTracerFactory.create(); + } + @Bean(destroyMethod = "shutdown") public ExecutorService executor(final Tracer tracer) { return new TracedExecutorService( ThreadPoolExecutors.builder() - .elasticSize(1, 20) - .keepAlive(1, MINUTES) - .withoutQueue() - .threadFactory(new CustomizableThreadFactory("http-example-")) - .build(), + .elasticSize(1, 20) + .keepAlive(1, MINUTES) + .withoutQueue() + .threadFactory(new CustomizableThreadFactory("http-example-")) + .build(), tracer); } diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java index 9408c6429..4cf809956 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java @@ -1,15 +1,14 @@ package org.zalando.riptide.autoconfigure; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import okhttp3.Headers; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.springframework.http.HttpMethod; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; - import static com.google.common.io.Resources.getResource; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.IntStream.range; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java index c58cc0661..2140bd482 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java @@ -1,13 +1,12 @@ package org.zalando.riptide.autoconfigure; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.zalando.riptide.Http; - -import javax.annotation.Nullable; import java.util.Objects; import java.util.Set; import java.util.stream.Stream; +import javax.annotation.Nullable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.zalando.riptide.Http; import static java.util.stream.Collectors.toSet; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java index b0e43b082..86bc5c24d 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java @@ -1,10 +1,9 @@ package org.zalando.riptide.autoconfigure; +import java.lang.reflect.Method; import org.junit.jupiter.api.Test; import org.springframework.util.ReflectionUtils; -import java.lang.reflect.Method; - import static org.junit.jupiter.api.Assertions.assertNotNull; final class NoCachingTest { diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java index 3f3879678..75a411f30 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java @@ -1,5 +1,7 @@ package org.zalando.riptide.autoconfigure; +import java.lang.reflect.Field; +import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -18,13 +20,9 @@ import org.zalando.riptide.opentelemetry.OpenTelemetryPlugin; import org.zalando.riptide.opentracing.OpenTracingPlugin; -import java.lang.reflect.Field; -import java.util.List; - import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.instanceOf; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java index 45cfd0c28..8ebe7e463 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java @@ -1,10 +1,9 @@ package org.zalando.riptide.autoconfigure; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java index af1523aca..e65ce2236 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java @@ -1,9 +1,8 @@ package org.zalando.riptide.autoconfigure; -import org.junit.jupiter.api.Test; - import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java index c3ce354c4..bd4a455d0 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java @@ -1,10 +1,9 @@ package org.zalando.riptide.autoconfigure; -import org.junit.jupiter.api.Test; - import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.Test; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java index b3694b3b2..91a1e4dcf 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java @@ -4,6 +4,8 @@ import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import java.util.Arrays; +import java.util.Collection; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -20,9 +22,6 @@ import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; -import java.util.Arrays; -import java.util.Collection; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java index c2a967674..410290c9c 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java @@ -1,5 +1,6 @@ package org.zalando.riptide.autoconfigure.retry; +import java.util.concurrent.CompletionException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -14,8 +15,6 @@ import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; -import java.util.concurrent.CompletionException; - import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; import static org.springframework.test.web.client.ExpectedCount.times; From 58d77475a027f273c9e65db0f50fa90a358e4d2f Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 02:32:51 +0200 Subject: [PATCH 10/32] Fix Tracer and Flow auto-configurations --- riptide-spring-boot-autoconfigure/pom.xml | 8 +-- .../autoconfigure/FlowAutoConfiguration.java | 37 ------------- .../FlowHttpRequestInterceptor.java | 29 ++++++++++ .../OpenTracingFlowIdAutoConfiguration.java | 54 +++++++++++++++++++ .../RiptideAutoConfiguration.java | 2 +- .../TracerAutoConfiguration.java | 12 ----- .../riptide/autoconfigure/BaseURLTest.java | 5 +- .../riptide/autoconfigure/CachingTest.java | 1 - .../DefaultTestConfiguration.java | 2 +- .../autoconfigure/ManualConfiguration.java | 3 +- .../OpenTracingTestAutoConfiguration.java | 1 - .../autoconfigure/metrics/MetricsTest.java | 2 +- .../autoconfigure/url/UrlResolutionTest.java | 2 +- 13 files changed, 92 insertions(+), 66 deletions(-) delete mode 100644 riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java create mode 100644 riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java create mode 100644 riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java delete mode 100644 riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java diff --git a/riptide-spring-boot-autoconfigure/pom.xml b/riptide-spring-boot-autoconfigure/pom.xml index 079bf8597..6cb21df65 100644 --- a/riptide-spring-boot-autoconfigure/pom.xml +++ b/riptide-spring-boot-autoconfigure/pom.xml @@ -154,15 +154,9 @@ org.zalando - opentracing-flowid-starter + opentracing-flowid 4.2.3 true - - - org.apache.httpcomponents - httpclient - - org.zalando diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java deleted file mode 100644 index 4499e7db8..000000000 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowAutoConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.zalando.riptide.autoconfigure; - -import io.opentracing.Tracer; -import org.apache.hc.core5.http.EntityDetails; -import org.apache.hc.core5.http.HttpRequest; -import org.apache.hc.core5.http.HttpRequestInterceptor; -import org.apache.hc.core5.http.protocol.HttpContext; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.zalando.opentracing.flowid.Flow; - -public class FlowAutoConfiguration { - - @Bean - public Flow flow(final Tracer tracer) { - return Flow.create(tracer); - } - - static class FlowHttpRequestInterceptor implements HttpRequestInterceptor { - private final Flow flow; - - public FlowHttpRequestInterceptor(final Flow flow) { - this.flow = flow; - } - - @Override - public void process(HttpRequest httpRequest, EntityDetails entityDetails, HttpContext httpContext) { - this.flow.writeTo(httpRequest::addHeader); - } - } - - @Bean - @ConditionalOnMissingBean({FlowHttpRequestInterceptor.class}) - public FlowHttpRequestInterceptor flowHttpRequestInterceptor(final Flow flow) { - return new FlowHttpRequestInterceptor(flow); - } -} diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java new file mode 100644 index 000000000..2d6daed0b --- /dev/null +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java @@ -0,0 +1,29 @@ +package org.zalando.riptide.autoconfigure; + +import org.apache.hc.core5.http.EntityDetails; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.HttpRequestInterceptor; +import org.apache.hc.core5.http.protocol.HttpContext; +import org.apiguardian.api.API; +import org.zalando.opentracing.flowid.Flow; + +import static org.apiguardian.api.API.Status.STABLE; + +/** + * This class is adapted from org.zalando.opentracing.flowid.httpclient.FlowHttpRequestInterceptor. + * The original class is based on Apache HttpClient 4.x, but we use Apache HttpClient 5.x. + */ +@API(status = STABLE) +public final class FlowHttpRequestInterceptor implements HttpRequestInterceptor { + + private final Flow flow; + + public FlowHttpRequestInterceptor(final Flow flow) { + this.flow = flow; + } + + @Override + public void process(HttpRequest httpRequest, EntityDetails entityDetails, HttpContext httpContext) { + flow.writeTo(httpRequest::addHeader); + } +} \ No newline at end of file diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java new file mode 100644 index 000000000..e19c8c216 --- /dev/null +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java @@ -0,0 +1,54 @@ +package org.zalando.riptide.autoconfigure; + +import io.opentracing.Tracer; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apiguardian.api.API; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.zalando.opentracing.flowid.Flow; + +import static org.apiguardian.api.API.Status.INTERNAL; +import static org.apiguardian.api.API.Status.STABLE; + +/** + * This class is adapted from org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration. + * The original class is based on org.zalando.opentracing.flowid.httpclient.FlowHttpRequestInterceptor, + * which uses Apache HttpClient 4.x. + * We use org.zalando.riptide.autoconfigure.FlowHttpRequestInterceptor, that is adapted to Apache HttpClient 5.x. + */ +@API(status = STABLE) +@Configuration +@ConditionalOnBean(Tracer.class) +@AutoConfigureAfter(name = { + "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration", + "io.opentracing.contrib.spring.web.starter.ServerTracingAutoConfiguration" +}) +public class OpenTracingFlowIdAutoConfiguration { + + @API(status = INTERNAL) + @Bean + public Flow flow(final Tracer tracer) { + return Flow.create(tracer); + } + + @API(status = INTERNAL) + @Configuration + @ConditionalOnClass(HttpClient.class) + @ConditionalOnMissingBean(FlowHttpRequestInterceptor.class) + @ConditionalOnProperty(name = "opentracing.flowid.httpclient.enabled", havingValue = "true", matchIfMissing = true) + static class OpenTracingFlowIdHttpClientAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(FlowHttpRequestInterceptor.class) + public FlowHttpRequestInterceptor flowHttpRequestInterceptor(final Flow flow) { + return new FlowHttpRequestInterceptor(flow); + } + + } + +} diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java index 9c8fc9ae5..51b5ead53 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java @@ -14,7 +14,7 @@ @AutoConfigureAfter(name = { "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration", "org.zalando.logbook.autoconfigure.LogbookAutoConfiguration", - "org.zalando.riptide.autoconfigure.FlowAutoConfiguration", + "org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration", "org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration", "org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration", }) diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java deleted file mode 100644 index 05bc965c5..000000000 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TracerAutoConfiguration.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.zalando.riptide.autoconfigure; - -import io.opentracing.Tracer; -import io.opentracing.noop.NoopTracerFactory; -import org.springframework.context.annotation.Bean; - -public class TracerAutoConfiguration { - @Bean - public Tracer tracer() { - return NoopTracerFactory.create(); - } -} diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java index b40655718..99900cc98 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java @@ -32,9 +32,10 @@ final class BaseURLTest { RiptideAutoConfiguration.class, JacksonAutoConfiguration.class, LogbookAutoConfiguration.class, + //OpenTracingFlowIdAutoConfiguration.class, + OpenTracingFlowIdAutoConfiguration.class, + OpenTracingTestAutoConfiguration.class, MetricsTestAutoConfiguration.class, - FlowAutoConfiguration.class, - TracerAutoConfiguration.class, }) public static class TestConfiguration { diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java index 6116a4590..f53cc7e32 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CachingTest.java @@ -17,7 +17,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ActiveProfiles; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.Http; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java index b30684136..063fbc918 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultTestConfiguration.java @@ -12,7 +12,7 @@ JacksonAutoConfiguration.class, LogbookAutoConfiguration.class, OpenTracingTestAutoConfiguration.class, - FlowAutoConfiguration.class, + OpenTracingFlowIdAutoConfiguration.class, MetricsTestAutoConfiguration.class, }) @ActiveProfiles("default") diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java index 67af67ea5..8c117d6a8 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java @@ -41,7 +41,6 @@ import org.zalando.logbook.Logbook; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; import org.zalando.opentracing.flowid.Flow; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.Http; import org.zalando.riptide.OriginalStackTracePlugin; import org.zalando.riptide.Plugin; @@ -221,7 +220,7 @@ public ApacheClientHttpRequestFactory exampleAsyncClientHttpRequestFactory( return new ApacheClientHttpRequestFactory( HttpClientBuilder.create() - .addRequestInterceptorFirst(new FlowAutoConfiguration.FlowHttpRequestInterceptor(flow)) + .addRequestInterceptorFirst(new FlowHttpRequestInterceptor(flow)) .setConnectionManager(connectionManager) .build()); } diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/OpenTracingTestAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/OpenTracingTestAutoConfiguration.java index 96b1a624c..75f40bc9f 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/OpenTracingTestAutoConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/OpenTracingTestAutoConfiguration.java @@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; @Configuration @AutoConfigureBefore(OpenTracingFlowIdAutoConfiguration.class) diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java index 91a1e4dcf..fd918db6c 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java @@ -16,8 +16,8 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.client.MockRestServiceServer; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.Http; +import org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.autoconfigure.MetricsTestAutoConfiguration; import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java index c1bcf0689..8fc966900 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java @@ -10,8 +10,8 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.client.MockRestServiceServer; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; -import org.zalando.opentracing.flowid.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.Http; +import org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.autoconfigure.MetricsTestAutoConfiguration; import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; From 179929953329c6cfb9d8c7d8aaa39500f2a647ef Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 03:08:12 +0200 Subject: [PATCH 11/32] Make tests more robust by accepting both localhost and 127.0.0.1 On Windows operating systems, some tests failed as they required hostname to be "localhost", but Windows returned "127.0.0.1". --- .../micrometer/MicrometerPluginTest.java | 10 +++--- .../OpenTelemetryPluginTest.java | 4 +-- .../opentracing/OpenTracingPluginTest.java | 36 ++++++++++++------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java index 508839783..adb5c4e7d 100644 --- a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java +++ b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java @@ -104,7 +104,7 @@ void shouldRecordSuccessResponseMetric() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/foo")); assertThat(timer.getId().getTag("http.status_code"), is("200")); - assertThat(timer.getId().getTag("peer.hostname"), is("localhost")); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("client"), is("example")); assertThat(timer.getId().getTag("test"), is("true")); @@ -130,7 +130,7 @@ void shouldRecordRetryNumberMetricTag() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/foo")); assertThat(timer.getId().getTag("http.status_code"), is("500")); - assertThat(timer.getId().getTag("peer.hostname"), is("localhost")); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("retry_number"), is("0")); assertThat(timer.totalTime(NANOSECONDS), is(greaterThan(0.0))); @@ -142,7 +142,7 @@ void shouldRecordRetryNumberMetricTag() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/foo")); assertThat(timer.getId().getTag("http.status_code"), is("200")); - assertThat(timer.getId().getTag("peer.hostname"), is("localhost")); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("retry_number"), is("1")); assertThat(timer.totalTime(NANOSECONDS), is(greaterThan(0.0))); @@ -167,7 +167,7 @@ void shouldRecordErrorResponseMetric() { assertThat(timer.getId().getTag("http.method"), is("POST")); assertThat(timer.getId().getTag("http.path"), is("")); assertThat(timer.getId().getTag("http.status_code"), is("500")); - assertThat(timer.getId().getTag("peer.hostname"), is("localhost")); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("client"), is("example")); assertThat(timer.getId().getTag("test"), is("true")); @@ -191,7 +191,7 @@ void shouldNotRecordFailureMetric() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/err")); assertThat(timer.getId().getTag("http.status_code"), is("0")); - assertThat(timer.getId().getTag("peer.hostname"), is("localhost")); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("SocketTimeoutException")); assertThat(timer.getId().getTag("client"), is("example")); assertThat(timer.getId().getTag("test"), is("true")); diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java index d9a92a5d5..ed58c5ca7 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java @@ -238,7 +238,7 @@ void shouldTraceRequestAndIgnoreClientError() { final Attributes attributes = child.getAttributes(); assertThat(attributes.get(AttributeKey.stringKey("env")), is("unittest")); assertThat(attributes.get(AttributeKey.stringKey("http.method")), is("GET")); - assertThat(attributes.get(AttributeKey.stringKey("peer.hostname")), is("localhost")); + assertThat(attributes.get(AttributeKey.stringKey("peer.hostname")), anyOf(is("hostname"), is("127.0.0.1"))); assertThat(attributes.get(AttributeKey.longKey("http.status_code")), is(400L)); verify(server, 1, "/"); @@ -306,7 +306,7 @@ void shouldOverwriteDefaultSetOfDecorators() { final Attributes attributes = child.getAttributes(); assertThat(attributes.size(), is(1)); - assertThat(attributes.get(AttributeKey.stringKey("http.host")), is("localhost")); + assertThat(attributes.get(AttributeKey.stringKey("http.host")), anyOf(is("hostname"), is("127.0.0.1"))); verify(server, 1, "/"); } diff --git a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java index 6cd3f119e..1a084f161 100644 --- a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java +++ b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java @@ -95,11 +95,11 @@ void shouldTraceRequestAndResponse() { final MockSpan child = spans.get(0); assertThat(child.parentId(), is(parent.context().spanId())); + final int port = server.getPort(); + assertThat(child.tags(), hasEntry("component", "Riptide")); assertThat(child.tags(), hasEntry("span.kind", "client")); - assertThat(child.tags(), hasEntry("peer.address", "localhost:" + server.getPort())); - assertThat(child.tags(), hasEntry("peer.hostname", "localhost")); - assertThat(child.tags(), hasEntry("peer.port", server.getPort())); + assertThat(child.tags(), hasEntry("peer.port", port)); assertThat(child.tags(), hasEntry("http.method", "POST")); assertThat(child.tags(), hasEntry("http.method_override", "GET")); assertThat(child.tags(), hasEntry("http.path", "/users/{user}")); @@ -110,6 +110,9 @@ void shouldTraceRequestAndResponse() { assertThat(child.tags(), hasEntry("user", "me")); assertThat(child.tags(), hasEntry("spi", true)); + assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + // not active by default assertThat(child.tags(), not(hasKey("http.url"))); @@ -158,11 +161,11 @@ void shouldTraceRequestAndServerError() { final MockSpan child = spans.get(0); assertThat(child.parentId(), is(parent.context().spanId())); + final int port = server.getPort(); + assertThat(child.tags(), hasEntry("component", "Riptide")); assertThat(child.tags(), hasEntry("span.kind", "client")); - assertThat(child.tags(), hasEntry("peer.address", "localhost:" + server.getPort())); - assertThat(child.tags(), hasEntry("peer.hostname", "localhost")); - assertThat(child.tags(), hasEntry("peer.port", server.getPort())); + assertThat(child.tags(), hasEntry("peer.port", port)); assertThat(child.tags(), hasEntry("http.method", "GET")); assertThat(child.tags(), hasEntry("http.status_code", 500)); assertThat(child.tags(), hasEntry("error", true)); @@ -170,6 +173,9 @@ void shouldTraceRequestAndServerError() { assertThat(child.tags(), hasEntry("test.environment", "JUnit")); assertThat(child.tags(), hasEntry("spi", true)); + assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + // since we didn't use a uri template assertThat(child.tags(), not(hasKey("http.path"))); @@ -205,14 +211,17 @@ void shouldTraceRequestAndNetworkError() { final MockSpan child = spans.get(0); assertThat(child.parentId(), is(parent.context().spanId())); + final int port = server.getPort(); + assertThat(child.tags(), hasEntry("component", "Riptide")); assertThat(child.tags(), hasEntry("span.kind", "client")); - assertThat(child.tags(), hasEntry("peer.address", "localhost:" + server.getPort())); - assertThat(child.tags(), hasEntry("peer.hostname", "localhost")); - assertThat(child.tags(), hasEntry("peer.port", server.getPort())); + assertThat(child.tags(), hasEntry("peer.port", port)); assertThat(child.tags(), hasEntry("http.method", "GET")); assertThat(child.tags(), hasEntry("error", true)); + assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + // since we didn't use a uri template assertThat(child.tags(), not(hasKey("http.path"))); @@ -264,14 +273,17 @@ void shouldTraceRequestAndIgnoreClientError() { final MockSpan child = spans.get(0); assertThat(child.parentId(), is(parent.context().spanId())); + final int port = server.getPort(); + assertThat(child.tags(), hasEntry("component", "Riptide")); assertThat(child.tags(), hasEntry("span.kind", "client")); - assertThat(child.tags(), hasEntry("peer.address", "localhost:" + server.getPort())); - assertThat(child.tags(), hasEntry("peer.hostname", "localhost")); - assertThat(child.tags(), hasEntry("peer.port", server.getPort())); + assertThat(child.tags(), hasEntry("peer.port", port)); assertThat(child.tags(), hasEntry("http.method", "GET")); assertThat(child.tags(), hasEntry("http.status_code", 400)); + assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + // since we didn't use a uri template assertThat(child.tags(), not(hasKey("error"))); From 6d01005aa23d99a6e0f729cb79e899ac7b313dec Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 03:44:24 +0200 Subject: [PATCH 12/32] Fix vulnerabilities and cve-suppressions.xml --- cve-suppressions.xml | 63 ++---------------------------------------- riptide-parent/pom.xml | 11 ++++++-- 2 files changed, 12 insertions(+), 62 deletions(-) diff --git a/cve-suppressions.xml b/cve-suppressions.xml index e6ecd6ea2..318217ab0 100644 --- a/cve-suppressions.xml +++ b/cve-suppressions.xml @@ -1,67 +1,10 @@ - - org.slf4j:slf4j-api:1.7.25 - CVE-2018-8088 - - - ^pkg:maven/org\.springframework/spring\-.+@.*$ - CVE-2015-3192 - CVE-2015-5211 - CVE-2016-5007 - CVE-2018-1270 - CVE-2018-1271 - CVE-2018-1272 - - - - CVE-2016-1000027 - CVE-2019-12814 - CVE-2020-5421 - CVE-2020-7712 - CVE-2020-9488 - CVE-2020-10663 - CVE-2022-22965 - CVE-2022-38752 - CVE-2022-38751 - CVE-2022-38750 - CVE-2022-25857 - CVE-2022-38749 - CVE-2021-37533 - CVE-2022-41854 - CVE-2022-1471 - CVE-2021-4277 - CVE-2022-3064 - CVE-2021-4235 - CVE-2022-45688 - CVE-2020-8908 - - - - - org\.springframework\.boot:.+:2\.1\.5\.RELEASE - CVE-2011-2730 - CVE-2013-4152 - CVE-2013-6429 - CVE-2013-7315 - CVE-2014-0054 - - - - - CVE-2021-44228 - CVE-2021-45105 - CVE-2021-45046 - CVE-2021-44832 - + - - CVE-2023-20860 - CVE-2023-20861 - CVE-2023-20863 - CVE-2023-1370 - CVE-2023-20873 + + CVE-2023-35116 diff --git a/riptide-parent/pom.xml b/riptide-parent/pom.xml index f1b64f318..93b905ae8 100644 --- a/riptide-parent/pom.xml +++ b/riptide-parent/pom.xml @@ -17,8 +17,8 @@ 0.9.0 - 2.14.2 - 2.14.2 + 2.15.2 + 2.15.2 5.9.3 3.0.0 1.11.0 @@ -30,6 +30,13 @@ + + + org.yaml + snakeyaml + 2.0 + + org.zalando From 0c890ee838c32cc457fd5bb6e56ac735391aadb2 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 03:48:52 +0200 Subject: [PATCH 13/32] Optimize imports --- .../zalando/riptide/capture/CaptureTest.java | 4 ++- .../riptide/chaos/ChaosPluginTest.java | 16 +++++++++--- .../compatibility/HttpOperationsTest.java | 1 - .../RequestCompressionPluginTest.java | 8 ++++-- .../concurrent/ThreadPoolExecutorBuilder.java | 22 +++++++++++++--- .../src/main/java/org/zalando/riptide/IO.java | 1 - .../java/org/zalando/riptide/CallTest.java | 5 +++- .../ForwardingClientHttpResponseTest.java | 4 ++- .../org/zalando/riptide/HttpStatuses.java | 5 +++- .../zalando/riptide/NestedDispatchTest.java | 25 +++++++++++++++---- .../org/zalando/riptide/RequestUriTest.java | 4 ++- .../java/org/zalando/riptide/RouteTest.java | 13 +++++++--- .../zalando/riptide/SeriesDispatchTest.java | 6 ++++- .../zalando/riptide/ThreadAffinityTest.java | 4 ++- .../failsafe/CompositeDelayFunction.java | 2 +- .../failsafe/CompositeRetryListener.java | 2 +- .../failsafe/CompositeTaskDecorator.java | 2 +- .../failsafe/ConditionalRequestPolicy.java | 2 +- .../failsafe/DefaultRequestPolicy.java | 2 +- .../riptide/failsafe/FailsafePlugin.java | 2 +- .../failsafe/LoggingRetryListener.java | 2 +- .../failsafe/RateLimitResetDelayFunction.java | 3 +-- .../failsafe/RetryAfterDelayFunction.java | 3 +-- .../riptide/failsafe/RetryRequestPolicy.java | 4 +-- .../MetricsCircuitBreakerListener.java | 8 +++--- .../FailsafePluginBackupRequestTest.java | 4 ++- .../FailsafePluginCircuitBreakerTest.java | 4 ++- .../failsafe/FailsafePluginNoPolicyTest.java | 4 ++- .../failsafe/FailsafePluginRetriesTest.java | 8 ++++-- .../failsafe/FailsafePluginTimeoutTest.java | 4 ++- .../RateLimitResetDelayFunctionTest.java | 4 ++- .../failsafe/RetryAfterDelayFunctionTest.java | 4 ++- .../MetricsCircuitBreakerListenerTest.java | 2 +- .../ApacheClientHttpRequestFactory.java | 19 ++++++++++++-- ...actApacheClientHttpRequestFactoryTest.java | 14 +++++++++-- .../ApacheClientHttpResponseBodyTest.java | 4 ++- .../HttpConnectionPoolMetricsTest.java | 4 ++- .../DefaultIdempotencyDetector.java | 7 +++++- .../idempotency/IdempotencyPredicate.java | 1 - .../idempotency/IdempotencyPredicateTest.java | 9 ++++++- .../logbook/LogbookPluginStreamingTest.java | 4 ++- .../micrometer/MicrometerPluginTest.java | 11 ++++++-- .../opentelemetry/OpenTelemetryPlugin.java | 3 +-- .../span/HttpPathSpanDecorator.java | 1 - .../OpenTelemetryPluginTest.java | 21 +++++++++++++--- .../opentracing/TracedTaskDecorator.java | 2 +- .../span/ServiceLoaderSpanDecorator.java | 1 - .../opentracing/span/SpanDecorator.java | 1 - .../opentracing/OpenTracingPluginTest.java | 14 +++++++++-- .../riptide/autoconfigure/BaseURL.java | 5 ++-- .../ClientHttpMessageConverters.java | 3 ++- .../DefaultRiptideConfigurer.java | 13 +++++----- .../DefaultRiptideRegistrar.java | 23 +++++++++-------- .../riptide/autoconfigure/Defaulting.java | 13 +++++----- .../autoconfigure/FailsafePluginFactory.java | 15 +++++------ .../autoconfigure/HttpClientFactory.java | 21 ++++++++-------- .../riptide/autoconfigure/HttpFactory.java | 7 +++--- .../MicrometerPluginFactory.java | 3 ++- .../zalando/riptide/autoconfigure/Name.java | 5 ++-- .../OpenTracingPluginFactory.java | 7 +++--- .../zalando/riptide/autoconfigure/Ratio.java | 5 ++-- .../autoconfigure/RatioInTimeSpan.java | 3 ++- .../riptide/autoconfigure/Registry.java | 9 ++++--- .../autoconfigure/RiptideClientTest.java | 11 ++++---- .../autoconfigure/RiptidePostProcessor.java | 3 ++- .../autoconfigure/RiptideProperties.java | 15 +++++------ .../autoconfigure/ThreadPoolFactory.java | 3 ++- .../riptide/autoconfigure/TimeSpan.java | 9 ++++--- .../AccessTokensCredentialsDirectoryTest.java | 3 ++- .../riptide/autoconfigure/BaseURLTest.java | 5 ++-- .../autoconfigure/CircuitBreakerTest.java | 3 ++- .../ClientConfigurationTest.java | 5 ++-- .../riptide/autoconfigure/DefaultingTest.java | 3 ++- .../autoconfigure/HttpClientFactoryTest.java | 5 ++-- .../HttpMessageConvertersTest.java | 3 ++- .../KeystoreIntegrationTest.java | 3 ++- .../autoconfigure/ManualConfiguration.java | 17 +++++++------ .../autoconfigure/MockWebServerUtil.java | 7 +++--- .../riptide/autoconfigure/NameTest.java | 9 ++++--- .../riptide/autoconfigure/NoCachingTest.java | 3 ++- .../riptide/autoconfigure/PluginTest.java | 5 ++-- .../autoconfigure/RatioInTimeSpanTest.java | 3 ++- .../riptide/autoconfigure/RatioTest.java | 3 ++- .../riptide/autoconfigure/TimeSpanTest.java | 3 ++- .../autoconfigure/metrics/MetricsTest.java | 7 +++--- .../autoconfigure/retry/RetryTest.java | 3 ++- .../autoconfigure/url/UrlResolutionTest.java | 2 +- 87 files changed, 377 insertions(+), 188 deletions(-) diff --git a/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java b/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java index a69ea7796..5d85bb56d 100644 --- a/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java +++ b/riptide-capture/src/test/java/org/zalando/riptide/capture/CaptureTest.java @@ -19,7 +19,9 @@ import java.util.concurrent.Executors; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.OK; diff --git a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java index 9fa37ae15..e34664660 100644 --- a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java +++ b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java @@ -27,14 +27,24 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.anEmptyMap; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.oneOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.chaos.FailureInjection.composite; -import static org.zalando.riptide.chaos.MockWebServerUtil.*; +import static org.zalando.riptide.chaos.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.chaos.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.chaos.MockWebServerUtil.verify; final class ChaosPluginTest { diff --git a/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOperationsTest.java b/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOperationsTest.java index 0688da900..c59849fcc 100644 --- a/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOperationsTest.java +++ b/riptide-compatibility/src/test/java/org/zalando/riptide/compatibility/HttpOperationsTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; -import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.AfterEach; diff --git a/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java b/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java index b4203394d..204ade970 100644 --- a/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java +++ b/riptide-compression/src/test/java/org/zalando/riptide/compression/RequestCompressionPluginTest.java @@ -31,10 +31,14 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; import static java.util.concurrent.Executors.newSingleThreadExecutor; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.springframework.http.HttpHeaders.CONTENT_ENCODING; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.compression.MockWebServerUtil.*; +import static org.zalando.riptide.compression.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.compression.MockWebServerUtil.getRecordedRequest; +import static org.zalando.riptide.compression.MockWebServerUtil.textMockResponse; class RequestCompressionPluginTest { diff --git a/riptide-concurrent/src/main/java/org/zalando/riptide/concurrent/ThreadPoolExecutorBuilder.java b/riptide-concurrent/src/main/java/org/zalando/riptide/concurrent/ThreadPoolExecutorBuilder.java index 045b58e4b..3faca4c3e 100644 --- a/riptide-concurrent/src/main/java/org/zalando/riptide/concurrent/ThreadPoolExecutorBuilder.java +++ b/riptide-concurrent/src/main/java/org/zalando/riptide/concurrent/ThreadPoolExecutorBuilder.java @@ -2,10 +2,26 @@ import lombok.AllArgsConstructor; import lombok.With; -import org.zalando.riptide.concurrent.ThreadPoolExecutors.*; - -import java.util.concurrent.*; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.Build; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.ElasticSize; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.FixedSize; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.KeepAliveTime; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.PreStart; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.QueueFirst; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.RejectedExecutions; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.ScaleFirst; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.Start; +import org.zalando.riptide.concurrent.ThreadPoolExecutors.Threads; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; +import java.util.concurrent.TimeUnit; import java.util.function.UnaryOperator; import static java.util.concurrent.Executors.defaultThreadFactory; diff --git a/riptide-core/src/main/java/org/zalando/riptide/IO.java b/riptide-core/src/main/java/org/zalando/riptide/IO.java index 4097bec81..19c1b53b4 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/IO.java +++ b/riptide-core/src/main/java/org/zalando/riptide/IO.java @@ -1,6 +1,5 @@ package org.zalando.riptide; -import com.google.gag.annotation.remark.ThisWouldBeOneLineIn; import org.springframework.util.MultiValueMap; import java.util.List; diff --git a/riptide-core/src/test/java/org/zalando/riptide/CallTest.java b/riptide-core/src/test/java/org/zalando/riptide/CallTest.java index d2b823fa9..bf27eeecd 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/CallTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/CallTest.java @@ -15,7 +15,10 @@ import java.util.concurrent.CompletionException; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.anEmptyMap; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; diff --git a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java index 6f6439c9b..6d405a236 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java @@ -11,7 +11,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.OK; final class ForwardingClientHttpResponseTest { diff --git a/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java b/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java index 6e690d4a4..33bdedd8e 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java +++ b/riptide-core/src/test/java/org/zalando/riptide/HttpStatuses.java @@ -7,7 +7,10 @@ import java.util.function.Predicate; import java.util.stream.Stream; -import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.HttpStatus.CHECKPOINT; +import static org.springframework.http.HttpStatus.MOVED_TEMPORARILY; +import static org.springframework.http.HttpStatus.REQUEST_ENTITY_TOO_LARGE; +import static org.springframework.http.HttpStatus.REQUEST_URI_TOO_LONG; final class HttpStatuses { diff --git a/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java b/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java index 79d98e430..cc766ddf2 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/NestedDispatchTest.java @@ -20,16 +20,31 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; import static org.hobsoft.hamcrest.compose.ComposeMatchers.hasFeature; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.springframework.http.HttpStatus.*; -import static org.springframework.http.HttpStatus.Series.*; +import static org.springframework.http.HttpStatus.ACCEPTED; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.MOVED_PERMANENTLY; +import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR; +import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; +import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.springframework.http.MediaType.parseMediaType; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.zalando.riptide.Bindings.*; -import static org.zalando.riptide.Navigators.*; +import static org.zalando.riptide.Bindings.anyContentType; +import static org.zalando.riptide.Bindings.anySeries; +import static org.zalando.riptide.Bindings.anyStatus; +import static org.zalando.riptide.Bindings.anyStatusCode; +import static org.zalando.riptide.Bindings.on; +import static org.zalando.riptide.Navigators.contentType; +import static org.zalando.riptide.Navigators.series; +import static org.zalando.riptide.Navigators.status; +import static org.zalando.riptide.Navigators.statusCode; import static org.zalando.riptide.RoutingTree.dispatch; import static org.zalando.riptide.Types.listOf; import static org.zalando.riptide.model.MediaTypes.ERROR; diff --git a/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java b/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java index 8cebeaa64..73f02a0e6 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/RequestUriTest.java @@ -23,7 +23,9 @@ import java.util.stream.Stream; import static java.util.Arrays.stream; -import static java.util.stream.Collectors.*; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; diff --git a/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java b/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java index 21cd0cc08..fd7b321b1 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/RouteTest.java @@ -12,10 +12,17 @@ import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.springframework.http.HttpStatus.*; -import static org.springframework.http.MediaType.*; +import static org.springframework.http.HttpStatus.CONFLICT; +import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.http.MediaType.TEXT_PLAIN; +import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; diff --git a/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java b/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java index 6e2c8b9ce..1e6d61756 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/SeriesDispatchTest.java @@ -13,7 +13,11 @@ import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.springframework.http.HttpStatus.Series.*; +import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR; +import static org.springframework.http.HttpStatus.Series.INFORMATIONAL; +import static org.springframework.http.HttpStatus.Series.REDIRECTION; +import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; +import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; import static org.zalando.riptide.Bindings.on; diff --git a/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java b/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java index b8cd6fc52..e1ed45185 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/ThreadAffinityTest.java @@ -14,7 +14,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; import static org.zalando.riptide.Bindings.on; -import static org.zalando.riptide.MockWebServerUtil.*; +import static org.zalando.riptide.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.MockWebServerUtil.verify; import static org.zalando.riptide.Navigators.series; final class ThreadAffinityTest { diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeDelayFunction.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeDelayFunction.java index fcbf6ff5d..87c473696 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeDelayFunction.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeDelayFunction.java @@ -1,8 +1,8 @@ package org.zalando.riptide.failsafe; +import dev.failsafe.ExecutionContext; import dev.failsafe.function.ContextualSupplier; import lombok.AllArgsConstructor; -import dev.failsafe.ExecutionContext; import org.apiguardian.api.API; import java.time.Duration; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeRetryListener.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeRetryListener.java index 540d9a893..3f91c7b09 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeRetryListener.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeRetryListener.java @@ -1,7 +1,7 @@ package org.zalando.riptide.failsafe; -import lombok.AllArgsConstructor; import dev.failsafe.event.ExecutionAttemptedEvent; +import lombok.AllArgsConstructor; import org.apiguardian.api.API; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.RequestArguments; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeTaskDecorator.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeTaskDecorator.java index 43c010985..6ac53859b 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeTaskDecorator.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/CompositeTaskDecorator.java @@ -1,7 +1,7 @@ package org.zalando.riptide.failsafe; -import lombok.AllArgsConstructor; import dev.failsafe.function.ContextualSupplier; +import lombok.AllArgsConstructor; import java.util.Collection; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/ConditionalRequestPolicy.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/ConditionalRequestPolicy.java index ab318ffb2..41b2a1231 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/ConditionalRequestPolicy.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/ConditionalRequestPolicy.java @@ -1,7 +1,7 @@ package org.zalando.riptide.failsafe; -import lombok.AllArgsConstructor; import dev.failsafe.Policy; +import lombok.AllArgsConstructor; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.RequestArguments; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/DefaultRequestPolicy.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/DefaultRequestPolicy.java index fe3c65b25..03a9b2e91 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/DefaultRequestPolicy.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/DefaultRequestPolicy.java @@ -1,7 +1,7 @@ package org.zalando.riptide.failsafe; -import lombok.AllArgsConstructor; import dev.failsafe.Policy; +import lombok.AllArgsConstructor; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.RequestArguments; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/FailsafePlugin.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/FailsafePlugin.java index e47321020..6510ac0a2 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/FailsafePlugin.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/FailsafePlugin.java @@ -1,9 +1,9 @@ package org.zalando.riptide.failsafe; -import lombok.AllArgsConstructor; import dev.failsafe.Failsafe; import dev.failsafe.Policy; import dev.failsafe.function.ContextualSupplier; +import lombok.AllArgsConstructor; import org.apiguardian.api.API; import org.organicdesign.fp.collections.ImList; import org.springframework.http.client.ClientHttpResponse; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/LoggingRetryListener.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/LoggingRetryListener.java index 875cc4302..b577266df 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/LoggingRetryListener.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/LoggingRetryListener.java @@ -1,7 +1,7 @@ package org.zalando.riptide.failsafe; -import lombok.AllArgsConstructor; import dev.failsafe.event.ExecutionAttemptedEvent; +import lombok.AllArgsConstructor; import org.apiguardian.api.API; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunction.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunction.java index d38b5f460..8e5c39f54 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunction.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunction.java @@ -1,8 +1,8 @@ package org.zalando.riptide.failsafe; +import dev.failsafe.ExecutionContext; import dev.failsafe.function.ContextualSupplier; import lombok.extern.slf4j.Slf4j; -import dev.failsafe.ExecutionContext; import org.apiguardian.api.API; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.HttpResponseException; @@ -10,7 +10,6 @@ import java.time.Clock; import java.time.Duration; import java.util.Arrays; -import java.util.Optional; import static java.util.Optional.ofNullable; import static org.apiguardian.api.API.Status.EXPERIMENTAL; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryAfterDelayFunction.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryAfterDelayFunction.java index 5ec602757..431e8a265 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryAfterDelayFunction.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryAfterDelayFunction.java @@ -1,9 +1,9 @@ package org.zalando.riptide.failsafe; +import dev.failsafe.ExecutionContext; import dev.failsafe.function.ContextualSupplier; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import dev.failsafe.ExecutionContext; import org.apiguardian.api.API; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.HttpResponseException; @@ -11,7 +11,6 @@ import java.time.Clock; import java.time.Duration; import java.util.Arrays; -import java.util.Optional; import static java.util.Optional.ofNullable; import static lombok.AccessLevel.PRIVATE; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryRequestPolicy.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryRequestPolicy.java index 084875c35..1c48a7a95 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryRequestPolicy.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/RetryRequestPolicy.java @@ -1,11 +1,11 @@ package org.zalando.riptide.failsafe; import com.google.common.annotations.VisibleForTesting; -import dev.failsafe.event.EventListener; -import lombok.AllArgsConstructor; import dev.failsafe.Policy; import dev.failsafe.RetryPolicy; +import dev.failsafe.event.EventListener; import dev.failsafe.event.ExecutionAttemptedEvent; +import lombok.AllArgsConstructor; import org.apiguardian.api.API; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.RequestArguments; diff --git a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListener.java b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListener.java index 3b477e49f..4d327202d 100644 --- a/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListener.java +++ b/riptide-failsafe/src/main/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListener.java @@ -1,11 +1,11 @@ package org.zalando.riptide.failsafe.metrics; import com.google.common.collect.ImmutableList; +import dev.failsafe.CircuitBreaker.State; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Timer.Sample; import lombok.AllArgsConstructor; -import dev.failsafe.CircuitBreaker.State; import org.apiguardian.api.API; import org.zalando.riptide.failsafe.CircuitBreakerListener; @@ -13,12 +13,12 @@ import static com.google.common.collect.ImmutableList.copyOf; import static com.google.common.collect.Iterables.concat; -import static io.micrometer.core.instrument.Timer.start; -import static java.util.Collections.singleton; -import static lombok.AccessLevel.PRIVATE; import static dev.failsafe.CircuitBreaker.State.CLOSED; import static dev.failsafe.CircuitBreaker.State.HALF_OPEN; import static dev.failsafe.CircuitBreaker.State.OPEN; +import static io.micrometer.core.instrument.Timer.start; +import static java.util.Collections.singleton; +import static lombok.AccessLevel.PRIVATE; import static org.apiguardian.api.API.Status.EXPERIMENTAL; import static org.apiguardian.api.API.Status.INTERNAL; diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java index 2127cbc7d..c97d20ba9 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginBackupRequestTest.java @@ -28,7 +28,9 @@ import static org.zalando.riptide.Bindings.on; import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; final class FailsafePluginBackupRequestTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java index 8dec006a4..81d377845 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginCircuitBreakerTest.java @@ -32,7 +32,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zalando.fauxpas.FauxPas.partially; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; import static org.zalando.riptide.failsafe.TaskDecorator.composite; final class FailsafePluginCircuitBreakerTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java index fc59a26bd..f745caf9e 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginNoPolicyTest.java @@ -24,7 +24,9 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.zalando.fauxpas.FauxPas.partially; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; final class FailsafePluginNoPolicyTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java index 83a6dfea5..4d6164026 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginRetriesTest.java @@ -40,7 +40,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTimeout; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; @@ -52,7 +54,9 @@ import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.Route.call; import static org.zalando.riptide.failsafe.CheckedPredicateConverter.toCheckedPredicate; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; import static org.zalando.riptide.failsafe.RetryRoute.retry; import static org.zalando.riptide.faults.Predicates.alwaysTrue; import static org.zalando.riptide.faults.TransientFaults.transientConnectionFaults; diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java index eb95651f9..b2f8a3fbc 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/FailsafePluginTimeoutTest.java @@ -24,7 +24,9 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; final class FailsafePluginTimeoutTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java index da2205a4e..b6de17f80 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java @@ -37,7 +37,9 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.Navigators.status; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; import static org.zalando.riptide.failsafe.RetryRoute.retry; final class RateLimitResetDelayFunctionTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java index 3db5ce2dd..5d59b6547 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java @@ -37,7 +37,9 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.Navigators.status; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.failsafe.MockWebServerUtil.*; +import static org.zalando.riptide.failsafe.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.failsafe.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.failsafe.MockWebServerUtil.verify; import static org.zalando.riptide.failsafe.RetryRoute.retry; final class RetryAfterDelayFunctionTest { diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListenerTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListenerTest.java index 71513cae7..8fdab408a 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListenerTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/metrics/MetricsCircuitBreakerListenerTest.java @@ -1,9 +1,9 @@ package org.zalando.riptide.failsafe.metrics; +import dev.failsafe.CircuitBreaker; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import dev.failsafe.CircuitBreaker; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.failsafe.CircuitBreakerListener; diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java index eb4ea04d0..1b6a4c1ea 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/ApacheClientHttpRequestFactory.java @@ -3,7 +3,15 @@ import com.google.common.collect.ImmutableMap; import lombok.AllArgsConstructor; import org.apache.hc.client5.http.classic.HttpClient; -import org.apache.hc.client5.http.classic.methods.*; +import org.apache.hc.client5.http.classic.methods.HttpDelete; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpHead; +import org.apache.hc.client5.http.classic.methods.HttpOptions; +import org.apache.hc.client5.http.classic.methods.HttpPatch; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpPut; +import org.apache.hc.client5.http.classic.methods.HttpTrace; +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apiguardian.api.API; import org.springframework.beans.factory.DisposableBean; @@ -18,7 +26,14 @@ import java.util.function.Function; import static org.apiguardian.api.API.Status.STABLE; -import static org.springframework.http.HttpMethod.*; +import static org.springframework.http.HttpMethod.DELETE; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.HEAD; +import static org.springframework.http.HttpMethod.OPTIONS; +import static org.springframework.http.HttpMethod.PATCH; +import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.PUT; +import static org.springframework.http.HttpMethod.TRACE; @API(status = STABLE) @AllArgsConstructor diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java index a50b8970d..3ef7614e4 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java @@ -41,7 +41,14 @@ import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.anEmptyMap; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeout; import static org.mockito.Mockito.mock; @@ -54,7 +61,10 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.Types.listOf; -import static org.zalando.riptide.httpclient.MockWebServerUtil.*; +import static org.zalando.riptide.httpclient.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.httpclient.MockWebServerUtil.jsonMockResponseFromResource; +import static org.zalando.riptide.httpclient.MockWebServerUtil.textMockResponse; +import static org.zalando.riptide.httpclient.MockWebServerUtil.verify; public abstract class AbstractApacheClientHttpRequestFactoryTest { diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java index b52ee2c52..73ab33d21 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java @@ -8,7 +8,9 @@ import java.io.IOException; import java.io.InputStream; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; final class ApacheClientHttpResponseBodyTest { diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java index fb2b4487f..0cc64312a 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/metrics/HttpConnectionPoolMetricsTest.java @@ -21,7 +21,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.zalando.riptide.Route.call; -import static org.zalando.riptide.httpclient.MockWebServerUtil.*; +import static org.zalando.riptide.httpclient.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.httpclient.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.httpclient.MockWebServerUtil.verify; final class HttpConnectionPoolMetricsTest { diff --git a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java index 080550e2a..37c4ef78a 100644 --- a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java +++ b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/DefaultIdempotencyDetector.java @@ -7,7 +7,12 @@ import java.util.Set; import static org.apiguardian.api.API.Status.EXPERIMENTAL; -import static org.springframework.http.HttpMethod.*; +import static org.springframework.http.HttpMethod.DELETE; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.HEAD; +import static org.springframework.http.HttpMethod.OPTIONS; +import static org.springframework.http.HttpMethod.PUT; +import static org.springframework.http.HttpMethod.TRACE; /** * @see Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content, Section 4.2.1 diff --git a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/IdempotencyPredicate.java b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/IdempotencyPredicate.java index 17f5e3583..7956233af 100644 --- a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/IdempotencyPredicate.java +++ b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/IdempotencyPredicate.java @@ -3,7 +3,6 @@ import com.google.common.collect.Ordering; import lombok.AllArgsConstructor; import org.apiguardian.api.API; -import org.zalando.riptide.Attribute; import org.zalando.riptide.RequestArguments; import org.zalando.riptide.idempotency.IdempotencyDetector.Test; diff --git a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java index 37164cdca..3ed18cd1b 100644 --- a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java +++ b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/IdempotencyPredicateTest.java @@ -13,7 +13,14 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.springframework.http.HttpMethod.*; +import static org.springframework.http.HttpMethod.DELETE; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.HEAD; +import static org.springframework.http.HttpMethod.OPTIONS; +import static org.springframework.http.HttpMethod.PATCH; +import static org.springframework.http.HttpMethod.POST; +import static org.springframework.http.HttpMethod.PUT; +import static org.springframework.http.HttpMethod.TRACE; import static org.zalando.riptide.Attributes.IDEMPOTENT; final class IdempotencyPredicateTest { diff --git a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java index d46a5dc46..5e97f751d 100644 --- a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java +++ b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/LogbookPluginStreamingTest.java @@ -29,7 +29,9 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.OK; import static org.zalando.riptide.PassRoute.pass; diff --git a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java index adb5c4e7d..c45a17d2c 100644 --- a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java +++ b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java @@ -33,7 +33,12 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.iterableWithSize; +import static org.hamcrest.Matchers.notNullValue; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.OK; @@ -43,7 +48,9 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.failsafe.CheckedPredicateConverter.toCheckedPredicate; -import static org.zalando.riptide.micrometer.MockWebServerUtil.*; +import static org.zalando.riptide.micrometer.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.micrometer.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.micrometer.MockWebServerUtil.verify; final class MicrometerPluginTest { diff --git a/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/OpenTelemetryPlugin.java b/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/OpenTelemetryPlugin.java index d30a49b6a..d14004cc9 100644 --- a/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/OpenTelemetryPlugin.java +++ b/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/OpenTelemetryPlugin.java @@ -1,7 +1,5 @@ package org.zalando.riptide.opentelemetry; -import javax.annotation.Nonnull; - import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Multimaps; import io.opentelemetry.api.GlobalOpenTelemetry; @@ -26,6 +24,7 @@ import org.zalando.riptide.opentelemetry.span.PeerHostSpanDecorator; import org.zalando.riptide.opentelemetry.span.SpanDecorator; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.HashMap; import java.util.Map; diff --git a/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpPathSpanDecorator.java b/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpPathSpanDecorator.java index acb8ed732..27f1dd6f1 100644 --- a/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpPathSpanDecorator.java +++ b/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpPathSpanDecorator.java @@ -1,6 +1,5 @@ package org.zalando.riptide.opentelemetry.span; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; import org.zalando.riptide.RequestArguments; diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java index ed58c5ca7..f000c44ec 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java @@ -28,7 +28,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.zalando.riptide.*; +import org.zalando.riptide.AttributeStage; +import org.zalando.riptide.Bindings; +import org.zalando.riptide.Http; +import org.zalando.riptide.Navigators; +import org.zalando.riptide.RequestArguments; +import org.zalando.riptide.RequestExecution; import org.zalando.riptide.opentelemetry.span.HttpHostSpanDecorator; import org.zalando.riptide.opentelemetry.span.SpanDecorator; import org.zalando.riptide.opentelemetry.span.StaticSpanDecorator; @@ -48,12 +53,22 @@ import static java.util.Collections.singletonMap; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.zalando.riptide.NoRoute.noRoute; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.*; +import static org.zalando.riptide.opentelemetry.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.opentelemetry.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.opentelemetry.MockWebServerUtil.textMockResponse; +import static org.zalando.riptide.opentelemetry.MockWebServerUtil.verify; class OpenTelemetryPluginTest { @RegisterExtension diff --git a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/TracedTaskDecorator.java b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/TracedTaskDecorator.java index 885ab5cd1..50ed1a3b8 100644 --- a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/TracedTaskDecorator.java +++ b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/TracedTaskDecorator.java @@ -1,10 +1,10 @@ package org.zalando.riptide.opentracing; +import dev.failsafe.function.ContextualSupplier; import io.opentracing.Scope; import io.opentracing.Span; import io.opentracing.Tracer; import lombok.AllArgsConstructor; -import dev.failsafe.function.ContextualSupplier; import org.apiguardian.api.API; import org.zalando.riptide.failsafe.TaskDecorator; diff --git a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/ServiceLoaderSpanDecorator.java b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/ServiceLoaderSpanDecorator.java index 011ca6de1..086715e50 100644 --- a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/ServiceLoaderSpanDecorator.java +++ b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/ServiceLoaderSpanDecorator.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.ServiceLoader; -import java.util.stream.Collectors; import static java.util.ServiceLoader.load; import static java.util.stream.StreamSupport.stream; diff --git a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/SpanDecorator.java b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/SpanDecorator.java index 9fecaa807..dbc96f2ff 100644 --- a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/SpanDecorator.java +++ b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/SpanDecorator.java @@ -1,6 +1,5 @@ package org.zalando.riptide.opentracing.span; -import com.google.common.collect.Lists; import io.opentracing.Span; import org.apiguardian.api.API; import org.springframework.http.client.ClientHttpResponse; diff --git a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java index 1a084f161..2df518a9a 100644 --- a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java +++ b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java @@ -32,13 +32,23 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.zalando.riptide.NoRoute.noRoute; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.opentracing.MockWebServerUtil.*; +import static org.zalando.riptide.opentracing.MockWebServerUtil.emptyMockResponse; +import static org.zalando.riptide.opentracing.MockWebServerUtil.getBaseUrl; +import static org.zalando.riptide.opentracing.MockWebServerUtil.textMockResponse; +import static org.zalando.riptide.opentracing.MockWebServerUtil.verify; final class OpenTracingPluginTest { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java index ddda9d3c8..aa2dbcb17 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/BaseURL.java @@ -1,9 +1,10 @@ package org.zalando.riptide.autoconfigure; +import org.apiguardian.api.API; + +import javax.annotation.Nullable; import java.net.URI; import java.util.function.Supplier; -import javax.annotation.Nullable; -import org.apiguardian.api.API; import static org.apiguardian.api.API.Status.EXPERIMENTAL; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java index a5cb8063d..efc922502 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ClientHttpMessageConverters.java @@ -1,11 +1,12 @@ package org.zalando.riptide.autoconfigure; -import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; import org.apiguardian.api.API; import org.springframework.http.converter.HttpMessageConverter; +import java.util.List; + import static org.apiguardian.api.API.Status.STABLE; @API(status = STABLE) diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java index 03137638d..991540cd7 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideConfigurer.java @@ -3,12 +3,6 @@ import com.google.common.annotations.VisibleForTesting; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Predicate; import lombok.AllArgsConstructor; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -19,6 +13,13 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder; import org.zalando.logbook.Logbook; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Predicate; + import static org.zalando.riptide.autoconfigure.ValueConstants.LOGBOOK_REF; import static org.zalando.riptide.autoconfigure.ValueConstants.METER_REGISTRY_REF; import static org.zalando.riptide.autoconfigure.ValueConstants.TRACER_REF; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java index f5ab67674..cd48430dc 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/DefaultRiptideRegistrar.java @@ -9,17 +9,6 @@ import io.micrometer.core.instrument.Tags; import io.opentracing.contrib.concurrent.TracedExecutorService; import jakarta.xml.soap.SOAPConstants; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.time.Clock; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ExecutorService; -import java.util.function.Supplier; -import java.util.stream.Stream; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.hc.client5.http.cache.HttpCacheStorage; @@ -66,6 +55,18 @@ import org.zalando.riptide.soap.SOAPHttpMessageConverter; import org.zalando.riptide.stream.Streams; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.time.Clock; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; +import java.util.stream.Stream; + import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toCollection; import static java.util.stream.Collectors.toList; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java index e963716b1..d829b352f 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Defaulting.java @@ -2,12 +2,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.function.BinaryOperator; -import javax.annotation.Nullable; import lombok.extern.slf4j.Slf4j; import org.zalando.riptide.autoconfigure.RiptideProperties.Auth; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching; @@ -30,6 +24,13 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Tracing; import org.zalando.riptide.autoconfigure.RiptideProperties.TransientFaultDetection; +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.function.BinaryOperator; + import static com.google.common.collect.Maps.transformValues; import static java.lang.Math.max; import static java.util.Objects.requireNonNull; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java index 604742b49..c840e8e1b 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FailsafePluginFactory.java @@ -6,13 +6,6 @@ import dev.failsafe.RetryPolicyBuilder; import dev.failsafe.Timeout; import dev.failsafe.function.ContextualSupplier; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import javax.annotation.Nullable; import org.springframework.http.client.ClientHttpResponse; import org.zalando.riptide.Plugin; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; @@ -30,6 +23,14 @@ import org.zalando.riptide.failsafe.TaskDecorator; import org.zalando.riptide.idempotency.IdempotencyPredicate; +import javax.annotation.Nullable; +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + import static java.time.Clock.systemUTC; import static java.time.temporal.ChronoUnit.MILLIS; import static java.util.concurrent.TimeUnit.MILLISECONDS; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java index 397b8d1c0..e578ab6ec 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpClientFactory.java @@ -1,16 +1,6 @@ package org.zalando.riptide.autoconfigure; import com.google.gag.annotation.remark.Hack; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Path; -import java.security.GeneralSecurityException; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; -import javax.annotation.Nullable; -import javax.net.ssl.SSLContext; import lombok.extern.slf4j.Slf4j; import org.apache.hc.client5.http.cache.HttpCacheStorage; import org.apache.hc.client5.http.config.ConnectionConfig; @@ -35,6 +25,17 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Client; import org.zalando.riptide.autoconfigure.RiptideProperties.Connections; +import javax.annotation.Nullable; +import javax.net.ssl.SSLContext; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; + import static java.lang.String.format; @SuppressWarnings("unused") diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java index b3add26df..22bb35ee9 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/HttpFactory.java @@ -1,8 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.util.List; -import java.util.concurrent.Executor; -import javax.annotation.Nullable; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.zalando.riptide.Http; @@ -10,6 +7,10 @@ import org.zalando.riptide.Plugin; import org.zalando.riptide.UrlResolution; +import javax.annotation.Nullable; +import java.util.List; +import java.util.concurrent.Executor; + @SuppressWarnings("unused") final class HttpFactory { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java index f2c982d2f..a3aaf0517 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/MicrometerPluginFactory.java @@ -2,11 +2,12 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; -import java.util.Collection; import org.zalando.riptide.Plugin; import org.zalando.riptide.micrometer.MicrometerPlugin; import org.zalando.riptide.micrometer.tag.TagGenerator; +import java.util.Collection; + final class MicrometerPluginFactory { private MicrometerPluginFactory() { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java index 8dc9e0d0b..ba6f318e0 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Name.java @@ -1,12 +1,13 @@ package org.zalando.riptide.autoconfigure; +import lombok.AllArgsConstructor; + +import javax.annotation.Nullable; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; -import javax.annotation.Nullable; -import lombok.AllArgsConstructor; import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.LOWER_HYPHEN; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java index 5bc024b0f..407f4b399 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingPluginFactory.java @@ -1,9 +1,6 @@ package org.zalando.riptide.autoconfigure; import io.opentracing.Tracer; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nullable; import org.zalando.riptide.Plugin; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; import org.zalando.riptide.opentracing.OpenTracingPlugin; @@ -11,6 +8,10 @@ import org.zalando.riptide.opentracing.span.SpanDecorator; import org.zalando.riptide.opentracing.span.StaticSpanDecorator; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + import static org.zalando.riptide.opentracing.span.CompositeSpanDecorator.composite; @SuppressWarnings("unused") diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java index e591f04c9..1a2b5c1bb 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Ratio.java @@ -1,11 +1,12 @@ package org.zalando.riptide.autoconfigure; +import lombok.AllArgsConstructor; +import lombok.Getter; + import java.util.Optional; import java.util.function.BiConsumer; import java.util.regex.Matcher; import java.util.regex.Pattern; -import lombok.AllArgsConstructor; -import lombok.Getter; @AllArgsConstructor @Getter diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java index 33cfaceef..b6879f8c1 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RatioInTimeSpan.java @@ -1,9 +1,10 @@ package org.zalando.riptide.autoconfigure; +import lombok.Getter; + import java.time.Duration; import java.util.regex.Matcher; import java.util.regex.Pattern; -import lombok.Getter; @Getter final class RatioInTimeSpan { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java index 7de9f880d..d75fbbae7 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/Registry.java @@ -1,9 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.function.Supplier; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; @@ -15,6 +11,11 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.ManagedList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.function.Supplier; + import static org.zalando.riptide.autoconfigure.Name.name; @AllArgsConstructor diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java index e8c035151..8a3f25017 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideClientTest.java @@ -1,16 +1,17 @@ package org.zalando.riptide.autoconfigure; +import org.apiguardian.api.API; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer; +import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; +import org.springframework.core.annotation.AliasFor; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.apiguardian.api.API; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer; -import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; -import org.springframework.core.annotation.AliasFor; import static org.apiguardian.api.API.Status.EXPERIMENTAL; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java index 944b48079..147ae7551 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptidePostProcessor.java @@ -1,6 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.util.function.BiFunction; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -12,6 +11,8 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; +import java.util.function.BiFunction; + import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from; final class RiptidePostProcessor implements BeanDefinitionRegistryPostProcessor, EnvironmentAware { diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java index 5c061f7f5..270dca29c 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideProperties.java @@ -1,12 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.net.URI; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,6 +17,14 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Retry.Backoff; import org.zalando.riptide.httpclient.ApacheClientHttpRequestFactory.Mode; +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import static java.util.Collections.emptyMap; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java index a8a8c622a..d3150b6d3 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/ThreadPoolFactory.java @@ -1,10 +1,11 @@ package org.zalando.riptide.autoconfigure; -import java.util.concurrent.ThreadPoolExecutor; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.zalando.riptide.autoconfigure.RiptideProperties.Threads; import org.zalando.riptide.concurrent.ThreadPoolExecutors; +import java.util.concurrent.ThreadPoolExecutor; + import static org.zalando.riptide.concurrent.ThreadPoolExecutors.builder; @SuppressWarnings("unused") diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java index 234c64cc2..435b176d9 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/TimeSpan.java @@ -2,6 +2,11 @@ import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; + import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Arrays; @@ -12,10 +17,6 @@ import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.apache.hc.core5.util.TimeValue; -import org.apache.hc.core5.util.Timeout; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java index 65e9444db..926434445 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/AccessTokensCredentialsDirectoryTest.java @@ -1,6 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.io.IOException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -12,6 +11,8 @@ import org.springframework.test.context.ActiveProfiles; import org.zalando.riptide.auth.AuthorizationProvider; +import java.io.IOException; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java index 99900cc98..08f8d2f0d 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/BaseURLTest.java @@ -1,7 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.net.URI; -import java.util.concurrent.atomic.AtomicReference; import lombok.SneakyThrows; import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.Test; @@ -16,6 +14,9 @@ import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; import org.zalando.riptide.Http; +import java.net.URI; +import java.util.concurrent.atomic.AtomicReference; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java index 5645169f5..7053faa2e 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/CircuitBreakerTest.java @@ -1,7 +1,6 @@ package org.zalando.riptide.autoconfigure; import dev.failsafe.CircuitBreaker; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -10,6 +9,8 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.stereotype.Component; +import java.util.List; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java index 8fbc6a9d1..b3043dd3b 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ClientConfigurationTest.java @@ -1,7 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.lang.reflect.Field; -import java.util.concurrent.TimeUnit; import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.classic.HttpClient; import org.apache.hc.client5.http.config.ConnectionConfig; @@ -17,6 +15,9 @@ import org.springframework.web.client.RestOperations; import org.zalando.riptide.Http; +import java.lang.reflect.Field; +import java.util.concurrent.TimeUnit; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java index 0103a52b9..f9dc3be3c 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/DefaultingTest.java @@ -1,6 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; import org.zalando.riptide.autoconfigure.RiptideProperties.Caching.Heuristic; import org.zalando.riptide.autoconfigure.RiptideProperties.Client; @@ -8,6 +7,8 @@ import org.zalando.riptide.autoconfigure.RiptideProperties.Defaults; import org.zalando.riptide.autoconfigure.RiptideProperties.Threads; +import java.nio.file.Paths; + import static java.util.concurrent.TimeUnit.HOURS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java index 8920753b8..b86db94d7 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpClientFactoryTest.java @@ -1,13 +1,14 @@ package org.zalando.riptide.autoconfigure; import com.google.common.collect.ImmutableMap; -import java.io.FileNotFoundException; -import java.io.IOException; import org.junit.jupiter.api.Test; import org.zalando.riptide.autoconfigure.RiptideProperties.CertificatePinning; import org.zalando.riptide.autoconfigure.RiptideProperties.CertificatePinning.Keystore; import org.zalando.riptide.autoconfigure.RiptideProperties.Defaults; +import java.io.FileNotFoundException; +import java.io.IOException; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java index cec729284..6bab0ed6c 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/HttpMessageConvertersTest.java @@ -1,6 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -10,6 +9,8 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.stereotype.Component; +import java.util.List; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java index 9039ec5e2..08785a5e6 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/KeystoreIntegrationTest.java @@ -1,12 +1,13 @@ package org.zalando.riptide.autoconfigure; -import javax.net.ssl.SSLHandshakeException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.zalando.riptide.Http; +import javax.net.ssl.SSLHandshakeException; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java index 8c117d6a8..d771723f6 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/ManualConfiguration.java @@ -12,14 +12,6 @@ import io.opentracing.Tracer; import io.opentracing.contrib.concurrent.TracedExecutorService; import io.opentracing.noop.NoopTracerFactory; -import java.net.SocketTimeoutException; -import java.time.Clock; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.function.Predicate; import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; @@ -75,6 +67,15 @@ import org.zalando.riptide.soap.SOAPHttpMessageConverter; import org.zalando.riptide.stream.Streams; +import java.net.SocketTimeoutException; +import java.time.Clock; +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.function.Predicate; + import static java.time.Clock.systemUTC; import static java.time.temporal.ChronoUnit.MILLIS; import static java.util.Collections.singleton; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java index 4cf809956..9408c6429 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/MockWebServerUtil.java @@ -1,14 +1,15 @@ package org.zalando.riptide.autoconfigure; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; import okhttp3.Headers; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.springframework.http.HttpMethod; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + import static com.google.common.io.Resources.getResource; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.IntStream.range; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java index 2140bd482..c58cc0661 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NameTest.java @@ -1,13 +1,14 @@ package org.zalando.riptide.autoconfigure; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Stream; -import javax.annotation.Nullable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.zalando.riptide.Http; +import javax.annotation.Nullable; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Stream; + import static java.util.stream.Collectors.toSet; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.zalando.riptide.autoconfigure.Name.name; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java index 86bc5c24d..b0e43b082 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/NoCachingTest.java @@ -1,9 +1,10 @@ package org.zalando.riptide.autoconfigure; -import java.lang.reflect.Method; import org.junit.jupiter.api.Test; import org.springframework.util.ReflectionUtils; +import java.lang.reflect.Method; + import static org.junit.jupiter.api.Assertions.assertNotNull; final class NoCachingTest { diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java index 75a411f30..20148f504 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/PluginTest.java @@ -1,7 +1,5 @@ package org.zalando.riptide.autoconfigure; -import java.lang.reflect.Field; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -20,6 +18,9 @@ import org.zalando.riptide.opentelemetry.OpenTelemetryPlugin; import org.zalando.riptide.opentracing.OpenTracingPlugin; +import java.lang.reflect.Field; +import java.util.List; + import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java index 8ebe7e463..45cfd0c28 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioInTimeSpanTest.java @@ -1,9 +1,10 @@ package org.zalando.riptide.autoconfigure; +import org.junit.jupiter.api.Test; + import java.time.Duration; import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java index e65ce2236..af1523aca 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/RatioTest.java @@ -1,8 +1,9 @@ package org.zalando.riptide.autoconfigure; +import org.junit.jupiter.api.Test; + import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java index bd4a455d0..c3ce354c4 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/TimeSpanTest.java @@ -1,9 +1,10 @@ package org.zalando.riptide.autoconfigure; +import org.junit.jupiter.api.Test; + import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Test; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java index fd918db6c..c2593194c 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/metrics/MetricsTest.java @@ -4,8 +4,6 @@ import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import java.util.Arrays; -import java.util.Collection; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,11 +15,14 @@ import org.springframework.test.web.client.MockRestServiceServer; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; import org.zalando.riptide.Http; -import org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.autoconfigure.MetricsTestAutoConfiguration; +import org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; +import java.util.Arrays; +import java.util.Collection; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java index 410290c9c..c2a967674 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/retry/RetryTest.java @@ -1,6 +1,5 @@ package org.zalando.riptide.autoconfigure.retry; -import java.util.concurrent.CompletionException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -15,6 +14,8 @@ import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; +import java.util.concurrent.CompletionException; + import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpStatus.Series.SERVER_ERROR; import static org.springframework.test.web.client.ExpectedCount.times; diff --git a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java index 8fc966900..13521d0d8 100644 --- a/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java +++ b/riptide-spring-boot-autoconfigure/src/test/java/org/zalando/riptide/autoconfigure/url/UrlResolutionTest.java @@ -11,8 +11,8 @@ import org.springframework.test.web.client.MockRestServiceServer; import org.zalando.logbook.autoconfigure.LogbookAutoConfiguration; import org.zalando.riptide.Http; -import org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.autoconfigure.MetricsTestAutoConfiguration; +import org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration; import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration; import org.zalando.riptide.autoconfigure.RiptideClientTest; import org.zalando.riptide.opentracing.span.HttpUrlSpanDecorator; From 7eea50121e3537f3d12a9097d46e0b0a367fa58e Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 04:06:28 +0200 Subject: [PATCH 14/32] Replace deprecated getRawStatusCode() --- pom.xml | 2 +- .../org/zalando/riptide/ForwardingClientHttpResponseTest.java | 2 +- .../httpclient/AbstractApacheClientHttpRequestFactoryTest.java | 2 +- .../main/java/org/zalando/riptide/logbook/RemoteResponse.java | 2 +- .../riptide/logbook/RiptideLogbookCompatibilityTest.java | 2 +- .../zalando/riptide/micrometer/tag/HttpStatusTagGenerator.java | 2 +- .../riptide/opentelemetry/span/HttpStatusCodeSpanDecorator.java | 2 +- .../riptide/opentracing/span/HttpStatusCodeSpanDecorator.java | 2 +- .../src/test/java/org/zalando/riptide/stream/StreamsTest.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index fdf9ffb98..e2c1bd4ec 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ 17 17 - 6.0.9 + 6.0.10 diff --git a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java index 6d405a236..b076d0574 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java @@ -34,7 +34,7 @@ protected ClientHttpResponse delegate() { } }; - assertThat(unit.getRawStatusCode(), is(200)); + assertThat(unit.getStatusCode().value(), is(200)); assertThat(unit.getStatusCode(), is(OK)); assertThat(unit.getStatusText(), is("OK")); assertThat(new String(toByteArray(unit.getBody()), UTF_8), is("Hello World!")); diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java index 3ef7614e4..f7efec6f4 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/AbstractApacheClientHttpRequestFactoryTest.java @@ -162,7 +162,7 @@ void shouldReadContributorsManually() throws IOException { final ClientHttpResponse response = request.execute(); assertThat(response.getStatusCode(), is(HttpStatus.OK)); - assertThat(response.getRawStatusCode(), is(200)); + assertThat(response.getStatusCode().value(), is(200)); assertThat(response.getStatusText(), is("OK")); assertThat(response.getHeaders(), is(not(anEmptyMap()))); diff --git a/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java b/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java index a5c723477..1da0937ff 100644 --- a/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java +++ b/riptide-logbook/src/main/java/org/zalando/riptide/logbook/RemoteResponse.java @@ -150,7 +150,7 @@ public String getProtocolVersion() { @Override public int getStatus() { - return throwingFunction(ClientHttpResponse::getRawStatusCode).apply(response); + return throwingFunction(response -> ((ClientHttpResponse)response).getStatusCode().value()).apply(response); } @Override diff --git a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java index 3a40b4673..59822be7e 100644 --- a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java +++ b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java @@ -84,7 +84,7 @@ public void writeBoth(final Correlation correlation, final HttpRequest request, .join(); assertThat(response.getStatusCode(), is(HttpStatus.OK)); - assertThat(response.getRawStatusCode(), is(200)); + assertThat(response.getStatusCode().value(), is(200)); assertThat(response.getStatusText(), is("OK")); assertThat(response.getHeaders(), hasKey("Content-Type")); assertThat(new String(toByteArray(response.getBody()), UTF_8), is("World!")); diff --git a/riptide-micrometer/src/main/java/org/zalando/riptide/micrometer/tag/HttpStatusTagGenerator.java b/riptide-micrometer/src/main/java/org/zalando/riptide/micrometer/tag/HttpStatusTagGenerator.java index eac10f9f8..4c24bae7f 100644 --- a/riptide-micrometer/src/main/java/org/zalando/riptide/micrometer/tag/HttpStatusTagGenerator.java +++ b/riptide-micrometer/src/main/java/org/zalando/riptide/micrometer/tag/HttpStatusTagGenerator.java @@ -22,7 +22,7 @@ public Iterable onResponse( final RequestArguments arguments, final ClientHttpResponse response) throws IOException { - final String status = String.valueOf(response.getRawStatusCode()); + final String status = String.valueOf(response.getStatusCode().value()); return singleton(Tag.of(STATUS_CODE, status)); } diff --git a/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpStatusCodeSpanDecorator.java b/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpStatusCodeSpanDecorator.java index 44c448e6b..9f2f693b0 100644 --- a/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpStatusCodeSpanDecorator.java +++ b/riptide-opentelemetry/src/main/java/org/zalando/riptide/opentelemetry/span/HttpStatusCodeSpanDecorator.java @@ -20,7 +20,7 @@ public void onError(Span span, RequestArguments arguments, Throwable error) { @Override public void onResponse(Span span, RequestArguments arguments, ClientHttpResponse response) throws IOException { - setStatusCode(span, response.getRawStatusCode()); + setStatusCode(span, response.getStatusCode().value()); } private void setStatusCode(Span span, int statusCode) { diff --git a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/HttpStatusCodeSpanDecorator.java b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/HttpStatusCodeSpanDecorator.java index 2bd484f07..caae033a6 100644 --- a/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/HttpStatusCodeSpanDecorator.java +++ b/riptide-opentracing/src/main/java/org/zalando/riptide/opentracing/span/HttpStatusCodeSpanDecorator.java @@ -16,7 +16,7 @@ public final class HttpStatusCodeSpanDecorator implements SpanDecorator { @Override public void onResponse(final Span span, final RequestArguments arguments, final ClientHttpResponse response) throws IOException { - span.setTag(Tags.HTTP_STATUS, response.getRawStatusCode()); + span.setTag(Tags.HTTP_STATUS, response.getStatusCode().value()); } } diff --git a/riptide-stream/src/test/java/org/zalando/riptide/stream/StreamsTest.java b/riptide-stream/src/test/java/org/zalando/riptide/stream/StreamsTest.java index 650c6d179..23d9561a2 100644 --- a/riptide-stream/src/test/java/org/zalando/riptide/stream/StreamsTest.java +++ b/riptide-stream/src/test/java/org/zalando/riptide/stream/StreamsTest.java @@ -260,6 +260,6 @@ void shouldFailOnCallWithInvalidStream() { } private void fail(final ClientHttpResponse response) throws IOException { - throw new AssertionError(response.getRawStatusCode()); + throw new AssertionError(response.getStatusCode().value()); } } From 7d984bd2ee22ac3942cbc9518832648f4646a3aa Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 05:33:23 +0200 Subject: [PATCH 15/32] Fix coverage for riptide-core --- .../org/zalando/riptide/ForwardingClientHttpResponseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java index b076d0574..6d405a236 100644 --- a/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java +++ b/riptide-core/src/test/java/org/zalando/riptide/ForwardingClientHttpResponseTest.java @@ -34,7 +34,7 @@ protected ClientHttpResponse delegate() { } }; - assertThat(unit.getStatusCode().value(), is(200)); + assertThat(unit.getRawStatusCode(), is(200)); assertThat(unit.getStatusCode(), is(OK)); assertThat(unit.getStatusText(), is("OK")); assertThat(new String(toByteArray(unit.getBody()), UTF_8), is("Hello World!")); From 51c0266ecb3b57ea5e836a11912baace48a33f7f Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 05:33:35 +0200 Subject: [PATCH 16/32] Fix coverage for riptide-httpclient --- .../BufferingApacheClientHttpRequest.java | 11 +++++---- .../StreamingApacheClientHttpRequest.java | 8 +++++-- .../ApacheClientHttpResponseBodyTest.java | 12 ++++++++++ .../BufferingApacheClientHttpRequestTest.java | 23 +++++++++++++++++++ .../StreamingApacheClientHttpRequestTest.java | 13 +++++++++++ 5 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java index 53d3bb05a..089f0fd34 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java @@ -19,6 +19,7 @@ import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; +import java.util.Optional; @AllArgsConstructor final class BufferingApacheClientHttpRequest implements ClientHttpRequest { @@ -30,6 +31,7 @@ final class BufferingApacheClientHttpRequest implements ClientHttpRequest { private final HttpUriRequest request; @Override + @Nonnull public HttpMethod getMethod() { return HttpMethod.valueOf(request.getMethod()); } @@ -57,6 +59,7 @@ public OutputStream getBody() { } @Override + @Nonnull public ClientHttpResponse execute() throws IOException { Headers.writeHeaders(headers, request); request.setEntity(new ByteArrayEntity(output.toByteArray(), toContentType(headers.getContentType()))); @@ -67,10 +70,10 @@ public ClientHttpResponse execute() throws IOException { @Nullable private ContentType toContentType(@Nullable MediaType mediaType) { - if (mediaType == null) { - return null; - } - return ContentType.create(mediaType.toString()); + return Optional.ofNullable(mediaType) + .map(MediaType::toString) + .map(ContentType::create) + .orElse(null); } } diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java index afb859e23..54c2d454e 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java @@ -35,6 +35,7 @@ final class StreamingApacheClientHttpRequest implements ClientHttpRequest, Strea private final HttpUriRequest request; @Override + @Nonnull public HttpMethod getMethod() { return HttpMethod.valueOf(request.getMethod()); } @@ -63,10 +64,13 @@ public OutputStream getBody() { @Override public void setBody(final Body body) { - request.setEntity(new StreamingHttpEntity(body)); + try (StreamingHttpEntity streamingHttpEntity = new StreamingHttpEntity(body)) { + request.setEntity(streamingHttpEntity); + } } @Override + @Nonnull public ClientHttpResponse execute() throws IOException { Headers.writeHeaders(headers, request); final HttpResponse response = client.execute(request); @@ -131,7 +135,7 @@ public Supplier> getTrailers() { } @Override - public void close() throws IOException { + public void close() { } diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java index 73ab33d21..76ae201c2 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/ApacheClientHttpResponseBodyTest.java @@ -2,12 +2,14 @@ import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.io.entity.InputStreamEntity; import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -26,4 +28,14 @@ void shouldCallCloseOnNormalStreams() throws IOException { verify(stream).close(); } + @Test + void shouldReturnEmptyWhenResponseIsNotHttpEntityContainer() throws IOException { + final HttpResponse httpResponse = mock(HttpResponse.class); + when(httpResponse.getHeaders()).thenReturn(new Header[0]); + + try (final ApacheClientHttpResponse x = new ApacheClientHttpResponse(httpResponse)) { + assertThat(x.getBody()).isEqualTo(EmptyInputStream.EMPTY); + } + } + } diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java new file mode 100644 index 000000000..83a7063e0 --- /dev/null +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java @@ -0,0 +1,23 @@ +package org.zalando.riptide.httpclient; + +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; +import org.junit.jupiter.api.Test; + +import java.net.URISyntaxException; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class BufferingApacheClientHttpRequestTest { + + @Test + void shouldThrowIllegalArgumentException() throws URISyntaxException { + final HttpUriRequest httpUriRequest = mock(HttpUriRequest.class); + when(httpUriRequest.getUri()).thenThrow(URISyntaxException.class); + + final BufferingApacheClientHttpRequest request = new BufferingApacheClientHttpRequest(null, httpUriRequest); + assertThrows(IllegalArgumentException.class, request::getURI); + } + +} \ No newline at end of file diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java index 326a379be..afc05afe7 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequestTest.java @@ -2,14 +2,18 @@ import org.apache.hc.client5.http.classic.HttpClient; import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; import org.apache.hc.core5.http.HttpEntity; import org.junit.jupiter.api.Test; import org.springframework.http.StreamingHttpOutputMessage.Body; import org.springframework.http.client.ClientHttpRequest; +import java.net.URISyntaxException; + import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; final class StreamingApacheClientHttpRequestTest { @@ -38,4 +42,13 @@ void shouldNotSupportGetBody() { assertThrows(UnsupportedOperationException.class, unit::getBody); } + @Test + void shouldThrowIllegalArgumentException() throws URISyntaxException { + final HttpUriRequest httpUriRequest = mock(HttpUriRequest.class); + when(httpUriRequest.getUri()).thenThrow(URISyntaxException.class); + + final StreamingApacheClientHttpRequest request = new StreamingApacheClientHttpRequest(null, httpUriRequest); + assertThrows(IllegalArgumentException.class, request::getURI); + } + } From e45679e13b76b3b34df434c787e9268b0aa37e4a Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 06:03:07 +0200 Subject: [PATCH 17/32] Fix coverage for riptide-chaos --- .../riptide/chaos/ErrorResponseInjection.java | 19 ++----------------- .../riptide/chaos/ChaosPluginTest.java | 3 ++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java b/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java index 3657d9d54..eea5038bc 100644 --- a/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java +++ b/riptide-chaos/src/main/java/org/zalando/riptide/chaos/ErrorResponseInjection.java @@ -47,22 +47,10 @@ private ClientHttpResponse injectIfNecessary( return response; } - try { + try (response) { final HttpStatus status = choose(); log.debug("Injecting '{}' error response", status); return new ErrorClientHttpResponse(status); - } finally { - response.close(); - } - } - - private boolean isError(final HttpStatus status) { - switch (status.series()) { - case CLIENT_ERROR: - case SERVER_ERROR: - return true; - default: - return false; } } @@ -70,10 +58,7 @@ private HttpStatus choose() { return statuses.get(ThreadLocalRandom.current().nextInt(statuses.size())); } - @AllArgsConstructor - private static class ErrorClientHttpResponse implements ClientHttpResponse { - - private final HttpStatus status; + private record ErrorClientHttpResponse(HttpStatus status) implements ClientHttpResponse { @Nonnull @Override diff --git a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java index e34664660..ea32c4ed9 100644 --- a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java +++ b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java @@ -219,7 +219,8 @@ void shouldInjectLatencyAndErrorResponse() throws IOException { final Instant end = clock.instant(); assertThat(Duration.between(start, end), is(greaterThanOrEqualTo(Duration.ofSeconds(1)))); - assertThat(response.getStatusCode().value(), is(oneOf(500, 503))); + // noinspection deprecation : Using getRawStatusCode() to satisfy coverage + assertThat(response.getRawStatusCode(), is(oneOf(500, 503))); verify(server, 1, "/foo"); } From a7437ba743471462d249aab1b4c56c6e6b376bd4 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 06:33:33 +0200 Subject: [PATCH 18/32] Fix coverage for riptide-idempotency --- .../MethodOverrideIdempotencyDetector.java | 14 +++++--- ...MethodOverrideIdempotencyDetectorTest.java | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java diff --git a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetector.java b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetector.java index 3a9b12e9b..0ebfeb226 100644 --- a/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetector.java +++ b/riptide-idempotency/src/main/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetector.java @@ -6,6 +6,7 @@ import org.zalando.riptide.RequestArguments; import javax.annotation.Nullable; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -20,6 +21,8 @@ @Slf4j public final class MethodOverrideIdempotencyDetector implements IdempotencyDetector { + private static final List validMethods = Arrays.asList(HttpMethod.values()); + @Override public Decision test(final RequestArguments arguments, final Test root) { if (arguments.getMethod() != POST) { @@ -47,12 +50,13 @@ private HttpMethod getOverride(final RequestArguments arguments) { return null; } - try { - return HttpMethod.valueOf(override); - } catch (final IllegalArgumentException e) { - log.warn("Received invalid method in {} header: \"{}\"", name, override); - return null; + final HttpMethod method = HttpMethod.valueOf(override); + if (validMethods.contains(method)) { + return method; } + + log.warn("Received invalid method in {} header: \"{}\"", name, override); + return null; } } diff --git a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java new file mode 100644 index 000000000..4a04ca5d7 --- /dev/null +++ b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java @@ -0,0 +1,33 @@ +package org.zalando.riptide.idempotency; + +import org.junit.jupiter.api.Test; +import org.zalando.riptide.RequestArguments; + +import java.util.Collections; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.springframework.http.HttpMethod.POST; + +class MethodOverrideIdempotencyDetectorTest { + + @Test + public void should() { + final RequestArguments arguments = mock(RequestArguments.class); + final IdempotencyDetector.Test test = mock(IdempotencyDetector.Test.class); + + when(arguments.getMethod()).thenReturn(POST); + when(arguments.getHeaders()).thenReturn( + Map.of("X-HTTP-Method-Override", Collections.singletonList("BAD_METHOD")) + ); + + final MethodOverrideIdempotencyDetector methodOverrideIdempotencyDetector + = new MethodOverrideIdempotencyDetector(); + + assertThat(methodOverrideIdempotencyDetector.test(arguments, test), is(Decision.NEUTRAL)); + } + +} \ No newline at end of file From 6964228ed1048ecfaa594ea917a1c6955caf404c Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 06:39:11 +0200 Subject: [PATCH 19/32] Use better test name --- .../idempotency/MethodOverrideIdempotencyDetectorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java index 4a04ca5d7..7111a7608 100644 --- a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java +++ b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java @@ -15,7 +15,7 @@ class MethodOverrideIdempotencyDetectorTest { @Test - public void should() { + public void shouldDealWithIncorrectHttpMethodOverride() { final RequestArguments arguments = mock(RequestArguments.class); final IdempotencyDetector.Test test = mock(IdempotencyDetector.Test.class); From b1b25e56c5df87aacc460615f23c83328cd94caf Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 06:58:45 +0200 Subject: [PATCH 20/32] Fix coverage for riptide-failsafe --- .../failsafe/RateLimitResetDelayFunctionTest.java | 11 +++++++++++ .../riptide/failsafe/RetryAfterDelayFunctionTest.java | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java index b6de17f80..308bd91ba 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RateLimitResetDelayFunctionTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Stopwatch; import dev.failsafe.CircuitBreaker; +import dev.failsafe.ExecutionContext; import dev.failsafe.RetryPolicy; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -29,7 +30,9 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertTimeout; +import static org.mockito.Mockito.mock; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; import static org.zalando.riptide.Bindings.anySeries; @@ -156,6 +159,14 @@ void shouldRetryWithDelayEpochSeconds() { verify(server, 2, "/baz"); } + @Test + void shouldGetDefaultDuration() { + RateLimitResetDelayFunction rateLimitResetDelayFunction = new RateLimitResetDelayFunction(clock); + @SuppressWarnings("unchecked") + ExecutionContext context = mock(ExecutionContext.class); + assertThat(rateLimitResetDelayFunction.get(context), is(Duration.ofMinutes(-1))); + } + private void atLeast(final Duration minimum, final Runnable runnable) { final Duration actual = time(runnable); diff --git a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java index 5d59b6547..9393a1a07 100644 --- a/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java +++ b/riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/RetryAfterDelayFunctionTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Stopwatch; import dev.failsafe.CircuitBreaker; +import dev.failsafe.ExecutionContext; import dev.failsafe.RetryPolicy; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -29,7 +30,9 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertTimeout; +import static org.mockito.Mockito.mock; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; import static org.springframework.http.HttpStatus.Series.SUCCESSFUL; import static org.zalando.riptide.Bindings.anySeries; @@ -154,6 +157,14 @@ void shouldRetryWithDynamicDelayDate() { verify(server, 2, "/baz"); } + @Test + void shouldGetDefaultDuration() { + RetryAfterDelayFunction retryAfterDelayFunction = new RetryAfterDelayFunction(clock); + @SuppressWarnings("unchecked") + ExecutionContext context = mock(ExecutionContext.class); + assertThat(retryAfterDelayFunction.get(context), is(Duration.ofMinutes(-1))); + } + private void atLeast(final Duration minimum, final Runnable runnable) { final Duration actual = time(runnable); From 8e98d15a19da87c0c5c6d193cba1f8c0c8e4cc58 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 07:05:15 +0200 Subject: [PATCH 21/32] Fix coverage for riptide-logbook --- .../test/java/org/zalando/riptide/chaos/ChaosPluginTest.java | 2 +- .../riptide/logbook/RiptideLogbookCompatibilityTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java index ea32c4ed9..80c7a1add 100644 --- a/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java +++ b/riptide-chaos/src/test/java/org/zalando/riptide/chaos/ChaosPluginTest.java @@ -219,7 +219,7 @@ void shouldInjectLatencyAndErrorResponse() throws IOException { final Instant end = clock.instant(); assertThat(Duration.between(start, end), is(greaterThanOrEqualTo(Duration.ofSeconds(1)))); - // noinspection deprecation : Using getRawStatusCode() to satisfy coverage + // noinspection deprecation: Using getRawStatusCode() to satisfy coverage assertThat(response.getRawStatusCode(), is(oneOf(500, 503))); verify(server, 1, "/foo"); } diff --git a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java index 59822be7e..45064a328 100644 --- a/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java +++ b/riptide-logbook/src/test/java/org/zalando/riptide/logbook/RiptideLogbookCompatibilityTest.java @@ -84,7 +84,8 @@ public void writeBoth(final Correlation correlation, final HttpRequest request, .join(); assertThat(response.getStatusCode(), is(HttpStatus.OK)); - assertThat(response.getStatusCode().value(), is(200)); + // noinspection deprecation: Using getRawStatusCode() to satisfy coverage + assertThat(response.getRawStatusCode(), is(200)); assertThat(response.getStatusText(), is("OK")); assertThat(response.getHeaders(), hasKey("Content-Type")); assertThat(new String(toByteArray(response.getBody()), UTF_8), is("World!")); From f3f9f23c0403fba5b0bf7d907aa7bf69d454c594 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 07:25:16 +0200 Subject: [PATCH 22/32] Use executeOpen() HttpClient#execute(ClassicHttpRequest) is deprecated. Using executeOpen() shows the intent that the response should be kept open. --- .../riptide/httpclient/BufferingApacheClientHttpRequest.java | 2 +- .../riptide/httpclient/StreamingApacheClientHttpRequest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java index 089f0fd34..fdf2b0868 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequest.java @@ -64,7 +64,7 @@ public ClientHttpResponse execute() throws IOException { Headers.writeHeaders(headers, request); request.setEntity(new ByteArrayEntity(output.toByteArray(), toContentType(headers.getContentType()))); - final HttpResponse response = client.execute(request); + final HttpResponse response = client.executeOpen(null, request, null); return new ApacheClientHttpResponse(response); } diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java index 54c2d454e..5c732af2d 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/StreamingApacheClientHttpRequest.java @@ -73,7 +73,7 @@ public void setBody(final Body body) { @Nonnull public ClientHttpResponse execute() throws IOException { Headers.writeHeaders(headers, request); - final HttpResponse response = client.execute(request); + final HttpResponse response = client.executeOpen(null, request, null); return new ApacheClientHttpResponse(response); } From 97ff505cb538cbb6081c78914222d1cdf0ddfd70 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 07:42:06 +0200 Subject: [PATCH 23/32] Remove some warnings --- .../riptide/stream/StreamConverter.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamConverter.java b/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamConverter.java index 106de882b..49a86ed71 100644 --- a/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamConverter.java +++ b/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamConverter.java @@ -11,6 +11,7 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; @@ -30,13 +31,13 @@ final class StreamConverter implements GenericHttpMessageConverter> private final List supportedMediaTypes; @Override - public boolean canRead(final Class clazz, final MediaType mediaType) { + public boolean canRead(final Class clazz, @Nullable final MediaType mediaType) { // we only support generics return false; } @Override - public boolean canRead(final Type type, @Nullable final Class contextClass, final MediaType mediaType) { + public boolean canRead(final Type type, @Nullable final Class contextClass, @Nullable final MediaType mediaType) { final JavaType javaType = getJavaType(type, contextClass); if (Stream.class.isAssignableFrom(javaType.getRawClass())) { @@ -52,11 +53,13 @@ private boolean canRead(@Nullable final MediaType mediaType) { } @Override + @Nonnull public List getSupportedMediaTypes() { return Collections.unmodifiableList(supportedMediaTypes); } @Override + @Nonnull public Stream read(final Class> clazz, final HttpInputMessage inputMessage) throws HttpMessageNotReadableException { // we only support generics @@ -64,7 +67,8 @@ public Stream read(final Class> clazz, final HttpInputMes } @Override - public Stream read(final Type type, final Class contextClass, final HttpInputMessage inputMessage) + @Nonnull + public Stream read(final Type type, @Nullable final Class contextClass, final HttpInputMessage inputMessage) throws HttpMessageNotReadableException { final JavaType javaType = getJavaType(type, contextClass); return read(javaType, inputMessage); @@ -84,7 +88,7 @@ private Stream read(final JavaType javaType, final HttpInputMessage inputMess final InputStream body = extractBody(inputMessage); return stream(elementType, body); } catch (final IOException ex) { - throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex); + throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex, inputMessage); } } @@ -101,22 +105,25 @@ private Stream stream(final JavaType elementType, final InputStream stream) t } @Override - public boolean canWrite(final Class clazz, final MediaType mediaType) { + public boolean canWrite(final Class clazz, @Nullable final MediaType mediaType) { return false; } // @Override since 4.2 - public boolean canWrite(final Type type, final Class clazz, final MediaType mediaType) { + public boolean canWrite(@Nullable final Type type, final Class clazz, @Nullable final MediaType mediaType) { return false; } @Override - public void write(final Stream t, final MediaType mediaType, final HttpOutputMessage message) { + public void write(final Stream t, @Nullable final MediaType mediaType, final HttpOutputMessage message) { throw new UnsupportedOperationException(); } // @Override since 4.2 - public void write(final Stream t, final Type type, final MediaType mediaType, final HttpOutputMessage message) { + public void write(final Stream t, + @Nullable final Type type, + @Nullable final MediaType mediaType, + final HttpOutputMessage message) { throw new UnsupportedOperationException(); } From f05fcb763d57717387c7ac7b22d4a127b9cc52a2 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 08:10:24 +0200 Subject: [PATCH 24/32] Fix typo --- .../micrometer/MicrometerPluginTest.java | 21 ++++++---------- .../OpenTelemetryPluginTest.java | 25 ++++--------------- .../opentracing/OpenTracingPluginTest.java | 22 +++++----------- 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java index c45a17d2c..1dec8f369 100644 --- a/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java +++ b/riptide-micrometer/src/test/java/org/zalando/riptide/micrometer/MicrometerPluginTest.java @@ -33,12 +33,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.iterableWithSize; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.OK; @@ -48,9 +43,7 @@ import static org.zalando.riptide.Navigators.series; import static org.zalando.riptide.PassRoute.pass; import static org.zalando.riptide.failsafe.CheckedPredicateConverter.toCheckedPredicate; -import static org.zalando.riptide.micrometer.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.micrometer.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.micrometer.MockWebServerUtil.verify; +import static org.zalando.riptide.micrometer.MockWebServerUtil.*; final class MicrometerPluginTest { @@ -111,7 +104,7 @@ void shouldRecordSuccessResponseMetric() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/foo")); assertThat(timer.getId().getTag("http.status_code"), is("200")); - assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("client"), is("example")); assertThat(timer.getId().getTag("test"), is("true")); @@ -137,7 +130,7 @@ void shouldRecordRetryNumberMetricTag() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/foo")); assertThat(timer.getId().getTag("http.status_code"), is("500")); - assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("retry_number"), is("0")); assertThat(timer.totalTime(NANOSECONDS), is(greaterThan(0.0))); @@ -149,7 +142,7 @@ void shouldRecordRetryNumberMetricTag() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/foo")); assertThat(timer.getId().getTag("http.status_code"), is("200")); - assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("retry_number"), is("1")); assertThat(timer.totalTime(NANOSECONDS), is(greaterThan(0.0))); @@ -174,7 +167,7 @@ void shouldRecordErrorResponseMetric() { assertThat(timer.getId().getTag("http.method"), is("POST")); assertThat(timer.getId().getTag("http.path"), is("")); assertThat(timer.getId().getTag("http.status_code"), is("500")); - assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("none")); assertThat(timer.getId().getTag("client"), is("example")); assertThat(timer.getId().getTag("test"), is("true")); @@ -198,7 +191,7 @@ void shouldNotRecordFailureMetric() { assertThat(timer.getId().getTag("http.method"), is("GET")); assertThat(timer.getId().getTag("http.path"), is("/err")); assertThat(timer.getId().getTag("http.status_code"), is("0")); - assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(timer.getId().getTag("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); assertThat(timer.getId().getTag("error.kind"), is("SocketTimeoutException")); assertThat(timer.getId().getTag("client"), is("example")); assertThat(timer.getId().getTag("test"), is("true")); diff --git a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java index f000c44ec..63fbcaeda 100644 --- a/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java +++ b/riptide-opentelemetry/src/test/java/org/zalando/riptide/opentelemetry/OpenTelemetryPluginTest.java @@ -28,12 +28,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.zalando.riptide.AttributeStage; -import org.zalando.riptide.Bindings; -import org.zalando.riptide.Http; -import org.zalando.riptide.Navigators; -import org.zalando.riptide.RequestArguments; -import org.zalando.riptide.RequestExecution; +import org.zalando.riptide.*; import org.zalando.riptide.opentelemetry.span.HttpHostSpanDecorator; import org.zalando.riptide.opentelemetry.span.SpanDecorator; import org.zalando.riptide.opentelemetry.span.StaticSpanDecorator; @@ -53,22 +48,12 @@ import static java.util.Collections.singletonMap; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.zalando.riptide.NoRoute.noRoute; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.textMockResponse; -import static org.zalando.riptide.opentelemetry.MockWebServerUtil.verify; +import static org.zalando.riptide.opentelemetry.MockWebServerUtil.*; class OpenTelemetryPluginTest { @RegisterExtension @@ -253,7 +238,7 @@ void shouldTraceRequestAndIgnoreClientError() { final Attributes attributes = child.getAttributes(); assertThat(attributes.get(AttributeKey.stringKey("env")), is("unittest")); assertThat(attributes.get(AttributeKey.stringKey("http.method")), is("GET")); - assertThat(attributes.get(AttributeKey.stringKey("peer.hostname")), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(attributes.get(AttributeKey.stringKey("peer.hostname")), anyOf(is("localhost"), is("127.0.0.1"))); assertThat(attributes.get(AttributeKey.longKey("http.status_code")), is(400L)); verify(server, 1, "/"); @@ -321,7 +306,7 @@ void shouldOverwriteDefaultSetOfDecorators() { final Attributes attributes = child.getAttributes(); assertThat(attributes.size(), is(1)); - assertThat(attributes.get(AttributeKey.stringKey("http.host")), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(attributes.get(AttributeKey.stringKey("http.host")), anyOf(is("localhost"), is("127.0.0.1"))); verify(server, 1, "/"); } diff --git a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java index 2df518a9a..e17aa4566 100644 --- a/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java +++ b/riptide-opentracing/src/test/java/org/zalando/riptide/opentracing/OpenTracingPluginTest.java @@ -32,23 +32,13 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.hasKey; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.HttpMethod.POST; import static org.zalando.riptide.NoRoute.noRoute; import static org.zalando.riptide.PassRoute.pass; -import static org.zalando.riptide.opentracing.MockWebServerUtil.emptyMockResponse; -import static org.zalando.riptide.opentracing.MockWebServerUtil.getBaseUrl; -import static org.zalando.riptide.opentracing.MockWebServerUtil.textMockResponse; -import static org.zalando.riptide.opentracing.MockWebServerUtil.verify; +import static org.zalando.riptide.opentracing.MockWebServerUtil.*; final class OpenTracingPluginTest { @@ -121,7 +111,7 @@ void shouldTraceRequestAndResponse() { assertThat(child.tags(), hasEntry("spi", true)); assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); - assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); // not active by default assertThat(child.tags(), not(hasKey("http.url"))); @@ -184,7 +174,7 @@ void shouldTraceRequestAndServerError() { assertThat(child.tags(), hasEntry("spi", true)); assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); - assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); // since we didn't use a uri template assertThat(child.tags(), not(hasKey("http.path"))); @@ -230,7 +220,7 @@ void shouldTraceRequestAndNetworkError() { assertThat(child.tags(), hasEntry("error", true)); assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); - assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); // since we didn't use a uri template assertThat(child.tags(), not(hasKey("http.path"))); @@ -292,7 +282,7 @@ void shouldTraceRequestAndIgnoreClientError() { assertThat(child.tags(), hasEntry("http.status_code", 400)); assertThat(child.tags().get("peer.address"), anyOf(is("localhost:" + port), is("127.0.0.1:" + port))); - assertThat(child.tags().get("peer.hostname"), anyOf(is("hostname"), is("127.0.0.1"))); + assertThat(child.tags().get("peer.hostname"), anyOf(is("localhost"), is("127.0.0.1"))); // since we didn't use a uri template assertThat(child.tags(), not(hasKey("error"))); From 47a3ec8ed62beda8ff02f8edd6f246c8bea633f3 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 09:58:03 +0200 Subject: [PATCH 25/32] Update maven to 3.9+ and enable cache-extension maven-build-cache-extension improves build times. It requires Maven 3.9. --- .mvn/extensions.xml | 10 + .mvn/wrapper/MavenWrapperDownloader.java | 117 ------------ .mvn/wrapper/maven-wrapper.properties | 20 +- mvnw | 226 +++++++++++------------ mvnw.cmd | 59 ++++-- 5 files changed, 181 insertions(+), 251 deletions(-) create mode 100644 .mvn/extensions.xml delete mode 100644 .mvn/wrapper/MavenWrapperDownloader.java diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 000000000..b54a60b70 --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,10 @@ + + + + org.apache.maven.extensions + maven-build-cache-extension + 1.0.0 + + + diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index b901097f2..000000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index ffdc10e59..281ebbff8 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,18 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/mvnw b/mvnw index 41c0f0c23..66df28542 100755 --- a/mvnw +++ b/mvnw @@ -8,7 +8,7 @@ # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven Start Up Batch script +# Apache Maven Wrapper startup batch script, version 3.2.0 # # Required ENV vars: # ------------------ @@ -27,7 +27,6 @@ # # Optional ENV vars # ----------------- -# M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @@ -36,6 +35,10 @@ if [ -z "$MAVEN_SKIP_RC" ] ; then + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi @@ -50,7 +53,7 @@ fi cygwin=false; darwin=false; mingw=false -case "`uname`" in +case "$(uname)" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true @@ -58,9 +61,9 @@ case "`uname`" in # See https://developer.apple.com/library/mac/qa/qa1170/_index.html if [ -z "$JAVA_HOME" ]; then if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME else - export JAVA_HOME="/Library/Java/Home" + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME fi fi ;; @@ -68,68 +71,38 @@ esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` + JAVA_HOME=$(java-config --jre-home) fi fi -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") fi # For Mingw, ensure paths are in UNIX format before anything is touched if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" fi if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + javaHome="$(dirname "\"$javaExecutable\"")" + javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" else - javaExecutable="`readlink -f \"$javaExecutable\"`" + javaExecutable="$(readlink -f "\"$javaExecutable\"")" fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` + javaHome="$(dirname "\"$javaExecutable\"")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') JAVA_HOME="$javaHome" export JAVA_HOME fi @@ -145,7 +118,7 @@ if [ -z "$JAVACMD" ] ; then JAVACMD="$JAVA_HOME/bin/java" fi else - JAVACMD="`which java`" + JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" fi fi @@ -159,12 +132,9 @@ if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { - if [ -z "$1" ] then echo "Path not specified to find_maven_basedir" @@ -180,96 +150,99 @@ find_maven_basedir() { fi # workaround for JBEAP-8937 (on Solaris 10/Sparc) if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` + wdir=$(cd "$wdir/.." || exit 1; pwd) fi # end of workaround done - echo "${basedir}" + printf '%s' "$(cd "$basedir" || exit 1; pwd)" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" fi } -BASE_DIR=`find_maven_basedir "$(pwd)"` +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") if [ -z "$BASE_DIR" ]; then exit 1; fi +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + ########################################################################################## # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central # This allows using the maven wrapper in projects that prohibit checking in binary data. ########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi + log "Couldn't find $wrapperJarPath, downloading it ..." + if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") fi if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" fi elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" fi - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" # For Cygwin, switch paths to Windows format before running javac if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" fi fi fi @@ -278,33 +251,58 @@ fi # End of extension ########################################################################################## -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi fi + MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # For Cygwin, switch paths to Windows format before running java if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") fi # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" export MAVEN_CMD_LINE_ARGS WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain +# shellcheck disable=SC2086 # safe args exec "$JAVACMD" \ $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd index 86115719e..95ba6f54a 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -7,7 +7,7 @@ @REM "License"); you may not use this file except in compliance @REM with the License. You may obtain a copy of the License at @REM -@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM https://www.apache.org/licenses/LICENSE-2.0 @REM @REM Unless required by applicable law or agreed to in writing, @REM software distributed under the License is distributed on an @@ -18,13 +18,12 @@ @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script +@REM Apache Maven Wrapper startup batch script, version 3.2.0 @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @@ -46,8 +45,8 @@ if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* :skipRcPre @setlocal @@ -120,10 +119,10 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B ) @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central @@ -134,11 +133,11 @@ if exist %WRAPPER_JAR% ( ) ) else ( if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" ) if "%MVNW_VERBOSE%" == "true" ( echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% + echo Downloading from: %WRAPPER_URL% ) powershell -Command "&{"^ @@ -146,7 +145,7 @@ if exist %WRAPPER_JAR% ( "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ "}" if "%MVNW_VERBOSE%" == "true" ( echo Finished downloading %WRAPPER_JAR% @@ -154,11 +153,35 @@ if exist %WRAPPER_JAR% ( ) @REM End of extension +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + @REM Provide a "standardized" way to retrieve the CLI args that will @REM work with both Windows and non-Windows executions. set MAVEN_CMD_LINE_ARGS=%* -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* if ERRORLEVEL 1 goto error goto end @@ -168,15 +191,15 @@ set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause +if "%MAVEN_BATCH_PAUSE%"=="on" pause -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% -exit /B %ERROR_CODE% +cmd /C exit /B %ERROR_CODE% From 408a7663db0cf9a1aeb2f756044ef32c5e870c71 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:28:41 +0200 Subject: [PATCH 26/32] Update maven wrapper to check build cache --- .mvn/wrapper/maven-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 281ebbff8..e1d6b156e 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar From 7052bffa9ad42fdf76cdd5505aeb2db07ff01518 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Sat, 17 Jun 2023 22:24:39 +0200 Subject: [PATCH 27/32] Bump dependencies --- pom.xml | 4 ++-- riptide-core/pom.xml | 2 +- riptide-opentelemetry/pom.xml | 2 +- riptide-parent/pom.xml | 4 ++-- riptide-spring-boot-autoconfigure/pom.xml | 3 +-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index e2c1bd4ec..d279582d3 100644 --- a/pom.xml +++ b/pom.xml @@ -122,7 +122,7 @@ org.owasp dependency-check-maven - 8.2.1 + 8.3.1 @@ -180,7 +180,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.0 + 3.1.2 true classesAndMethods diff --git a/riptide-core/pom.xml b/riptide-core/pom.xml index fd026052f..f1f068662 100644 --- a/riptide-core/pom.xml +++ b/riptide-core/pom.xml @@ -36,7 +36,7 @@ org.organicdesign Paguro - 3.1.2 + 3.10.3 org.springframework diff --git a/riptide-opentelemetry/pom.xml b/riptide-opentelemetry/pom.xml index 6c290f80f..b00c247c8 100644 --- a/riptide-opentelemetry/pom.xml +++ b/riptide-opentelemetry/pom.xml @@ -17,7 +17,7 @@ Client side response routing - 1.26.0 + 1.27.0 ${opentelemetry.version}-alpha diff --git a/riptide-parent/pom.xml b/riptide-parent/pom.xml index 93b905ae8..e2b8e58ff 100644 --- a/riptide-parent/pom.xml +++ b/riptide-parent/pom.xml @@ -19,9 +19,9 @@ 0.9.0 2.15.2 2.15.2 - 5.9.3 + 5.10.0-M1 3.0.0 - 1.11.0 + 1.11.1 5.3.1 0.27.1 2.0.7 diff --git a/riptide-spring-boot-autoconfigure/pom.xml b/riptide-spring-boot-autoconfigure/pom.xml index 6cb21df65..7c34ff1b2 100644 --- a/riptide-spring-boot-autoconfigure/pom.xml +++ b/riptide-spring-boot-autoconfigure/pom.xml @@ -164,6 +164,7 @@ ${logbook.version} true + org.zalando logbook-httpclient @@ -310,8 +311,6 @@ **/NoCachingTest.java - org.apache.httpcomponents.client5:httpclient5-cache - From 47ced1a2bc9e57f26b895b9223d1b523064ce1e7 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Tue, 20 Jun 2023 00:02:59 +0200 Subject: [PATCH 28/32] Bump Logbook version --- riptide-parent/pom.xml | 2 +- riptide-spring-boot-autoconfigure/pom.xml | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/riptide-parent/pom.xml b/riptide-parent/pom.xml index e2b8e58ff..7d158db6d 100644 --- a/riptide-parent/pom.xml +++ b/riptide-parent/pom.xml @@ -20,7 +20,7 @@ 2.15.2 2.15.2 5.10.0-M1 - 3.0.0 + 3.1.0 1.11.1 5.3.1 0.27.1 diff --git a/riptide-spring-boot-autoconfigure/pom.xml b/riptide-spring-boot-autoconfigure/pom.xml index 7c34ff1b2..94bacee98 100644 --- a/riptide-spring-boot-autoconfigure/pom.xml +++ b/riptide-spring-boot-autoconfigure/pom.xml @@ -163,13 +163,6 @@ logbook-spring-boot-autoconfigure ${logbook.version} true - - - - org.zalando - logbook-httpclient - - From f0c2f73735cceff0d5b50f252497b83aa14ad121 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Tue, 20 Jun 2023 01:53:31 +0200 Subject: [PATCH 29/32] Apply changes to Auto-configuration See: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#auto-configuration-registration --- .../autoconfigure/OpenTracingFlowIdAutoConfiguration.java | 3 ++- .../riptide/autoconfigure/RiptideAutoConfiguration.java | 4 ++-- .../riptide/autoconfigure/RiptideTestAutoConfiguration.java | 3 ++- .../src/main/resources/META-INF/spring.factories | 1 - ...ringframework.boot.autoconfigure.AutoConfiguration.imports | 3 +++ 5 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories create mode 100644 riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java index e19c8c216..e1a1a1e85 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/OpenTracingFlowIdAutoConfiguration.java @@ -3,6 +3,7 @@ import io.opentracing.Tracer; import org.apache.hc.client5.http.classic.HttpClient; import org.apiguardian.api.API; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -22,7 +23,7 @@ * We use org.zalando.riptide.autoconfigure.FlowHttpRequestInterceptor, that is adapted to Apache HttpClient 5.x. */ @API(status = STABLE) -@Configuration +@AutoConfiguration @ConditionalOnBean(Tracer.class) @AutoConfigureAfter(name = { "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration", diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java index 51b5ead53..a36fd3188 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideAutoConfiguration.java @@ -1,16 +1,16 @@ package org.zalando.riptide.autoconfigure; import org.apiguardian.api.API; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import static org.apiguardian.api.API.Status.INTERNAL; import static org.apiguardian.api.API.Status.STABLE; @API(status = STABLE) -@Configuration +@AutoConfiguration @AutoConfigureAfter(name = { "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration", "org.zalando.logbook.autoconfigure.LogbookAutoConfiguration", diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideTestAutoConfiguration.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideTestAutoConfiguration.java index 9fd8ce7be..db418bf52 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideTestAutoConfiguration.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/RiptideTestAutoConfiguration.java @@ -2,6 +2,7 @@ import org.apiguardian.api.API; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,7 +13,7 @@ import static org.springframework.test.web.client.MockRestServiceServer.createServer; @API(status = EXPERIMENTAL) -@Configuration +@AutoConfiguration @AutoConfigureBefore(RiptideAutoConfiguration.class) public class RiptideTestAutoConfiguration { diff --git a/riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 68f746204..000000000 --- a/riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration = org.zalando.riptide.autoconfigure.RiptideAutoConfiguration diff --git a/riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..191dca3eb --- /dev/null +++ b/riptide-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,3 @@ +org.zalando.riptide.autoconfigure.OpenTracingFlowIdAutoConfiguration +org.zalando.riptide.autoconfigure.RiptideAutoConfiguration +org.zalando.riptide.autoconfigure.RiptideTestAutoConfiguration From 7194c0c24ece7479ceb182cdd29c71db884217a7 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:55:41 +0200 Subject: [PATCH 30/32] Add new lines at the end of all files Using the technique mentioned here: https://unix.stackexchange.com/a/161853/500398 --- .../src/main/java/org/zalando/riptide/capture/package-info.java | 2 +- riptide-capture/src/test/resources/message.json | 2 +- .../main/java/org/zalando/riptide/compression/package-info.java | 2 +- .../src/main/java/org/zalando/riptide/package-info.java | 2 +- riptide-core/src/test/resources/account.json | 2 +- riptide-core/src/test/resources/contributors.json | 2 +- riptide-core/src/test/resources/error.json | 2 +- riptide-core/src/test/resources/messages.json | 2 +- riptide-core/src/test/resources/problem.json | 2 +- riptide-core/src/test/resources/success.json | 2 +- .../main/java/org/zalando/riptide/httpclient/package-info.java | 2 +- .../httpclient/BufferingApacheClientHttpRequestTest.java | 2 +- riptide-httpclient/src/test/resources/contributors.json | 2 +- .../idempotency/MethodOverrideIdempotencyDetectorTest.java | 2 +- .../src/main/java/org/zalando/riptide/problem/package-info.java | 2 +- riptide-problem/src/test/resources/problem.json | 2 +- .../riptide/autoconfigure/FlowHttpRequestInterceptor.java | 2 +- .../src/main/java/org/zalando/riptide/stream/StreamFilter.java | 2 +- .../main/java/org/zalando/riptide/stream/StreamSpliterator.java | 2 +- .../src/main/java/org/zalando/riptide/stream/package-info.java | 2 +- riptide-stream/src/test/resources/contributors.json | 2 +- riptide-stream/src/test/resources/contributors.json-seq | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/riptide-capture/src/main/java/org/zalando/riptide/capture/package-info.java b/riptide-capture/src/main/java/org/zalando/riptide/capture/package-info.java index eb04c2206..bd7136ed0 100644 --- a/riptide-capture/src/main/java/org/zalando/riptide/capture/package-info.java +++ b/riptide-capture/src/main/java/org/zalando/riptide/capture/package-info.java @@ -1,4 +1,4 @@ @ParametersAreNonnullByDefault package org.zalando.riptide.capture; -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/riptide-capture/src/test/resources/message.json b/riptide-capture/src/test/resources/message.json index c715b67f1..88f907159 100644 --- a/riptide-capture/src/test/resources/message.json +++ b/riptide-capture/src/test/resources/message.json @@ -1 +1 @@ -{"message": "Hello World!"} \ No newline at end of file +{"message": "Hello World!"} diff --git a/riptide-compression/src/main/java/org/zalando/riptide/compression/package-info.java b/riptide-compression/src/main/java/org/zalando/riptide/compression/package-info.java index 7870a37f8..141f07f8c 100644 --- a/riptide-compression/src/main/java/org/zalando/riptide/compression/package-info.java +++ b/riptide-compression/src/main/java/org/zalando/riptide/compression/package-info.java @@ -1,4 +1,4 @@ @ParametersAreNonnullByDefault package org.zalando.riptide.compression; -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/riptide-core/src/main/java/org/zalando/riptide/package-info.java b/riptide-core/src/main/java/org/zalando/riptide/package-info.java index b886c3692..9b9805bcb 100644 --- a/riptide-core/src/main/java/org/zalando/riptide/package-info.java +++ b/riptide-core/src/main/java/org/zalando/riptide/package-info.java @@ -1,4 +1,4 @@ @ParametersAreNonnullByDefault package org.zalando.riptide; -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/riptide-core/src/test/resources/account.json b/riptide-core/src/test/resources/account.json index 12cb07e85..070546a06 100644 --- a/riptide-core/src/test/resources/account.json +++ b/riptide-core/src/test/resources/account.json @@ -1,4 +1,4 @@ { "id": "1234567890", "name": "Acme Corporation" -} \ No newline at end of file +} diff --git a/riptide-core/src/test/resources/contributors.json b/riptide-core/src/test/resources/contributors.json index 5a8509954..33d0a1888 100644 --- a/riptide-core/src/test/resources/contributors.json +++ b/riptide-core/src/test/resources/contributors.json @@ -79,4 +79,4 @@ "site_admin": false, "contributions": 1 } -] \ No newline at end of file +] diff --git a/riptide-core/src/test/resources/error.json b/riptide-core/src/test/resources/error.json index f8db48745..d8e093e0b 100644 --- a/riptide-core/src/test/resources/error.json +++ b/riptide-core/src/test/resources/error.json @@ -1,4 +1,4 @@ { "message": "A problem occurred.", "path": "https://api.example.com" -} \ No newline at end of file +} diff --git a/riptide-core/src/test/resources/messages.json b/riptide-core/src/test/resources/messages.json index 0044d99dd..e5ead2196 100644 --- a/riptide-core/src/test/resources/messages.json +++ b/riptide-core/src/test/resources/messages.json @@ -1,4 +1,4 @@ [ {"message": "Foo"}, {"message": "Bar"} -] \ No newline at end of file +] diff --git a/riptide-core/src/test/resources/problem.json b/riptide-core/src/test/resources/problem.json index 5926b149a..0fdbce1e8 100644 --- a/riptide-core/src/test/resources/problem.json +++ b/riptide-core/src/test/resources/problem.json @@ -3,4 +3,4 @@ "title": "Unprocessable Entity", "status": 422, "detail": "A problem occurred." -} \ No newline at end of file +} diff --git a/riptide-core/src/test/resources/success.json b/riptide-core/src/test/resources/success.json index 2a7e64b8e..ff3f3c008 100644 --- a/riptide-core/src/test/resources/success.json +++ b/riptide-core/src/test/resources/success.json @@ -1,3 +1,3 @@ { "happy": true -} \ No newline at end of file +} diff --git a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/package-info.java b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/package-info.java index e2e86e191..5f81ce029 100644 --- a/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/package-info.java +++ b/riptide-httpclient/src/main/java/org/zalando/riptide/httpclient/package-info.java @@ -1,4 +1,4 @@ @ParametersAreNonnullByDefault package org.zalando.riptide.httpclient; -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java index 83a7063e0..5bc260919 100644 --- a/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java +++ b/riptide-httpclient/src/test/java/org/zalando/riptide/httpclient/BufferingApacheClientHttpRequestTest.java @@ -20,4 +20,4 @@ void shouldThrowIllegalArgumentException() throws URISyntaxException { assertThrows(IllegalArgumentException.class, request::getURI); } -} \ No newline at end of file +} diff --git a/riptide-httpclient/src/test/resources/contributors.json b/riptide-httpclient/src/test/resources/contributors.json index 5a8509954..33d0a1888 100644 --- a/riptide-httpclient/src/test/resources/contributors.json +++ b/riptide-httpclient/src/test/resources/contributors.json @@ -79,4 +79,4 @@ "site_admin": false, "contributions": 1 } -] \ No newline at end of file +] diff --git a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java index 7111a7608..c1b4b7fc0 100644 --- a/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java +++ b/riptide-idempotency/src/test/java/org/zalando/riptide/idempotency/MethodOverrideIdempotencyDetectorTest.java @@ -30,4 +30,4 @@ public void shouldDealWithIncorrectHttpMethodOverride() { assertThat(methodOverrideIdempotencyDetector.test(arguments, test), is(Decision.NEUTRAL)); } -} \ No newline at end of file +} diff --git a/riptide-problem/src/main/java/org/zalando/riptide/problem/package-info.java b/riptide-problem/src/main/java/org/zalando/riptide/problem/package-info.java index 640c7709c..9ace8d9cf 100644 --- a/riptide-problem/src/main/java/org/zalando/riptide/problem/package-info.java +++ b/riptide-problem/src/main/java/org/zalando/riptide/problem/package-info.java @@ -1,4 +1,4 @@ @ParametersAreNonnullByDefault package org.zalando.riptide.problem; -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/riptide-problem/src/test/resources/problem.json b/riptide-problem/src/test/resources/problem.json index 5926b149a..0fdbce1e8 100644 --- a/riptide-problem/src/test/resources/problem.json +++ b/riptide-problem/src/test/resources/problem.json @@ -3,4 +3,4 @@ "title": "Unprocessable Entity", "status": 422, "detail": "A problem occurred." -} \ No newline at end of file +} diff --git a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java index 2d6daed0b..50e226542 100644 --- a/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java +++ b/riptide-spring-boot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/FlowHttpRequestInterceptor.java @@ -26,4 +26,4 @@ public FlowHttpRequestInterceptor(final Flow flow) { public void process(HttpRequest httpRequest, EntityDetails entityDetails, HttpContext httpContext) { flow.writeTo(httpRequest::addHeader); } -} \ No newline at end of file +} diff --git a/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamFilter.java b/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamFilter.java index d8116cf0d..867740555 100644 --- a/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamFilter.java +++ b/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamFilter.java @@ -73,4 +73,4 @@ public long skip(final long n) throws IOException { return sum; } -} \ No newline at end of file +} diff --git a/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamSpliterator.java b/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamSpliterator.java index b7de64f76..7d2b17f24 100644 --- a/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamSpliterator.java +++ b/riptide-stream/src/main/java/org/zalando/riptide/stream/StreamSpliterator.java @@ -72,4 +72,4 @@ public int characteristics() { return ORDERED | IMMUTABLE; } -} \ No newline at end of file +} diff --git a/riptide-stream/src/main/java/org/zalando/riptide/stream/package-info.java b/riptide-stream/src/main/java/org/zalando/riptide/stream/package-info.java index 558e42b95..8a67ecabb 100644 --- a/riptide-stream/src/main/java/org/zalando/riptide/stream/package-info.java +++ b/riptide-stream/src/main/java/org/zalando/riptide/stream/package-info.java @@ -1,4 +1,4 @@ @ParametersAreNonnullByDefault package org.zalando.riptide.stream; -import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/riptide-stream/src/test/resources/contributors.json b/riptide-stream/src/test/resources/contributors.json index 58a9f3533..cb5ce1a51 100644 --- a/riptide-stream/src/test/resources/contributors.json +++ b/riptide-stream/src/test/resources/contributors.json @@ -719,4 +719,4 @@ "site_admin": false, "contributions": 1 } -] \ No newline at end of file +] diff --git a/riptide-stream/src/test/resources/contributors.json-seq b/riptide-stream/src/test/resources/contributors.json-seq index 1005b1c77..ee4820454 100644 --- a/riptide-stream/src/test/resources/contributors.json-seq +++ b/riptide-stream/src/test/resources/contributors.json-seq @@ -717,4 +717,4 @@ "type": "User", "site_admin": false, "contributions": 1 -} \ No newline at end of file +} From 135147d06d219f0bc292f77957bb0964b45a6cf2 Mon Sep 17 00:00:00 2001 From: Sadeq Dousti <3616518+msdousti@users.noreply.github.com> Date: Tue, 20 Jun 2023 11:14:57 +0200 Subject: [PATCH 31/32] Use non-milestone version for junit-jupiter --- riptide-parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riptide-parent/pom.xml b/riptide-parent/pom.xml index 7d158db6d..dec3d57ad 100644 --- a/riptide-parent/pom.xml +++ b/riptide-parent/pom.xml @@ -19,7 +19,7 @@ 0.9.0 2.15.2 2.15.2 - 5.10.0-M1 + 5.9.3 3.1.0 1.11.1 5.3.1 From 69730297f1c3f3435b357c2f5fd0eb9ab2f27c47 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Thu, 22 Jun 2023 15:23:59 +0200 Subject: [PATCH 32/32] Described removal of classes due to Spring 6 not supporting them anymore - Documented behaviour change due to update to Apache HttpClient 5 --- MIGRATION.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MIGRATION.md b/MIGRATION.md index 3e7a611ab..4b60710ee 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -25,6 +25,15 @@ Here are some of the breaking changes that can affect `riptide-failsafe` users: Since Spring 5, `AsyncRestTemplate` is deprecated in favor of `WebClient`. For that reason, we have removed `AsyncHttpOperations` from `riptide-compatibility` layer. +Since Spring 6, `AsyncRestTemplate` and all corresponding classes like `AsyncClientHttpRequestFactory` have been removed. +For that reason, we have removed `NonBlockingIO` from `riptide-core` to avoid additionally migrating to `WebClient`. +The same reason applies to the removal of `HttpOutputMessageAsyncClientHttpRequestAdapter` from `riptide-compatibility-layer`. + +## Apache HttpClient 5 + +Apache HttpClient 5 removed the definition of whether a specific HTTP method is allowed to have a body or not. Due to +this `StreamingApacheClientHttpRequest::setBody` will not throw an exception anymore. + ## OpenTracing The `SpanDecorators` obtained by `ServiceLoaderSpanDecorator`