diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index eacdc9ed1..7d02699af 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.5/apache-maven-3.9.5-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-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/components/api/pom.xml b/components/api/pom.xml index d0f28a393..cfd9184ec 100644 --- a/components/api/pom.xml +++ b/components/api/pom.xml @@ -58,11 +58,6 @@ guava - - com.google.code.findbugs - annotations - - com.fasterxml.uuid java-uuid-generator diff --git a/components/client/pom.xml b/components/client/pom.xml index 33fa8f660..52e91a0f9 100644 --- a/components/client/pom.xml +++ b/components/client/pom.xml @@ -37,11 +37,6 @@ styx-api - - com.google.code.findbugs - annotations - - io.dropwizard.metrics metrics-json diff --git a/components/client/src/main/java/com/hotels/styx/client/HttpClient.java b/components/client/src/main/java/com/hotels/styx/client/HttpClient.java index 020158c0d..2374a5087 100644 --- a/components/client/src/main/java/com/hotels/styx/client/HttpClient.java +++ b/components/client/src/main/java/com/hotels/styx/client/HttpClient.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ /** * A Styx HTTP client interface. - * + *

* This interface offers a fluent interface to build and configure HTTP * request transactions from a client instance. The requests can be consumed * either aggregated {@link HttpResponse} or streaming {@link LiveHttpRequest} @@ -33,20 +33,7 @@ public interface HttpClient { /** - * Sends a HTTP request message using this client. - * - * @deprecated use {@link #send} instead. - * - * @param request a full HTTP request object - * @return a future of full HTTP request object - */ - @Deprecated - default CompletableFuture sendRequest(HttpRequest request) { - return send(request); - } - - /** - * Sends a HTTP request message using this client. + * Sends an HTTP request message using this client. * * @param request a full HTTP request object * @return a future of full HTTP request object @@ -54,8 +41,8 @@ default CompletableFuture sendRequest(HttpRequest request) { CompletableFuture send(HttpRequest request); /** - * A HTTP request transaction. - * + * An HTTP request transaction. + *

* This interface allows client attributes and context to be customised * for each request without having to rely on configured default values * in the client. @@ -80,7 +67,7 @@ interface Transaction { /** * Converts the transaction object to streaming transaction. - * + *

* A call to {@code streaming()} converts this {@link Transaction} object to * a {@link StreamingTransaction}. This allows responses to be consumed * in streaming responses. @@ -90,7 +77,7 @@ interface Transaction { StreamingTransaction streaming(); /** - * Sends a HTTP request message using this client. + * Sends an HTTP request message using this client. * * @param request a full HTTP request object * @return a future of full HTTP request object @@ -100,7 +87,7 @@ interface Transaction { /** * A streaming HTTP request transaction. - * + *

* This interface allows the response object to be consumed in a streaming * fashion instead of being aggregated into a HttpResponse. */ diff --git a/components/client/src/test/integration/scala/com/hotels/styx/client/OriginSupport.scala b/components/client/src/test/integration/scala/com/hotels/styx/client/OriginSupport.scala index b9a3f8870..a79e56620 100644 --- a/components/client/src/test/integration/scala/com/hotels/styx/client/OriginSupport.scala +++ b/components/client/src/test/integration/scala/com/hotels/styx/client/OriginSupport.scala @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2022 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/components/client/src/test/unit/java/com/hotels/styx/client/netty/connectionpool/NettyConnectionFactoryTest.java b/components/client/src/test/unit/java/com/hotels/styx/client/netty/connectionpool/NettyConnectionFactoryTest.java index 7ec1577a9..b87344154 100644 --- a/components/client/src/test/unit/java/com/hotels/styx/client/netty/connectionpool/NettyConnectionFactoryTest.java +++ b/components/client/src/test/unit/java/com/hotels/styx/client/netty/connectionpool/NettyConnectionFactoryTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.hotels.styx.client.Connection; import com.hotels.styx.client.ConnectionSettings; import com.hotels.styx.support.server.FakeHttpServer; +import com.hotels.styx.support.server.UrlMatchingStrategies; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; diff --git a/components/proxy/pom.xml b/components/proxy/pom.xml index 748cabf1e..c0d9462f8 100644 --- a/components/proxy/pom.xml +++ b/components/proxy/pom.xml @@ -62,11 +62,6 @@ guava - - com.google.code.findbugs - annotations - - org.codehaus.janino diff --git a/components/proxy/src/test/java/com/hotels/styx/admin/handlers/ServiceProviderHandlerTest.java b/components/proxy/src/test/java/com/hotels/styx/admin/handlers/ServiceProviderHandlerTest.java index 2b6fb3634..4f1f34bf5 100644 --- a/components/proxy/src/test/java/com/hotels/styx/admin/handlers/ServiceProviderHandlerTest.java +++ b/components/proxy/src/test/java/com/hotels/styx/admin/handlers/ServiceProviderHandlerTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,13 +17,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.hotels.styx.StyxObjectRecord; import com.hotels.styx.api.HttpRequest; import com.hotels.styx.api.HttpResponse; import com.hotels.styx.api.extension.service.spi.StyxService; import com.hotels.styx.routing.config.StyxObjectDefinition; import com.hotels.styx.routing.db.StyxObjectStore; -import com.hotels.styx.StyxObjectRecord; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -35,10 +35,10 @@ import java.util.Optional; import java.util.stream.Collectors; -import static com.hotels.styx.support.Support.requestContext; import static com.hotels.styx.api.HttpResponseStatus.NOT_FOUND; import static com.hotels.styx.api.HttpResponseStatus.NO_CONTENT; import static com.hotels.styx.api.HttpResponseStatus.OK; +import static com.hotels.styx.support.Support.requestContext; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; diff --git a/components/proxy/src/test/java/com/hotels/styx/proxy/StyxProxyTest.java b/components/proxy/src/test/java/com/hotels/styx/proxy/StyxProxyTest.java index 8279a99a0..0c72db26c 100644 --- a/components/proxy/src/test/java/com/hotels/styx/proxy/StyxProxyTest.java +++ b/components/proxy/src/test/java/com/hotels/styx/proxy/StyxProxyTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -139,6 +139,6 @@ private HttpResponse get(String uri) { } private HttpResponse execute(HttpRequest request) { - return await(client.sendRequest(request)); + return await(client.send(request)); } } diff --git a/components/test-api/pom.xml b/components/test-api/pom.xml index efd51d0d4..32fd825a5 100644 --- a/components/test-api/pom.xml +++ b/components/test-api/pom.xml @@ -63,7 +63,7 @@ - com.github.tomakehurst + org.wiremock wiremock compile diff --git a/components/test-api/src/test/java/com/hotels/styx/testapi/StyxServerTest.java b/components/test-api/src/test/java/com/hotels/styx/testapi/StyxServerTest.java index dd3685ad8..3fbd1d545 100644 --- a/components/test-api/src/test/java/com/hotels/styx/testapi/StyxServerTest.java +++ b/components/test-api/src/test/java/com/hotels/styx/testapi/StyxServerTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -119,7 +119,7 @@ public void proxiesToOrigin() { .addRoute("/", originServer1.port()) .start(); - HttpResponse response = await(client.sendRequest(get(format("https://localhost:%d/", styxServer.proxyHttpPort())).build())); + HttpResponse response = await(client.send(get(format("https://localhost:%d/", styxServer.proxyHttpPort())).build())); assertThat(response.status(), is(OK)); configureFor(originServer1.port()); @@ -133,7 +133,7 @@ public void startsProxyOnSpecifiedHttpPort() { .addRoute("/", originServer1.port()) .start(); - HttpResponse response = await(client.sendRequest(get(format("https://localhost:%d/", styxServer.proxyHttpPort())).build())); + HttpResponse response = await(client.send(get(format("https://localhost:%d/", styxServer.proxyHttpPort())).build())); assertThat(response.status(), is(OK)); } @@ -145,7 +145,7 @@ public void startsAdminOnSpecifiedHttpPort() { .addRoute("/", originServer1.port()) .start(); - HttpResponse response = await(client.sendRequest(get(format("https://localhost:%d/admin", styxServer.adminPort())).build())); + HttpResponse response = await(client.send(get(format("https://localhost:%d/admin", styxServer.adminPort())).build())); assertThat(response.status(), is(OK)); } @@ -161,7 +161,7 @@ public void startsProxyOnSpecifiedHttpsPort() { .tlsSettings(new TlsSettings.Builder().build()) .build(); - HttpResponse response = await(tlsClient.sendRequest(get(format("https://localhost:%d/", styxServer.proxyHttpsPort())).build())); + HttpResponse response = await(tlsClient.send(get(format("https://localhost:%d/", styxServer.proxyHttpsPort())).build())); assertThat(response.status(), is(OK)); } @@ -195,7 +195,7 @@ public void proxiesToOriginViaHttps() { .tlsSettings(new TlsSettings.Builder().build()) .build(); - HttpResponse response = await(tlsClient.sendRequest(get(format("https://localhost:%d/", styxServer.proxyHttpsPort())).build())); + HttpResponse response = await(tlsClient.send(get(format("https://localhost:%d/", styxServer.proxyHttpsPort())).build())); assertThat(response.status(), is(OK)); configureFor(secureOriginServer.port()); @@ -212,7 +212,7 @@ public void proxiesToOriginViaHttpsWithRequestOriginallyHttp() { .addRoute("/", backendService) .start(); - HttpResponse response = await(client.sendRequest(get(format("http://localhost:%d/", styxServer.proxyHttpPort())).build())); + HttpResponse response = await(client.send(get(format("http://localhost:%d/", styxServer.proxyHttpPort())).build())); assertThat(response.status(), is(OK)); configureFor(secureOriginServer.port()); @@ -226,12 +226,12 @@ public void routesCorrectly() { .addRoute("/o2/", originServer2.port()) .start(); - HttpResponse response1 = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response1 = await(client.send(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); assertThat(response1.status(), is(OK)); assertThat(response1.header("origin"), isValue("first")); - HttpResponse response2 = await(client.sendRequest(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response2 = await(client.send(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build())); assertThat(response2.status(), is(OK)); assertThat(response2.header("origin"), isValue("second")); @@ -255,7 +255,7 @@ public void executesPluginsWhenProxying() { .addPluginFactory("response-decorator", pluginFactory, null) .start(); - HttpResponse response = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response = await(client.send(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); assertThat(response.status(), is(OK)); assertThat(response.header("origin"), isValue("first")); assertThat(response.header("plugin-executed"), isValue("yes")); @@ -344,7 +344,7 @@ private Plugin mockPlugin(Map adminInterfaceHandlers) { private HttpResponse doAdminRequest(String path) { String url = format("%s://localhost:%s%s", "http", styxServer.adminPort(), startWithSlash(path)); - return await(client.sendRequest(get(url).build())); + return await(client.send(get(url).build())); } @Test @@ -368,11 +368,11 @@ public void canConfigureWithStyxOrigins() { .addRoute("/o2/", origin(originServer2.port())) .start(); - HttpResponse response1 = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response1 = await(client.send(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); assertThat(response1.status(), is(OK)); assertThat(response1.header("origin"), isValue("first")); - HttpResponse response2 = await(client.sendRequest(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response2 = await(client.send(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build())); assertThat(response2.status(), is(OK)); assertThat(response2.header("origin"), isValue("second")); @@ -389,11 +389,11 @@ public void canConfigureWithBackendService() { .addRoute("/o2/", new BackendService().addOrigin(originServer2.port())) .start(); - HttpResponse response1 = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response1 = await(client.send(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build())); assertThat(response1.status(), is(OK)); assertThat(response1.header("origin"), isValue("first")); - HttpResponse response2 = await(client.sendRequest(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build())); + HttpResponse response2 = await(client.send(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build())); assertThat(response2.status(), is(OK)); assertThat(response2.header("origin"), isValue("second")); diff --git a/demo/pom.xml b/demo/pom.xml index ab6225fc6..978d7e991 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -25,7 +25,7 @@ kotlin-stdlib - com.github.tomakehurst + org.wiremock wiremock diff --git a/demo/src/test/kotlin/com/hotels/styx/demo/DemoOrigin.kt b/demo/src/test/kotlin/com/hotels/styx/demo/DemoOrigin.kt index 28a166ef8..027a9a53d 100644 --- a/demo/src/test/kotlin/com/hotels/styx/demo/DemoOrigin.kt +++ b/demo/src/test/kotlin/com/hotels/styx/demo/DemoOrigin.kt @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,16 +18,14 @@ package com.hotels.styx.demo import com.github.tomakehurst.wiremock.WireMockServer import com.github.tomakehurst.wiremock.client.MappingBuilder import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder -import com.github.tomakehurst.wiremock.client.UrlMatchingStrategy import com.github.tomakehurst.wiremock.client.WireMock import com.github.tomakehurst.wiremock.client.WireMock.aResponse -import com.github.tomakehurst.wiremock.common.FileSource +import com.github.tomakehurst.wiremock.client.WireMock.urlMatching import com.github.tomakehurst.wiremock.core.WireMockConfiguration -import com.github.tomakehurst.wiremock.extension.ResponseTransformer -import com.github.tomakehurst.wiremock.http.QueryParameter -import com.github.tomakehurst.wiremock.http.Request -import com.github.tomakehurst.wiremock.http.ResponseDefinition -import com.hotels.styx.api.HttpResponseStatus +import com.github.tomakehurst.wiremock.extension.ResponseTransformerV2 +import com.github.tomakehurst.wiremock.http.Response +import com.github.tomakehurst.wiremock.stubbing.ServeEvent +import com.hotels.styx.api.HttpResponseStatus.statusWithCode /** * This can be executed to launch a fake backend on localhost:9090. @@ -49,10 +47,14 @@ fun main() { println("Demo origin started on port $port") } -fun launchDemoOrigin(port: Int = 9090, path: String = "/"): WireMockServer { - val config = WireMockConfiguration() - .port(port) - .extensions(DemoTransformer()) +fun launchDemoOrigin( + port: Int = 9090, + path: String = "/", +): WireMockServer { + val config = + WireMockConfiguration() + .port(port) + .extensions(DemoTransformer()) return WireMockServer(config).apply { stub(path) { @@ -65,32 +67,36 @@ fun launchDemoOrigin(port: Int = 9090, path: String = "/"): WireMockServer { } } -private class DemoTransformer : ResponseTransformer() { - override fun name(): String = "demo" - - override fun transform(request: Request, responseDefinition: ResponseDefinition, files: FileSource) = - responseDefinition.apply { - status = request.queryParam("status")?.toInt() ?: 200 - - body = request.queryParam("body") - ?: "Demo origin response. Status = ${HttpResponseStatus.statusWithCode(status)}" +private class DemoTransformer : ResponseTransformerV2 { + override fun getName(): String = "demo" + + override fun transform( + response: Response, + serveEvent: ServeEvent, + ): Response = + serveEvent.transformerParameters.let { + val status = it.getInt("status") ?: 200 + Response.Builder.like(response) + .status(status) + .body( + it.getString("body") + ?: "Demo origin response. Status = ${statusWithCode(status)}", + ) + .build() } override fun applyGlobally() = false } -private fun Request.queryParam(name: String): String? = queryParameter(name).value1() -private fun QueryParameter.value1(): String? = if (isPresent) firstValue() else null - -private inline fun WireMockServer.stub(startsWith: String, block: ResponseDefinitionBuilder.() -> Unit) = apply { +private inline fun WireMockServer.stub( + startsWith: String, + block: ResponseDefinitionBuilder.() -> Unit, +) = apply { stubFor( urlMatchingPattern("$startsWith.*").willReturn( - aResponse().apply(block) - ) + aResponse().apply(block), + ), ) } -private fun urlMatchingPattern(pattern: String): MappingBuilder = - WireMock.get(UrlMatchingStrategy().apply { - setUrlPattern(pattern) - }) +private fun urlMatchingPattern(pattern: String): MappingBuilder = WireMock.get(urlMatching(pattern)) diff --git a/mvnw.cmd b/mvnw.cmd index c4586b564..f80fbad3e 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,205 +1,205 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@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 -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@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 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 -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -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 "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -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 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 "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 -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - 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: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "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('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %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% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -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_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@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 +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@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 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 +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +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 "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +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 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 "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 +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + 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: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "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('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %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% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +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_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 5e676f445..dec31c030 100644 --- a/pom.xml +++ b/pom.xml @@ -100,66 +100,70 @@ 11 - 33.0.0-jre - 2.15.3 + 4.13.1 + 1.14.12 4.2.25 - 1.10.13 - 4.5.3 - 4.1.106.Final - - 1.0.4 - 2023.0.2 + 33.0.0-jre + 2.1.12 + 2.15.4 + 3.1.12 + 1.12.3 + 4.1.107.Final 3.0.5 - 1.14.11 + 1.0.4 + 2023.0.3 1.9.22 5.8.0 true - 0.11.0 + 0.11.0 - 4.3.0 + 5.0.0 - 1.4.14 - 2.0.11 + 1.5.1 + 2.0.12 2.12 2.12.18 + 2.8.5 2.2 + 5.10.2 5.10.0 - 1.13.9 - 5.10.1 + 1.13.10 3.0.9 1.17.0 1.0.2 + 3.4.2 3.1.0 3.6.0 - 3.3.0 - 3.11.0 - 3.6.0 + 3.3.1 + 3.12.1 + 3.6.1 3.1.1 3.4.1 - 3.1.2 + 3.2.5 3.1.1 3.3.0 - 3.21.0 - 3.6.0 - 3.4.5 + 3.21.2 + 3.6.3 + 3.5.0 3.0.1 3.3.1 3.12.1 3.3.0 - 3.1.2 + 3.2.5 - 3.4.0 + 3.5.0 0.8.11 - 1.6.8 + 1.6.13 + 4.8.1 jacoco @@ -355,7 +359,7 @@ org.hdrhistogram HdrHistogram - 2.1.12 + ${hdrhistogram.version} @@ -412,7 +416,7 @@ org.codehaus.janino janino - 3.1.11 + ${janino.version} @@ -421,22 +425,6 @@ ${scala.java8.compat.version} - - - com.google.code.findbugs - jsr305 - 3.0.2 - provided - true - - - - com.google.code.findbugs - annotations - 3.0.1 - provided - - com.hotels.styx styx-testsupport @@ -496,21 +484,21 @@ com.typesafe.akka akka-actor_${scala.version} - 2.5.32 + ${akka.version} test com.typesafe.akka akka-testkit_${scala.version} - 2.5.32 + ${akka.version} test - com.github.tomakehurst + org.wiremock wiremock - 1.54 + ${wiremock.version} test @@ -523,7 +511,7 @@ org.jetbrains.kotlinx kotlinx-html-jvm - ${kotlinx.html.version} + ${kotlinx-html.version} @@ -613,7 +601,7 @@ net.alchim31.maven scala-maven-plugin - 4.8.0 + ${scala-maven-plugin.version} scala-test-compile @@ -682,7 +670,7 @@ org.apache.ant ant-launcher - 1.10.7 + 1.10.14 @@ -869,7 +857,7 @@ true - [3.2.1,) + [3.8.7,) [1.8,) diff --git a/support/api-testsupport/pom.xml b/support/api-testsupport/pom.xml index 49da811df..b40cc7284 100755 --- a/support/api-testsupport/pom.xml +++ b/support/api-testsupport/pom.xml @@ -53,7 +53,7 @@ - com.github.tomakehurst + org.wiremock wiremock compile diff --git a/support/api-testsupport/src/main/java/com/hotels/styx/support/api/FakeHttpServer.java b/support/api-testsupport/src/main/java/com/hotels/styx/support/api/FakeHttpServer.java index f121e574b..ce47ce054 100644 --- a/support/api-testsupport/src/main/java/com/hotels/styx/support/api/FakeHttpServer.java +++ b/support/api-testsupport/src/main/java/com/hotels/styx/support/api/FakeHttpServer.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,12 +17,12 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.MappingBuilder; -import com.github.tomakehurst.wiremock.client.RequestPatternBuilder; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.client.UrlMatchingStrategy; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.common.HttpsSettings; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; +import com.github.tomakehurst.wiremock.matching.UrlPattern; import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; @@ -89,9 +89,9 @@ public FakeHttpServer start() { return this; } - public FakeHttpServer stub(UrlMatchingStrategy urlMatchingStrategy, ResponseDefinitionBuilder response) { + public FakeHttpServer stub(UrlPattern urlPattern, ResponseDefinitionBuilder response) { configureFor("localhost", adminPort()); - stubFor(WireMock.get(urlMatchingStrategy).willReturn(response)); + stubFor(WireMock.get(urlPattern).willReturn(response)); return this; } diff --git a/support/testsupport/pom.xml b/support/testsupport/pom.xml index 09860c1a6..b6140431d 100755 --- a/support/testsupport/pom.xml +++ b/support/testsupport/pom.xml @@ -51,7 +51,7 @@ - com.github.tomakehurst + org.wiremock wiremock compile diff --git a/support/testsupport/src/main/java/com/hotels/styx/support/server/FakeHttpServer.java b/support/testsupport/src/main/java/com/hotels/styx/support/server/FakeHttpServer.java index 260e18548..e3fd4fd4d 100644 --- a/support/testsupport/src/main/java/com/hotels/styx/support/server/FakeHttpServer.java +++ b/support/testsupport/src/main/java/com/hotels/styx/support/server/FakeHttpServer.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,12 +17,12 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.MappingBuilder; -import com.github.tomakehurst.wiremock.client.RequestPatternBuilder; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.client.UrlMatchingStrategy; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.common.HttpsSettings; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; +import com.github.tomakehurst.wiremock.matching.UrlPattern; import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; @@ -89,9 +89,9 @@ public FakeHttpServer start() { return this; } - public FakeHttpServer stub(UrlMatchingStrategy urlMatchingStrategy, ResponseDefinitionBuilder response) { + public FakeHttpServer stub(UrlPattern urlPattern, ResponseDefinitionBuilder response) { configureFor("localhost", adminPort()); - stubFor(WireMock.get(urlMatchingStrategy).willReturn(response)); + stubFor(WireMock.get(urlPattern).willReturn(response)); return this; } diff --git a/support/testsupport/src/main/java/com/hotels/styx/support/server/UrlMatchingStrategies.java b/support/testsupport/src/main/java/com/hotels/styx/support/server/UrlMatchingStrategies.java index c9bf711c0..3859114bc 100644 --- a/support/testsupport/src/main/java/com/hotels/styx/support/server/UrlMatchingStrategies.java +++ b/support/testsupport/src/main/java/com/hotels/styx/support/server/UrlMatchingStrategies.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,21 +15,19 @@ */ package com.hotels.styx.support.server; -import com.github.tomakehurst.wiremock.client.UrlMatchingStrategy; +import com.github.tomakehurst.wiremock.matching.UrlPattern; + +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; public final class UrlMatchingStrategies { private UrlMatchingStrategies() { } - public static UrlMatchingStrategy urlStartingWith(String url) { - UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy(); - urlStrategy.setUrlPattern(url + ".*"); - return urlStrategy; + public static UrlPattern urlStartingWith(String url) { + return urlMatching(url + ".*"); } - public static UrlMatchingStrategy urlEndingWith(String url) { - UrlMatchingStrategy urlStrategy = new UrlMatchingStrategy(); - urlStrategy.setUrlPattern(".*" + url); - return urlStrategy; + public static UrlPattern urlEndingWith(String url) { + return urlMatching(".*" + url); } } diff --git a/system-tests/e2e-suite/pom.xml b/system-tests/e2e-suite/pom.xml index b1297d655..d8440da98 100644 --- a/system-tests/e2e-suite/pom.xml +++ b/system-tests/e2e-suite/pom.xml @@ -50,11 +50,6 @@ runtime - - com.google.code.findbugs - jsr305 - - org.scalacheck scalacheck_${scala.version} @@ -100,7 +95,7 @@ - com.github.tomakehurst + org.wiremock wiremock diff --git a/system-tests/e2e-suite/src/test/java/com/hotels/styx/http/StaticFileOnRealServerIT.java b/system-tests/e2e-suite/src/test/java/com/hotels/styx/http/StaticFileOnRealServerIT.java index 467f9f1c6..de91c52c0 100644 --- a/system-tests/e2e-suite/src/test/java/com/hotels/styx/http/StaticFileOnRealServerIT.java +++ b/system-tests/e2e-suite/src/test/java/com/hotels/styx/http/StaticFileOnRealServerIT.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ public void shouldWorkInRealServer() throws Exception { .header("Host", serverEndpoint) .build(); - HttpResponse response = await(client.sendRequest(request)); + HttpResponse response = await(client.send(request)); assertThat(response.bodyAs(UTF_8), is("Hello World")); } diff --git a/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/ProtocolMetricsTest.java b/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/ProtocolMetricsTest.java index ce1ce80cd..498814939 100644 --- a/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/ProtocolMetricsTest.java +++ b/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/ProtocolMetricsTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -118,7 +118,7 @@ private static HttpResponse doRequest(HttpClient client, String protocol, int po .body("foobarbaz", UTF_8) .build(); - return await(client.sendRequest(request)); + return await(client.send(request)); } private static String startWithSlash(String path) { diff --git a/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/StyxMetrics.java b/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/StyxMetrics.java index c8af2f178..feb22b9e8 100644 --- a/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/StyxMetrics.java +++ b/system-tests/e2e-suite/src/test/java/com/hotels/styx/metrics/StyxMetrics.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -159,7 +159,7 @@ private static Object toGauge(Map map) { private static String downloadJsonString(String host, int port) { StyxHttpClient client = new StyxHttpClient.Builder().build(); - HttpResponse response = await(client.sendRequest(get(format("http://%s:%d/admin/metrics", host, port)).build())); + HttpResponse response = await(client.send(get(format("http://%s:%d/admin/metrics", host, port)).build())); return response.bodyAs(UTF_8); } diff --git a/system-tests/e2e-suite/src/test/scala/com/hotels/styx/plugins/AsyncRequestSpec.scala b/system-tests/e2e-suite/src/test/scala/com/hotels/styx/plugins/AsyncRequestSpec.scala index 32ccfcd15..5e8ffcd0b 100644 --- a/system-tests/e2e-suite/src/test/scala/com/hotels/styx/plugins/AsyncRequestSpec.scala +++ b/system-tests/e2e-suite/src/test/scala/com/hotels/styx/plugins/AsyncRequestSpec.scala @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ class AsyncRequestSpec extends FunSpec .addHeader("Content-Length", "0") .build() - val response = Await.result(client.sendRequest(request).toScala, 5.seconds) + val response = Await.result(client.send(request).toScala, 5.seconds) mockServer.verify(1, getRequestedFor(urlStartingWith("/foobar"))) response.bodyAs(UTF_8) should be("I should be here!") diff --git a/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ChunkedRequestSpec.scala b/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ChunkedRequestSpec.scala index 68c419982..5a120092c 100644 --- a/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ChunkedRequestSpec.scala +++ b/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ChunkedRequestSpec.scala @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,8 +15,9 @@ */ package com.hotels.styx.proxy -import com.github.tomakehurst.wiremock.client.{RequestPatternBuilder, UrlMatchingStrategy, ValueMatchingStrategy} +import com.github.tomakehurst.wiremock.client.WireMock.{matching, urlMatching} import com.github.tomakehurst.wiremock.http.RequestMethod +import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder import com.hotels.styx.api.{HttpResponse, HttpResponseStatus, LiveHttpResponse} import com.hotels.styx.javaconvenience.UtilKt import com.hotels.styx.support.TestClientSupport @@ -64,26 +65,14 @@ class ChunkedRequestSpec extends FunSpec UtilKt.copy(new ByteArrayInputStream(chunks), connection.getOutputStream) readResponse(connection) - normalBackend.verify(new RequestPatternBuilder(RequestMethod.POST, urlMatchingStrategy("/chunked/1")) - .withRequestBody(valueMatchingStrategy("abc")) + normalBackend.verify(new RequestPatternBuilder(RequestMethod.POST, urlMatching("/chunked/1")) + .withRequestBody(matching("abc")) ) connection.disconnect() } } - def urlMatchingStrategy(path: String) = { - val pathMatch = new UrlMatchingStrategy() - pathMatch.setUrlPath("/chunked/1") - pathMatch - } - - def valueMatchingStrategy(matches: String) = { - val matchingStrategy = new ValueMatchingStrategy() - matchingStrategy.setMatches("abc") - matchingStrategy - } - @throws(classOf[IOException]) def readResponse(connection: HttpURLConnection): LiveHttpResponse = { val status: Int = connection.getResponseCode diff --git a/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ProxySpec.scala b/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ProxySpec.scala index d8722788b..9d2665914 100644 --- a/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ProxySpec.scala +++ b/system-tests/e2e-suite/src/test/scala/com/hotels/styx/proxy/ProxySpec.scala @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -135,7 +135,7 @@ class ProxySpec extends FunSpec .addHeader(HOST, styxServer.proxyHost) .build() - val resp = Await.result(client.sendRequest(req).toScala, 5.seconds) + val resp = Await.result(client.send(req).toScala, 5.seconds) recordingBackend.verify(headRequestedFor(urlPathEqualTo("/bodiless"))) diff --git a/system-tests/e2e-testsupport/pom.xml b/system-tests/e2e-testsupport/pom.xml index 862516e1c..c63bead29 100644 --- a/system-tests/e2e-testsupport/pom.xml +++ b/system-tests/e2e-testsupport/pom.xml @@ -35,11 +35,6 @@ styx-proxy - - com.google.code.findbugs - jsr305 - - org.junit.jupiter junit-jupiter @@ -58,7 +53,7 @@ - com.github.tomakehurst + org.wiremock wiremock compile diff --git a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/MockOriginServer.java b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/MockOriginServer.java index cb44306fd..2826df8ba 100644 --- a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/MockOriginServer.java +++ b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/MockOriginServer.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,20 +16,11 @@ package com.hotels.styx.servers; import com.github.tomakehurst.wiremock.client.MappingBuilder; -import com.github.tomakehurst.wiremock.client.RequestPatternBuilder; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.client.UrlMatchingStrategy; import com.github.tomakehurst.wiremock.client.WireMock; -import com.github.tomakehurst.wiremock.core.WireMockApp; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.global.NotImplementedRequestDelayControl; -import com.github.tomakehurst.wiremock.http.AdminRequestHandler; -import com.github.tomakehurst.wiremock.http.BasicResponseRenderer; -import com.github.tomakehurst.wiremock.http.ProxyResponseRenderer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.RequestHandler; -import com.github.tomakehurst.wiremock.http.StubRequestHandler; -import com.github.tomakehurst.wiremock.http.StubResponseRenderer; +import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder; +import com.github.tomakehurst.wiremock.matching.UrlPattern; import com.google.common.util.concurrent.ServiceManager; import com.hotels.styx.InetServer; import com.hotels.styx.StyxServers; @@ -38,6 +29,7 @@ import com.hotels.styx.server.HttpConnectorConfig; import com.hotels.styx.server.HttpServers; import com.hotels.styx.server.HttpsConnectorConfig; +import com.hotels.styx.support.api.FakeHttpServer; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.slf4j.Logger; @@ -45,13 +37,12 @@ import java.util.List; -import static com.github.tomakehurst.wiremock.WireMockServer.FILES_ROOT; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.google.common.base.Optional.absent; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.hotels.styx.servers.WiremockResponseConverter.toStyxResponse; import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Collections.emptyMap; public final class MockOriginServer { private static final Logger LOGGER = LoggerFactory.getLogger(MockOriginServer.class); @@ -60,8 +51,7 @@ public final class MockOriginServer { private final String appId; private final String originId; private final int adminPort; - - private int serverPort; + private final int serverPort; private final InetServer adminServer; private final InetServer mockServer; @@ -81,57 +71,40 @@ private MockOriginServer(String appId, String originId, int adminPort, int serve } public static MockOriginServer create(String appId, String originId, int adminPort, HttpConnectorConfig httpConfig) { - WireMockApp wireMockApp = wireMockApp(); - InetServer adminServer = createAdminServer(originId, adminPort, wireMockApp); + int serverPort = httpConfig.port(); + FakeHttpServer fakeHttpServer = fakeHttpServer(appId, originId, serverPort, adminPort); + InetServer adminServer = createAdminServer(originId, adminPort, fakeHttpServer); InetServer mockServer = HttpServers.createHttpServer( "mock-stub-" + originId, httpConfig, - mockHandler(originId, wireMockApp, new WireMockConfiguration())); - int serverPort = httpConfig.port(); + mockHandler(originId, fakeHttpServer)); return new MockOriginServer(appId, originId, adminPort, serverPort, adminServer, mockServer); } public static MockOriginServer create(String appId, String originId, int adminPort, HttpsConnectorConfig httpsConfig) { - WireMockApp wireMockApp = wireMockApp(); - InetServer adminServer = createAdminServer(originId, adminPort, wireMockApp); + int serverPort = httpsConfig.port(); + FakeHttpServer fakeHttpServer = fakeHttpServer(appId, originId, serverPort, adminPort); + InetServer adminServer = createAdminServer(originId, adminPort, fakeHttpServer); InetServer mockServer = HttpServers.createHttpsServer( "mock-stub-" + originId, httpsConfig, - mockHandler(originId, wireMockApp, new WireMockConfiguration())); - int serverPort = httpsConfig.port(); + mockHandler(originId, fakeHttpServer)); return new MockOriginServer(appId, originId, adminPort, serverPort, adminServer, mockServer); } - - private static HttpHandler mockHandler(String originId, WireMockApp wireMockApp, WireMockConfiguration defaultConfig) { - return newHandler(originId, new StubRequestHandler( - wireMockApp, - new StubResponseRenderer( - defaultConfig.filesRoot().child(FILES_ROOT), - wireMockApp.getGlobalSettingsHolder(), - new ProxyResponseRenderer( - defaultConfig.proxyVia(), - defaultConfig.httpsSettings().trustStore(), - defaultConfig.shouldPreserveHostHeader(), - defaultConfig.proxyHostHeader() - ) - ) - )); - } - - private static HttpHandler newHandler(String originId, RequestHandler wireMockHandler) { + private static HttpHandler mockHandler(String originId, FakeHttpServer fakeHttpServer) { return (httpRequest, ctx) -> httpRequest.aggregate(MAX_CONTENT_LENGTH) .map(fullRequest -> { - LOGGER.info("{} received: {}\n{}", new Object[]{originId, fullRequest.url(), fullRequest.body()}); + LOGGER.info("{} received: {}\n{}", originId, fullRequest.url(), fullRequest.body()); return fullRequest; }) .flatMap(fullRequest -> { - Request wmRequest = new WiremockStyxRequestAdapter(fullRequest); - com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest); - return Eventual.of(toStyxResponse(wmResponse).stream()); + ResponseDefinitionBuilder responseDefinitionBuilder = aResponse(); + fakeHttpServer.stub(urlMatching(fullRequest.path()), responseDefinitionBuilder); + return Eventual.of(toStyxResponse(responseDefinitionBuilder).stream()); }); } @@ -150,9 +123,9 @@ public MockOriginServer stop() { return this; } - public MockOriginServer stub(UrlMatchingStrategy urlMatchingStrategy, ResponseDefinitionBuilder response) { + public MockOriginServer stub(UrlPattern urlPattern, ResponseDefinitionBuilder response) { WireMock wm = new WireMock("localhost", adminPort()); - wm.register(WireMock.get(urlMatchingStrategy).willReturn(response)); + wm.register(WireMock.get(urlPattern).willReturn(response)); return this; } @@ -187,57 +160,46 @@ public String originId() { } public int port() { - return mockServer.inetAddress().getPort(); + return serverPort; } public int adminPort() { - return adminServer.inetAddress().getPort(); + return adminPort; } public boolean isRunning() { return services.isHealthy(); } - private static WireMockApp wireMockApp() { - return new WireMockApp( - new NotImplementedRequestDelayControl(), - false, - stubMappings -> { - - }, - mappings -> { - - }, - false, - absent(), - emptyMap(), - null, - null - ); + private static FakeHttpServer fakeHttpServer(String appId, String originId, int serverPort, int adminPort) { + WireMockConfiguration wireMockConfiguration = WireMockConfiguration.wireMockConfig() + .httpsPort(serverPort) + .port(adminPort); + return FakeHttpServer.newHttpServer(appId, originId, wireMockConfiguration); } - private static InetServer createAdminServer(String originId, int adminPort, WireMockApp wireMockApp) { + private static InetServer createAdminServer(String originId, int adminPort, FakeHttpServer fakeHttpServer) { return HttpServers.createHttpServer( "mock-admin-" + originId, new HttpConnectorConfig(adminPort), - adminHandler(wireMockApp)); + adminHandler(fakeHttpServer)); } - private static HttpHandler adminHandler(WireMockApp wireMockApp) { - return newHandler(new AdminRequestHandler(wireMockApp, new BasicResponseRenderer())); + private static HttpHandler adminHandler(FakeHttpServer fakeHttpServer) { + return newHandler(fakeHttpServer); } - private static HttpHandler newHandler(RequestHandler wireMockHandler) { + private static HttpHandler newHandler(FakeHttpServer fakeHttpServer) { return (httpRequest, ctx) -> httpRequest.aggregate(MAX_CONTENT_LENGTH) .map(fullRequest -> { - LOGGER.info("Received: {}\n{}", new Object[]{fullRequest.url(), fullRequest.body()}); + LOGGER.info("Received: {}\n{}", fullRequest.url(), fullRequest.body()); return fullRequest; }) .flatMap(fullRequest -> { - Request wmRequest = new WiremockStyxRequestAdapter(fullRequest); - com.github.tomakehurst.wiremock.http.Response wmResponse = wireMockHandler.handle(wmRequest); - return Eventual.of(toStyxResponse(wmResponse).stream()); + ResponseDefinitionBuilder responseDefinitionBuilder = aResponse(); + fakeHttpServer.stub(urlMatching(fullRequest.path()), responseDefinitionBuilder); + return Eventual.of(toStyxResponse(responseDefinitionBuilder).stream()); }); } } diff --git a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockResponseConverter.java b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockResponseConverter.java index d0401aa93..d7939f020 100644 --- a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockResponseConverter.java +++ b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockResponseConverter.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,24 +15,30 @@ */ package com.hotels.styx.servers; +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.http.Response; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; import com.hotels.styx.api.HttpHeaders; import com.hotels.styx.api.HttpResponse; +import java.nio.charset.StandardCharsets; + import static com.hotels.styx.api.HttpResponseStatus.statusWithCode; +import static java.nio.charset.StandardCharsets.UTF_8; final class WiremockResponseConverter { private WiremockResponseConverter() { } - static HttpResponse toStyxResponse(Response response) { - HttpHeaders headers = toStyxHeaders(response.getHeaders()); - byte[] body = response.getBody(); + static HttpResponse toStyxResponse(ResponseDefinitionBuilder responseDefinitionBuilder) { + ResponseDefinition responseDefinition = responseDefinitionBuilder.build(); + HttpHeaders headers = toStyxHeaders(responseDefinition.getHeaders()); + String body = responseDefinition.getBody(); - return HttpResponse.response(statusWithCode(response.getStatus())) + return HttpResponse.response(statusWithCode(responseDefinition.getStatus())) .headers(headers) - .body(body, false) + .body(body, UTF_8) .build(); } diff --git a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockStyxRequestAdapter.java b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockStyxRequestAdapter.java deleted file mode 100644 index ba89ca397..000000000 --- a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/servers/WiremockStyxRequestAdapter.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - Copyright (C) 2013-2021 Expedia Inc. - - 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. - */ -package com.hotels.styx.servers; - -import com.github.tomakehurst.wiremock.http.ContentTypeHeader; -import com.github.tomakehurst.wiremock.http.HttpHeader; -import com.github.tomakehurst.wiremock.http.HttpHeaders; -import com.github.tomakehurst.wiremock.http.QueryParameter; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.RequestMethod; -import com.hotels.styx.api.HttpRequest; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.github.tomakehurst.wiremock.http.HttpHeader.httpHeader; -import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; -import static io.netty.handler.codec.http.HttpHeaderNames.HOST; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Objects.requireNonNull; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; - -public class WiremockStyxRequestAdapter implements Request { - private final HttpRequest styxRequest; - - public WiremockStyxRequestAdapter(HttpRequest styxRequest) { - this.styxRequest = requireNonNull(styxRequest); - } - - @Override - public String getUrl() { - return styxRequest.path(); - } - - @Override - public String getAbsoluteUrl() { - String host = styxRequest.header(HOST).orElse(""); - String protocol = "http"; - - return protocol + "://" + host + styxRequest.url().toURI().toString(); - } - - @Override - public RequestMethod getMethod() { - return RequestMethod.fromString(styxRequest.method().name()); - } - - @Override - public String getHeader(String key) { - return styxRequest.header(key).orElse(null); - } - - @Override - public HttpHeader header(String key) { - List values = styxRequest.headers(key); - return httpHeader(key, values.toArray(new String[values.size()])); - } - - @Override - public ContentTypeHeader contentTypeHeader() { - return styxRequest.header(CONTENT_TYPE) - .map(ContentTypeHeader::new) - .orElseGet(ContentTypeHeader::absent); - } - - @Override - public HttpHeaders getHeaders() { - List list = stream(styxRequest.headers().spliterator(), false) - .map(styxHeader -> httpHeader(styxHeader.name(), styxHeader.value())) - .collect(toList()); - - return new HttpHeaders(list); - } - - @Override - public boolean containsHeader(String key) { - return styxRequest.headers().contains(key); - } - - @Override - public Set getAllHeaderKeys() { - return new HashSet<>(styxRequest.headers().names()); - } - - @Override - public QueryParameter queryParameter(String key) { - return styxRequest.queryParam(key) - .map(value -> new QueryParameter(key, List.of(value))) - .orElseGet(() -> QueryParameter.absent(key)); - } - - @Override - public byte[] getBody() { - return styxRequest.body(); - } - - @Override - public String getBodyAsString() { - return styxRequest.bodyAs(UTF_8); - } - - @Override - public boolean isBrowserProxyRequest() { - return false; - } -} diff --git a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/utils/MetricsSnapshot.java b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/utils/MetricsSnapshot.java index 239325539..181d15ffd 100644 --- a/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/utils/MetricsSnapshot.java +++ b/system-tests/e2e-testsupport/src/main/java/com/hotels/styx/utils/MetricsSnapshot.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2022 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ private MetricsSnapshot(Map tree) { public static MetricsSnapshot downloadFrom(String host, int port) throws IOException { HttpClient client = new StyxHttpClient.Builder().build(); - HttpResponse response = await(client.sendRequest(get(format("http://%s:%d/admin/metrics", host, port)).build())); + HttpResponse response = await(client.send(get(format("http://%s:%d/admin/metrics", host, port)).build())); return new MetricsSnapshot(decodeToMap(response.bodyAs(UTF_8))); } diff --git a/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/MockOriginServerTest.java b/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/MockOriginServerTest.java index e1e698600..deac199e3 100644 --- a/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/MockOriginServerTest.java +++ b/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/MockOriginServerTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.hotels.styx.servers; -import com.github.tomakehurst.wiremock.client.ValueMatchingStrategy; import com.github.tomakehurst.wiremock.client.WireMock; import com.hotels.styx.api.HttpResponse; import com.hotels.styx.api.extension.service.TlsSettings; @@ -32,6 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.matching; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.hotels.styx.api.HttpRequest.get; @@ -73,7 +73,7 @@ public void configuresEndpoints() { .withHeader("a", "b") .withBody("Hello, World!")); - HttpResponse response = await(client.sendRequest( + HttpResponse response = await(client.send( get(format("http://localhost:%d/mock", server.port())) .header("X-Forwarded-Proto", "http") .build())); @@ -83,7 +83,7 @@ public void configuresEndpoints() { assertThat(response.bodyAs(UTF_8), is("Hello, World!")); server.verify(getRequestedFor(urlEqualTo("/mock")) - .withHeader("X-Forwarded-Proto", valueMatchingStrategy("http"))); + .withHeader("X-Forwarded-Proto", matching("http"))); } @Test @@ -99,7 +99,7 @@ public void configuresTlsEndpoints() throws Exception { .withBody("Hello, World!")); HttpResponse response = await( - tlsClient.sendRequest( + tlsClient.send( get(format("https://localhost:%d/mock", server.port())) .header("X-Forwarded-Proto", "http") .build())); @@ -108,13 +108,7 @@ public void configuresTlsEndpoints() throws Exception { assertThat(response.header("a"), is(Optional.of("b"))); server.verify(getRequestedFor(urlEqualTo("/mock")) - .withHeader("X-Forwarded-Proto", valueMatchingStrategy("http"))); - } - - private ValueMatchingStrategy valueMatchingStrategy(String matches) { - ValueMatchingStrategy strategy = new ValueMatchingStrategy(); - strategy.setMatches(matches); - return strategy; + .withHeader("X-Forwarded-Proto", matching("http"))); } private HostnameVerifier disableHostNameVerification() { diff --git a/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockResponseConverterTest.java b/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockResponseConverterTest.java index b7cf664dc..297679328 100644 --- a/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockResponseConverterTest.java +++ b/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockResponseConverterTest.java @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2021 Expedia Inc. + Copyright (C) 2013-2024 Expedia Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,10 +15,8 @@ */ package com.hotels.styx.servers; -import com.github.tomakehurst.wiremock.http.BasicResponseRenderer; +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.http.HttpHeaders; -import com.github.tomakehurst.wiremock.http.Response; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; import com.hotels.styx.api.HttpHeader; import com.hotels.styx.api.HttpResponse; import org.junit.jupiter.api.Test; @@ -29,11 +27,11 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.http.HttpHeader.httpHeader; import static com.hotels.styx.api.HttpResponseStatus.CREATED; import static com.hotels.styx.api.HttpResponseStatus.OK; import static com.hotels.styx.servers.WiremockResponseConverter.toStyxResponse; -import static java.net.HttpURLConnection.HTTP_OK; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -42,10 +40,7 @@ public class WiremockResponseConverterTest { @Test public void convertsCreatedResponse() { - ResponseDefinition created = ResponseDefinition.created(); - Response render = new BasicResponseRenderer().render(created); - - HttpResponse styxResponse = toStyxResponse(render); + HttpResponse styxResponse = toStyxResponse(aResponse()); assertThat(styxResponse.status(), is(CREATED)); assertThat(styxResponse.bodyAs(UTF_8), is("")); @@ -54,19 +49,21 @@ public void convertsCreatedResponse() { @Test public void convertsResponseWithBody() { - ResponseDefinition response = new ResponseDefinition(HTTP_OK, "{ \"count\" : 0, \"requestJournalDisabled\" : false}"); - response.setHeaders(new HttpHeaders( - httpHeader("Transfer-Encoding", "chunked"), - httpHeader("Content-Type", "application/json"))); + ResponseDefinitionBuilder responseDefinitionBuilder = + aResponse().withBody("{ \"count\" : 0, \"requestJournalDisabled\" : false}"); + responseDefinitionBuilder.withHeaders(new HttpHeaders( + httpHeader("Transfer-Encoding", "chunked"), + httpHeader("Content-Type", "application/json")) + ); - HttpResponse styxResponse = toStyxResponse(new BasicResponseRenderer().render(response)); + HttpResponse styxResponse = toStyxResponse(responseDefinitionBuilder); assertThat(styxResponse.status(), is(OK)); Map actual = headersAsMap(styxResponse); assertThat(actual, is(Map.of( - "Transfer-Encoding", "chunked", - "Content-Type", "application/json"))); + "Transfer-Encoding", "chunked", + "Content-Type", "application/json"))); assertThat(styxResponse.bodyAs(UTF_8), is("{ \"count\" : 0, \"requestJournalDisabled\" : false}")); assertThat(headerCount(styxResponse.headers()), is(2)); } @@ -75,7 +72,7 @@ private Map headersAsMap(HttpResponse response) { Spliterator spliterator = response.headers().spliterator(); return StreamSupport.stream(spliterator, false) - .collect(Collectors.toMap(HttpHeader::name, HttpHeader::value)); + .collect(Collectors.toMap(HttpHeader::name, HttpHeader::value)); } private int headerCount(com.hotels.styx.api.HttpHeaders headers) { diff --git a/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockStyxRequestAdapterTest.java b/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockStyxRequestAdapterTest.java deleted file mode 100644 index 11ae6e351..000000000 --- a/system-tests/e2e-testsupport/src/test/java/com/hotels/styx/servers/WiremockStyxRequestAdapterTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - Copyright (C) 2013-2022 Expedia Inc. - - 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. - */ -package com.hotels.styx.servers; - -import com.github.tomakehurst.wiremock.http.ContentTypeHeader; -import com.github.tomakehurst.wiremock.http.QueryParameter; -import com.google.common.base.Optional; -import com.hotels.styx.api.HttpRequest; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import static com.github.tomakehurst.wiremock.http.RequestMethod.POST; -import static com.hotels.styx.api.HttpHeaderNames.CONNECTION; -import static com.hotels.styx.api.HttpHeaderNames.CONTENT_TYPE; -import static io.netty.handler.codec.http.HttpHeaderNames.HOST; -import static io.netty.handler.codec.http.HttpHeaderNames.USER_AGENT; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - - -public class WiremockStyxRequestAdapterTest { - private WiremockStyxRequestAdapter adapter; - private String content; - private HttpRequest.Builder styxRequestBuilder; - - @BeforeEach - public void setUp() { - content = "{\n" + - " \"request\" : {\n" + - " \"urlPattern\" : \"/.*\",\n" + - " \"method\" : \"GET\"\n" + - " },\n" + - " \"response\" : {\n" + - " \"status\" : 200,\n" + - " \"body\" : \"Hello, World!\",\n" + - " \"headers\" : {\n" + - " \"Stub-Origin-Info\" : \"App TLS v1.1\"\n" + - " }\n" + - " }\n" + - "}"; - - styxRequestBuilder = HttpRequest.post("/__admin/mappings/new?msg=6198.1") - .header(CONTENT_TYPE, "application/json; charset=UTF-8") - .header(HOST, "localhost") - .header(CONNECTION, "Keep-Alive") - .header(USER_AGENT, "Apache-HttpClient/4.3.5 (java 1.5)") - .body(content, UTF_8); - - adapter = new WiremockStyxRequestAdapter(styxRequestBuilder.build()); - } - - @Test - public void adaptsContainsHeader() { - assertThat(adapter.containsHeader("Foo-Bar"), is(false)); - assertThat(adapter.containsHeader("Host"), is(true)); - assertThat(adapter.containsHeader("host"), is(true)); - } - - // Disabled due to a failing test. - // Looks like it is an underlying problem with Netty, which doesn't convert - // HTTP header names from AsciiString to String when toArray() is called on - // CharSequenceDelegatingStringSet. - @Disabled - @Test - public void adaptsGetAllHeaderKeys() { - assertEquals(adapter.getAllHeaderKeys(), contains("Connection", "user-agent", "Content-Type", "Content-Length", "host")); - } - - @Test - public void adaptsGetUrl() { - assertThat(adapter.getUrl(), is("/__admin/mappings/new")); - } - - @Test - public void adaptsGetAbsoluteUrl() { - assertThat(adapter.getAbsoluteUrl(), is("http://localhost/__admin/mappings/new?msg=6198.1")); - } - - @Test - public void adaptsGetMethod() { - assertThat(adapter.getMethod(), is(POST)); - } - - @Test - public void adaptsGetHeader() { - assertThat(adapter.getHeader("Content-Length"), is("246")); - assertThat(adapter.getHeader("Foo-Bar"), is(nullValue())); - } - - @Test - public void adaptsGetHeaders() { - assertThat(adapter.getHeaders().keys(), containsInAnyOrder("content-type", "host", "connection", "user-agent", "content-length")); - - assertThat(adapter.getHeader("content-type"), is("application/json; charset=UTF-8")); - assertThat(adapter.getHeader("host"), is("localhost")); - assertThat(adapter.getHeader("connection"), is("Keep-Alive")); - assertThat(adapter.getHeader("user-agent"), is("Apache-HttpClient/4.3.5 (java 1.5)")); - assertThat(adapter.getHeader("content-length"), is("246")); - } - - @Test - public void adaptsGetBodyWhenAbsent() { - assertThat(adapter.getBody(), is(content.getBytes(UTF_8))); - } - - @Test - public void adaptsGetBodyWhenPresent() { - assertThat(adapter.getBody(), is(content.getBytes(UTF_8))); - } - - @Test - public void adaptsGetBodyAsStringWhenAbsent() { - assertThat(adapter.getBodyAsString(), is(content)); - } - - @Test - public void adaptsGetBodyAsStringWhenPresent() { - assertThat(adapter.getBodyAsString(), is(content)); - } - - @Test - public void adaptsContentTypeHeaderWhenPresent() { - ContentTypeHeader contentType = adapter.contentTypeHeader(); - - assertThat(contentType.encodingPart(), is(Optional.of("UTF-8"))); - assertThat(contentType.mimeTypePart(), is("application/json")); - } - - @Test - public void adaptsQueryParameter() { - QueryParameter msg = adapter.queryParameter("msg"); - - assertThat(msg.key(), is("msg")); - assertThat(msg.values(), is(contains("6198.1"))); - } - - @Test - public void adaptsNonExistantQueryParameterToNull() { - QueryParameter msg = adapter.queryParameter("foobar"); - - assertThat(msg.key(), is("foobar")); - assertThrows(IllegalStateException.class, () -> msg.values()); - } - - @Test - public void adaptsContentTypeHeaderWhenAbsent() { - adapter = new WiremockStyxRequestAdapter( - styxRequestBuilder - .removeHeader(CONTENT_TYPE) - .build()); - - // NOTE: We don't call actual.mimeTypePart() or encodingPart() methods. - // WireMock will throw a NullPointerException when they are called on an - // absent ContentTypeHeader. Possibly a bug. - assertThat(adapter.contentTypeHeader().key(), is("Content-Type")); - } - - @Test - public void adaptsIsBrowserProxyRequest() { - assertThat(adapter.isBrowserProxyRequest(), is(false)); - } - -} \ No newline at end of file