From ee089ea9adab279e4724c9562328950dce4f9b99 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Thu, 7 Dec 2023 17:53:22 +0100 Subject: [PATCH 1/9] Update dependencies --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index bb2318b6df..dbed355914 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.warning.mode=all org.gradle.console=plain # Gradle -version=3.4.5 +version=3.4.6 group=com.hexagonkt description=The atoms of your platform @@ -37,7 +37,7 @@ mockkVersion=1.13.8 junitVersion=5.10.1 gatlingVersion=3.9.5 jmhVersion=1.37 -mkdocsMaterialVersion=9.4.14 +mkdocsMaterialVersion=9.5.0 mermaidDokkaVersion=0.4.4 nativeToolsVersion=0.9.28 From c563add7e9080a9271751514c47f961cd7322d12 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Fri, 8 Dec 2023 17:16:57 +0100 Subject: [PATCH 2/9] Update dependencies --- contributing.md | 3 ++- gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/contributing.md b/contributing.md index 85d1a6ee9e..fc815643ae 100644 --- a/contributing.md +++ b/contributing.md @@ -119,10 +119,11 @@ If you want to generate the documentation site, check the Hexagon's site module 11. Publish changelog on: * Dev.to * Kotlin Slack - * Reddit + * Reddit Kotlin * Twitter * Kotlin Weekly Newsletter * LinkedIn + * Mailing lists (Awesome Kotlin, Kotlin Weekly) [Nexus Repository Manager]: https://oss.sonatype.org diff --git a/gradle.properties b/gradle.properties index dbed355914..a40b4dec4e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ mockkVersion=1.13.8 junitVersion=5.10.1 gatlingVersion=3.9.5 jmhVersion=1.37 -mkdocsMaterialVersion=9.5.0 +mkdocsMaterialVersion=9.5.1 mermaidDokkaVersion=0.4.4 nativeToolsVersion=0.9.28 @@ -67,7 +67,7 @@ dslJsonVersion=2.0.2 freemarkerVersion=2.3.32 # templates_jte -jteVersion=3.1.5 +jteVersion=3.1.6 # templates_pebble pebbleVersion=3.2.2 From 70c85b20a3b6a44585df998f8e2a1c8f6e9fb6e0 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Tue, 12 Dec 2023 20:09:18 +0100 Subject: [PATCH 3/9] Update dependencies --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a40b4dec4e..395c937b29 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ mockkVersion=1.13.8 junitVersion=5.10.1 gatlingVersion=3.9.5 jmhVersion=1.37 -mkdocsMaterialVersion=9.5.1 +mkdocsMaterialVersion=9.5.2 mermaidDokkaVersion=0.4.4 nativeToolsVersion=0.9.28 From 6f6336656f8ae2a449bc40d8d98fa2201336fa77 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Tue, 19 Dec 2023 22:36:01 +0100 Subject: [PATCH 4/9] Refactor --- core/src/main/kotlin/com/hexagonkt/core/Network.kt | 2 +- core/src/main/kotlin/com/hexagonkt/core/text/Ansi.kt | 2 +- core/src/main/kotlin/com/hexagonkt/core/text/Cases.kt | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/kotlin/com/hexagonkt/core/Network.kt b/core/src/main/kotlin/com/hexagonkt/core/Network.kt index 28fff58fed..b64baee0db 100644 --- a/core/src/main/kotlin/com/hexagonkt/core/Network.kt +++ b/core/src/main/kotlin/com/hexagonkt/core/Network.kt @@ -7,7 +7,7 @@ import java.util.* /** Internet address used to bind services to all local network interfaces. */ val ALL_INTERFACES: InetAddress by lazy { inetAddress(0, 0, 0, 0) } -/** Internet address used to bind services to the loopback interface. */ +/** Internet address used to bind services to the loop-back interface. */ val LOOPBACK_INTERFACE: InetAddress by lazy { inetAddress(127, 0, 0, 1) } /** diff --git a/core/src/main/kotlin/com/hexagonkt/core/text/Ansi.kt b/core/src/main/kotlin/com/hexagonkt/core/text/Ansi.kt index 41d2f052ce..02ee2eb3b6 100644 --- a/core/src/main/kotlin/com/hexagonkt/core/text/Ansi.kt +++ b/core/src/main/kotlin/com/hexagonkt/core/text/Ansi.kt @@ -6,7 +6,7 @@ package com.hexagonkt.core.text */ object Ansi { /** Regex that matches ANSI escape sequences. */ - val REGEX: Regex = """\u001B\[\d+?m""".toRegex() + val REGEX: Regex by lazy { """\u001B\[\d+?m""".toRegex() } /** Control Sequence Introducer. */ const val CSI = "\u001B[" diff --git a/core/src/main/kotlin/com/hexagonkt/core/text/Cases.kt b/core/src/main/kotlin/com/hexagonkt/core/text/Cases.kt index 8c446c5311..673e27728e 100644 --- a/core/src/main/kotlin/com/hexagonkt/core/text/Cases.kt +++ b/core/src/main/kotlin/com/hexagonkt/core/text/Cases.kt @@ -1,9 +1,9 @@ package com.hexagonkt.core.text -val CAMEL_CASE: Regex = Regex("[a-z]+([A-Z][a-z0-9]+)+") -val PASCAL_CASE: Regex = Regex("([A-Z][a-z0-9]+)+") -val SNAKE_CASE: Regex = Regex("[A-Za-z]+(_[A-Za-z0-9]+)+") -val KEBAB_CASE: Regex = Regex("[A-Za-z]+(-[A-Za-z0-9]+)+") +val CAMEL_CASE: Regex by lazy { Regex("[a-z]+([A-Z][a-z0-9]+)+") } +val PASCAL_CASE: Regex by lazy { Regex("([A-Z][a-z0-9]+)+") } +val SNAKE_CASE: Regex by lazy { Regex("[A-Za-z]+(_[A-Za-z0-9]+)+") } +val KEBAB_CASE: Regex by lazy { Regex("[A-Za-z]+(-[A-Za-z0-9]+)+") } fun String.camelToWords(): List = split("(?=\\p{Upper}\\p{Lower})".toRegex()).toWords() From 4910f3de2ad1a2e8685e021fc407cbb7900599c7 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Tue, 19 Dec 2023 22:37:07 +0100 Subject: [PATCH 5/9] Update dependencies --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 395c937b29..fdd4ca5081 100644 --- a/gradle.properties +++ b/gradle.properties @@ -35,14 +35,14 @@ kotlinVersion=1.9.21 dokkaVersion=1.9.10 mockkVersion=1.13.8 junitVersion=5.10.1 -gatlingVersion=3.9.5 +gatlingVersion=3.10.2 jmhVersion=1.37 mkdocsMaterialVersion=9.5.2 mermaidDokkaVersion=0.4.4 nativeToolsVersion=0.9.28 # http_server_netty -nettyVersion=4.1.101.Final +nettyVersion=4.1.104.Final nettyTcNativeVersion=2.0.62.Final # http_server_helidon From 985cf22f7dcb74352c61548dbe449879e48762d3 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Tue, 19 Dec 2023 22:51:35 +0100 Subject: [PATCH 6/9] Refactor --- README.md | 2 +- gradle.properties | 2 +- gradle/kotlin.gradle | 2 +- http/http_handlers/api/http_handlers.api | 30 ++++++++++++++++--- .../http/handlers/ExceptionHandler.kt | 18 +++++++++++ .../hexagonkt/http/handlers/HandlerBuilder.kt | 13 +++----- .../com/hexagonkt/http/handlers/Handlers.kt | 30 ++++--------------- .../hexagonkt/http/handlers/HttpHandler.kt | 3 ++ .../hexagonkt/http/handlers/HandlersTest.kt | 23 ++------------ .../http/server/jetty/JettyServletAdapter.kt | 2 +- .../http/test/examples/ErrorsTest.kt | 3 +- .../http/test/examples/SamplesTest.kt | 4 +-- 12 files changed, 66 insertions(+), 66 deletions(-) create mode 100644 http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/ExceptionHandler.kt diff --git a/README.md b/README.md index 5130273629..2e37349688 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ private val path: PathHandler = path { * Catching `Exception` handles any unhandled exception, has to be the last executed (first * declared) */ - exception(NOT_FOUND_404) { + exception { internalServerError("Root handler") } diff --git a/gradle.properties b/gradle.properties index fdd4ca5081..86a5a6ad65 100644 --- a/gradle.properties +++ b/gradle.properties @@ -50,7 +50,7 @@ helidonVersion=4.0.1 # http_server_servlet servletVersion=6.0.0 -jettyVersion=12.0.4 +jettyVersion=12.0.5 # rest_tools swaggerRequestValidatorVersion=2.39.0 diff --git a/gradle/kotlin.gradle b/gradle/kotlin.gradle index 114166a79d..14dd041708 100644 --- a/gradle/kotlin.gradle +++ b/gradle/kotlin.gradle @@ -11,7 +11,7 @@ apply(plugin: "maven-publish") defaultTasks("build") java { - sourceCompatibility = JavaVersion.toVersion(findProperty("jvmTarget") ?: "17") + sourceCompatibility = JavaVersion.toVersion(findProperty("jvmTarget") ?: "11") targetCompatibility = sourceCompatibility } diff --git a/http/http_handlers/api/http_handlers.api b/http/http_handlers/api/http_handlers.api index fec1a4d64a..1b36b35746 100644 --- a/http/http_handlers/api/http_handlers.api +++ b/http/http_handlers/api/http_handlers.api @@ -50,6 +50,30 @@ public final class com/hexagonkt/http/handlers/BeforeHandler : com/hexagonkt/han public fun toString ()Ljava/lang/String; } +public final class com/hexagonkt/http/handlers/ExceptionHandler : com/hexagonkt/handlers/Handler, com/hexagonkt/http/handlers/HttpHandler { + public fun (Lkotlin/reflect/KClass;ZLkotlin/jvm/functions/Function2;)V + public synthetic fun (Lkotlin/reflect/KClass;ZLkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun addPrefix (Ljava/lang/String;)Lcom/hexagonkt/http/handlers/HttpHandler; + public fun byMethod ()Ljava/util/Map; + public final fun component1 ()Lkotlin/reflect/KClass; + public final fun component2 ()Z + public final fun component3 ()Lkotlin/jvm/functions/Function2; + public final fun copy (Lkotlin/reflect/KClass;ZLkotlin/jvm/functions/Function2;)Lcom/hexagonkt/http/handlers/ExceptionHandler; + public static synthetic fun copy$default (Lcom/hexagonkt/http/handlers/ExceptionHandler;Lkotlin/reflect/KClass;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/ExceptionHandler; + public fun equals (Ljava/lang/Object;)Z + public fun filter (Lcom/hexagonkt/http/model/HttpMethod;)Lcom/hexagonkt/http/handlers/HttpHandler; + public final fun getBlock ()Lkotlin/jvm/functions/Function2; + public fun getCallback ()Lkotlin/jvm/functions/Function1; + public final fun getClear ()Z + public final fun getException ()Lkotlin/reflect/KClass; + public fun getHandlerPredicate ()Lcom/hexagonkt/http/handlers/HttpPredicate; + public fun getPredicate ()Lkotlin/jvm/functions/Function1; + public fun hashCode ()I + public fun process (Lcom/hexagonkt/handlers/Context;)Lcom/hexagonkt/handlers/Context; + public fun process (Lcom/hexagonkt/http/model/HttpRequestPort;)Lcom/hexagonkt/http/handlers/HttpContext; + public fun toString ()Ljava/lang/String; +} + public final class com/hexagonkt/http/handlers/FilterHandler : com/hexagonkt/handlers/Handler, com/hexagonkt/http/handlers/HttpHandler { public fun (Lcom/hexagonkt/http/handlers/HttpPredicate;Lkotlin/jvm/functions/Function1;)V public synthetic fun (Lcom/hexagonkt/http/handlers/HttpPredicate;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V @@ -96,8 +120,8 @@ public final class com/hexagonkt/http/handlers/HandlerBuilder { public static synthetic fun before$default (Lcom/hexagonkt/http/handlers/HandlerBuilder;Ljava/util/Set;Ljava/lang/String;Lkotlin/reflect/KClass;Lcom/hexagonkt/http/model/HttpStatus;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V public final fun delete (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V public static synthetic fun delete$default (Lcom/hexagonkt/http/handlers/HandlerBuilder;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V - public final fun exception (Lkotlin/reflect/KClass;Lcom/hexagonkt/http/model/HttpStatus;ZLkotlin/jvm/functions/Function2;)V - public static synthetic fun exception$default (Lcom/hexagonkt/http/handlers/HandlerBuilder;Lkotlin/reflect/KClass;Lcom/hexagonkt/http/model/HttpStatus;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public final fun exception (Lkotlin/reflect/KClass;ZLkotlin/jvm/functions/Function2;)V + public static synthetic fun exception$default (Lcom/hexagonkt/http/handlers/HandlerBuilder;Lkotlin/reflect/KClass;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public final fun filter (Lcom/hexagonkt/http/handlers/HttpPredicate;Lkotlin/jvm/functions/Function1;)V public final fun filter (Lcom/hexagonkt/http/model/HttpMethod;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V public final fun filter (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V @@ -142,8 +166,6 @@ public final class com/hexagonkt/http/handlers/HandlerBuilder { public final class com/hexagonkt/http/handlers/HandlersKt { public static final fun Delete (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/hexagonkt/http/handlers/OnHandler; public static synthetic fun Delete$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/OnHandler; - public static final fun Exception (Lkotlin/reflect/KClass;Lcom/hexagonkt/http/model/HttpStatus;ZLkotlin/jvm/functions/Function2;)Lcom/hexagonkt/http/handlers/AfterHandler; - public static synthetic fun Exception$default (Lkotlin/reflect/KClass;Lcom/hexagonkt/http/model/HttpStatus;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/AfterHandler; public static final fun Get (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/hexagonkt/http/handlers/OnHandler; public static synthetic fun Get$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/OnHandler; public static final fun Head (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/hexagonkt/http/handlers/OnHandler; diff --git a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/ExceptionHandler.kt b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/ExceptionHandler.kt new file mode 100644 index 0000000000..2c123747e4 --- /dev/null +++ b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/ExceptionHandler.kt @@ -0,0 +1,18 @@ +package com.hexagonkt.http.handlers + +import com.hexagonkt.handlers.ExceptionHandler +import com.hexagonkt.handlers.Handler +import com.hexagonkt.http.model.HttpCall +import kotlin.reflect.KClass + +data class ExceptionHandler( + val exception: KClass, + val clear: Boolean = true, + val block: HttpExceptionCallback +) : HttpHandler, Handler by ExceptionHandler(exception, clear, toCallback(block)) { + + override val handlerPredicate: HttpPredicate = HttpPredicate() + + override fun addPrefix(prefix: String): HttpHandler = + this +} diff --git a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HandlerBuilder.kt b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HandlerBuilder.kt index c16418d5cc..ee5b5f67b6 100644 --- a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HandlerBuilder.kt +++ b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HandlerBuilder.kt @@ -133,20 +133,15 @@ class HandlerBuilder(var handlers: List = emptyList()) { } fun exception( - exception: KClass? = null, - status: HttpStatus? = null, - clear: Boolean = true, - callback: HttpExceptionCallback, + exception: KClass, clear: Boolean = true, callback: HttpExceptionCallback ) { - use(Exception(exception, status, clear, callback)) + use(ExceptionHandler(exception, clear, callback)) } inline fun exception( - status: HttpStatus? = null, - clear: Boolean = true, - noinline callback: HttpExceptionCallback, + clear: Boolean = true, noinline callback: HttpExceptionCallback, ) { - use(Exception(T::class, status, clear, callback)) + use(ExceptionHandler(T::class, clear, callback)) } fun get(pattern: String = "", callback: HttpCallback) { diff --git a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/Handlers.kt b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/Handlers.kt index 3316a4deaf..5bdd33f724 100644 --- a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/Handlers.kt +++ b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/Handlers.kt @@ -12,8 +12,6 @@ import com.hexagonkt.http.model.HttpRequest import java.lang.IllegalStateException import java.math.BigInteger import java.security.cert.X509Certificate -import kotlin.reflect.KClass -import kotlin.reflect.cast typealias HttpCallback = HttpContext.() -> HttpContext typealias HttpExceptionCallback = HttpContext.(T) -> HttpContext @@ -27,6 +25,11 @@ private val BODY_TYPES_NAMES: String by lazy { internal fun toCallback(block: HttpCallback): (Context) -> Context = { context -> HttpContext(context).block() } +internal fun toCallback( + block: HttpExceptionCallback +): (Context, E) -> Context = + { context, e -> HttpContext(context).block(e) } + fun HttpCallback.process( request: HttpRequest, attributes: Map<*, *> = emptyMap() @@ -87,29 +90,6 @@ fun path(contextPath: String = "", handlers: List): PathHandler = PathHandler(contextPath, it) } -fun Exception( - exception: KClass? = null, - status: HttpStatus? = null, - clear: Boolean = true, - callback: HttpExceptionCallback, -): AfterHandler = - AfterHandler(emptySet(), "*", exception, status) { - callback(this.exception.castException(exception)).let { - if (clear) it.copy(exception = null) - else it - } - } - -inline fun Exception( - status: HttpStatus? = null, - clear: Boolean = true, - noinline callback: HttpExceptionCallback, -): AfterHandler = - Exception(T::class, status, clear, callback) - -internal fun Exception?.castException(exception: KClass?) = - this?.let { exception?.cast(this) } ?: error("Exception 'null' or incorrect type") - fun Get(pattern: String = "", callback: HttpCallback): OnHandler = OnHandler(GET, pattern, callback) diff --git a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HttpHandler.kt b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HttpHandler.kt index 463949244f..b9fafda377 100644 --- a/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HttpHandler.kt +++ b/http/http_handlers/src/main/kotlin/com/hexagonkt/http/handlers/HttpHandler.kt @@ -36,6 +36,9 @@ sealed interface HttpHandler : Handler { is BeforeHandler -> copy(handlerPredicate = handlerPredicate.clearMethods()) + + is ExceptionHandler<*> -> + this } fun process(request: HttpRequestPort): HttpContext = diff --git a/http/http_handlers/src/test/kotlin/com/hexagonkt/http/handlers/HandlersTest.kt b/http/http_handlers/src/test/kotlin/com/hexagonkt/http/handlers/HandlersTest.kt index b278a61173..6be5e0e964 100644 --- a/http/http_handlers/src/test/kotlin/com/hexagonkt/http/handlers/HandlersTest.kt +++ b/http/http_handlers/src/test/kotlin/com/hexagonkt/http/handlers/HandlersTest.kt @@ -9,7 +9,6 @@ import java.math.BigInteger import java.time.LocalDate import kotlin.test.assertEquals import kotlin.test.assertFailsWith -import kotlin.reflect.KClass import kotlin.test.assertContentEquals import kotlin.test.assertNull @@ -48,25 +47,9 @@ internal class HandlersTest { assertEquals(expected2.handlersPredicates(), actual2.handlersPredicates()) } - @Test - @Suppress("CAST_NEVER_SUCCEEDS") // Required for test 'null' arguments - fun `Exceptions are casted properly`() { - assertFailsWith { null.castException(Exception::class) } - assertFailsWith { null.castException(null as? KClass) } - assertFailsWith { - IllegalStateException().castException(IllegalArgumentException::class) - } - assertFailsWith { - RuntimeException().castException(null as? KClass) - } - - val ise = IllegalStateException() - assertEquals(ise, ise.castException(RuntimeException::class)) - } - @Test fun `Exceptions are cleared properly`() { PathHandler( - Exception { ok() }, + ExceptionHandler(Exception::class) { ok() }, OnHandler { error("Error") } ) .process(HttpRequest()) @@ -76,7 +59,7 @@ internal class HandlersTest { } PathHandler( - Exception { this }, + ExceptionHandler(Exception::class) { this }, OnHandler { error("Error") } ) .process(HttpRequest()) @@ -86,7 +69,7 @@ internal class HandlersTest { } PathHandler( - Exception(clear = false) { ok() }, + ExceptionHandler(Exception::class, clear = false) { ok() }, OnHandler { error("Error") } ) .process(HttpRequest()) diff --git a/http/http_server_jetty/src/main/kotlin/com/hexagonkt/http/server/jetty/JettyServletAdapter.kt b/http/http_server_jetty/src/main/kotlin/com/hexagonkt/http/server/jetty/JettyServletAdapter.kt index 52e8475add..6e7624bcaa 100644 --- a/http/http_server_jetty/src/main/kotlin/com/hexagonkt/http/server/jetty/JettyServletAdapter.kt +++ b/http/http_server_jetty/src/main/kotlin/com/hexagonkt/http/server/jetty/JettyServletAdapter.kt @@ -113,7 +113,7 @@ class JettyServletAdapter( serverConnector.host = settings.bindAddress.hostName serverConnector.port = settings.bindPort serverConnector.connectionFactories - .filterIsInstance(HttpConnectionFactory::class.java) + .filterIsInstance() .map { it.httpConfiguration } .map { it.sendDateHeader = sendDateHeader diff --git a/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/ErrorsTest.kt b/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/ErrorsTest.kt index 1c17ec4483..0031352128 100644 --- a/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/ErrorsTest.kt +++ b/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/ErrorsTest.kt @@ -2,7 +2,6 @@ package com.hexagonkt.http.test.examples import com.hexagonkt.core.fail import com.hexagonkt.http.client.HttpClientPort -import com.hexagonkt.http.model.NOT_FOUND_404 import com.hexagonkt.http.model.HttpStatus import com.hexagonkt.http.model.Header import com.hexagonkt.http.model.INTERNAL_SERVER_ERROR_500 @@ -32,7 +31,7 @@ abstract class ErrorsTest( * Catching `Exception` handles any unhandled exception, has to be the last executed (first * declared) */ - exception(NOT_FOUND_404) { + exception { internalServerError("Root handler") } diff --git a/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt b/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt index d3960ca0c1..0c80eaeb6d 100644 --- a/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt +++ b/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt @@ -438,7 +438,7 @@ abstract class SamplesTest( val server = serve(serverAdapter()) { // errors - exception(NOT_FOUND_404) { + exception { internalServerError("Root handler") } @@ -464,7 +464,7 @@ abstract class SamplesTest( before(pattern = "*", status = HttpStatus(509)) { send(HttpStatus(599)) } - before(pattern = "*", exception = IllegalStateException::class) { + exception { send(HTTP_VERSION_NOT_SUPPORTED_505, exception?.message ?: "empty") } // exceptions From 6e56a2e9977f1307ae2ab0cc294d07e2a909f6f8 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Tue, 19 Dec 2023 23:03:42 +0100 Subject: [PATCH 7/9] Refactor --- core/src/main/kotlin/com/hexagonkt/core/text/Strings.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/kotlin/com/hexagonkt/core/text/Strings.kt b/core/src/main/kotlin/com/hexagonkt/core/text/Strings.kt index 9cbc279eda..02a36151aa 100644 --- a/core/src/main/kotlin/com/hexagonkt/core/text/Strings.kt +++ b/core/src/main/kotlin/com/hexagonkt/core/text/Strings.kt @@ -4,7 +4,6 @@ import com.hexagonkt.core.urlOf import java.io.ByteArrayInputStream import java.io.File import java.io.InputStream -import java.lang.System.getProperty import java.net.InetAddress import java.net.URI import java.net.URL @@ -23,7 +22,7 @@ private val base64Encoder: Base64.Encoder by lazy { Base64.getEncoder().withoutP private val base64Decoder: Base64.Decoder by lazy { Base64.getDecoder() } /** Runtime specific end of line. */ -val eol: String by lazy { getProperty("line.separator") } +val eol: String by lazy { System.lineSeparator() } /** Supported types for the [parseOrNull] function. */ val parsedClasses: Set> by lazy { From 28257e6f28d866d25ad48b19d83e81dcf2216c0d Mon Sep 17 00:00:00 2001 From: jaguililla Date: Wed, 20 Dec 2023 19:10:12 +0100 Subject: [PATCH 8/9] Update dependencies --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 86a5a6ad65..ec303be845 100644 --- a/gradle.properties +++ b/gradle.properties @@ -46,7 +46,7 @@ nettyVersion=4.1.104.Final nettyTcNativeVersion=2.0.62.Final # http_server_helidon -helidonVersion=4.0.1 +helidonVersion=4.0.2 # http_server_servlet servletVersion=6.0.0 From 4fcb8b9267faeb89b6b79386c6200f32afc68fc2 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Thu, 21 Dec 2023 19:17:10 +0100 Subject: [PATCH 9/9] Update dependencies --- build.gradle.kts | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e5d11fbcac..ae1e46ad15 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL */ plugins { - kotlin("jvm") version("1.9.21") apply(false) + kotlin("jvm") version("1.9.22") apply(false) id("idea") id("eclipse") diff --git a/gradle.properties b/gradle.properties index ec303be845..38884e4db5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,7 +31,7 @@ logoSmall=assets/img/logo.svg iconsDirectory=content # VERSIONS -kotlinVersion=1.9.21 +kotlinVersion=1.9.22 dokkaVersion=1.9.10 mockkVersion=1.13.8 junitVersion=5.10.1