Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/serverless #657

Merged
merged 10 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ apiValidation {
// Experimental modules
"rest",
"rest_tools",
// "serverless",
"web",
)
)
Expand Down
6 changes: 5 additions & 1 deletion handlers/src/main/kotlin/com/hexagonkt/handlers/OnHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ data class OnHandler<T : Any>(

override fun process(context: Context<T>): Context<T> =
try {
callback(context).with(handled = true).next()
val callbackContext = callback(context)
if (callbackContext.handled)
callbackContext.next()
else
callbackContext.with(handled = true).next()
}
catch (e: Exception) {
context.with(exception = e).next()
Expand Down
50 changes: 26 additions & 24 deletions http/http_client/api/http_client.api
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ public final class com/hexagonkt/http/client/HttpClient : java/io/Closeable {
public synthetic fun <init> (Lcom/hexagonkt/http/client/HttpClientPort;Lcom/hexagonkt/http/client/HttpClientSettings;Lcom/hexagonkt/http/handlers/HttpHandler;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public final fun cookiesMap ()Ljava/util/Map;
public final fun delete (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun delete$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun get (Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun get$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun delete (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun delete$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun get (Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun get$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun getCookies ()Ljava/util/List;
public final fun getHandler ()Lcom/hexagonkt/http/handlers/HttpHandler;
public final fun getSettings ()Lcom/hexagonkt/http/client/HttpClientSettings;
public final fun head (Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun head$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Lcom/hexagonkt/http/model/Headers;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun options (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun options$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun patch (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun patch$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun post (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun post$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun put (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun put$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun options (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun options$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun patch (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun patch$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun post (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun post$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun put (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun put$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun request (Lkotlin/jvm/functions/Function1;)V
public final fun send (Lcom/hexagonkt/http/model/HttpRequest;Ljava/util/Map;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun send$default (Lcom/hexagonkt/http/client/HttpClient;Lcom/hexagonkt/http/model/HttpRequest;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
Expand All @@ -29,8 +29,8 @@ public final class com/hexagonkt/http/client/HttpClient : java/io/Closeable {
public final fun start ()V
public final fun started ()Z
public final fun stop ()V
public final fun trace (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun trace$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun trace (Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;)Lcom/hexagonkt/http/model/HttpResponsePort;
public static synthetic fun trace$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Ljava/lang/Object;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ILjava/lang/Object;)Lcom/hexagonkt/http/model/HttpResponsePort;
public final fun ws (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Lcom/hexagonkt/http/model/ws/WsSession;
public static synthetic fun ws$default (Lcom/hexagonkt/http/client/HttpClient;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)Lcom/hexagonkt/http/model/ws/WsSession;
}
Expand All @@ -50,19 +50,21 @@ public final class com/hexagonkt/http/client/HttpClientPort$DefaultImpls {

public final class com/hexagonkt/http/client/HttpClientSettings {
public fun <init> ()V
public fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;Z)V
public synthetic fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;Z)V
public synthetic fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/net/URL;
public final fun component2 ()Lcom/hexagonkt/http/model/ContentType;
public final fun component3 ()Z
public final fun component4 ()Lcom/hexagonkt/http/model/Headers;
public final fun component5 ()Z
public final fun component6 ()Lcom/hexagonkt/http/SslSettings;
public final fun component7 ()Lcom/hexagonkt/http/model/Authorization;
public final fun component8 ()Z
public final fun copy (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;Z)Lcom/hexagonkt/http/client/HttpClientSettings;
public static synthetic fun copy$default (Lcom/hexagonkt/http/client/HttpClientSettings;Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ZILjava/lang/Object;)Lcom/hexagonkt/http/client/HttpClientSettings;
public final fun component3 ()Ljava/util/List;
public final fun component4 ()Z
public final fun component5 ()Lcom/hexagonkt/http/model/Headers;
public final fun component6 ()Z
public final fun component7 ()Lcom/hexagonkt/http/SslSettings;
public final fun component8 ()Lcom/hexagonkt/http/model/Authorization;
public final fun component9 ()Z
public final fun copy (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;Z)Lcom/hexagonkt/http/client/HttpClientSettings;
public static synthetic fun copy$default (Lcom/hexagonkt/http/client/HttpClientSettings;Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ZILjava/lang/Object;)Lcom/hexagonkt/http/client/HttpClientSettings;
public fun equals (Ljava/lang/Object;)Z
public final fun getAccept ()Ljava/util/List;
public final fun getAuthorization ()Lcom/hexagonkt/http/model/Authorization;
public final fun getBaseUrl ()Ljava/net/URL;
public final fun getContentType ()Lcom/hexagonkt/http/model/ContentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ class HttpClient(
path: String = "",
headers: Headers = Headers(),
body: Any? = null,
contentType: ContentType? = settings.contentType): HttpResponsePort =
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(
HttpRequest(
method = GET,
path = path,
body = body ?: "",
headers = headers,
contentType = contentType)
contentType = contentType,
accept = accept,
)
)

fun head(path: String = "", headers: Headers = Headers()): HttpResponsePort =
Expand All @@ -110,53 +114,100 @@ class HttpClient(
fun post(
path: String = "",
body: Any? = null,
contentType: ContentType? = settings.contentType
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(HttpRequest(POST, path = path, body = body ?: "", contentType = contentType))
send(
HttpRequest(
method = POST,
path = path,
body = body ?: "",
contentType = contentType,
accept = accept,
)
)

fun put(
path: String = "",
body: Any? = null,
contentType: ContentType? = settings.contentType
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(HttpRequest(PUT, path = path, body = body ?: "", contentType = contentType))
send(
HttpRequest(
method = PUT,
path = path,
body = body ?: "",
contentType = contentType,
accept = accept,
)
)

fun delete(
path: String = "",
body: Any? = null,
contentType: ContentType? = settings.contentType
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(HttpRequest(DELETE, path = path, body = body ?: "", contentType = contentType))
send(
HttpRequest(
method = DELETE,
path = path,
body = body ?: "",
contentType = contentType,
accept = accept,
)
)

fun trace(
path: String = "",
body: Any? = null,
contentType: ContentType? = settings.contentType
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(HttpRequest(TRACE, path = path, body = body ?: "", contentType = contentType))
send(
HttpRequest(
method = TRACE,
path = path,
body = body ?: "",
contentType = contentType,
accept = accept,
)
)

fun options(
path: String = "",
body: Any? = null,
headers: Headers = Headers(),
contentType: ContentType? = settings.contentType
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(
HttpRequest(
method = OPTIONS,
path = path,
body = body ?: "",
headers = headers,
contentType = contentType
contentType = contentType,
accept = accept,
)
)

fun patch(
path: String = "",
body: Any? = null,
contentType: ContentType? = settings.contentType
contentType: ContentType? = settings.contentType,
accept: List<ContentType> = settings.accept,
): HttpResponsePort =
send(HttpRequest(PATCH, path = path, body = body ?: "", contentType = contentType))
send(
HttpRequest(
method = PATCH,
path = path,
body = body ?: "",
contentType = contentType,
accept = accept,
)
)

private fun HttpHandler.process(
request: HttpRequestPort, attributes: Map<String, Any>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.net.URL
data class HttpClientSettings(
val baseUrl: URL? = null,
val contentType: ContentType? = null,
val accept: List<ContentType> = emptyList(),
val useCookies: Boolean = true,
val headers: Headers = Headers(),
val insecure: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class HttpClientSettingsTest {
HttpClientSettings().let {
assertNull(it.baseUrl)
assertNull(it.contentType)
assertEquals(emptyList(), it.accept)
assertTrue(it.useCookies)
assertEquals(Headers(), it.headers)
assertFalse(it.insecure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ open class JettyClientAdapter : HttpClientPort {

val settings = adapterHttpClient.settings
val contentType = request.contentType ?: settings.contentType
val accept = request.accept.ifEmpty(settings::accept)
val authorization = request.authorization ?: settings.authorization
val baseUrl = settings.baseUrl

Expand All @@ -193,7 +194,7 @@ open class JettyClientAdapter : HttpClientPort {
.forEach { (k, v) -> it.put(k, v.map(Any::toString)) }
}
.body(createBody(request))
.accept(*request.accept.map { it.text }.toTypedArray())
.accept(*accept.map { it.text }.toTypedArray())

request.queryParameters
.forEach { (k, v) -> v.strings().forEach { jettyRequest.param(k, it) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ data class HttpPredicate(
val status: HttpStatus? = null,
) : (Context<HttpCall>) -> Boolean {

private val logger: Logger = Logger(HttpPredicate::class)
private companion object {
val logger: Logger = Logger(HttpPredicate::class)
}

private fun PathPattern.isEmpty(): Boolean =
pattern.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ data class PathHandler(
)
{

private val logger: Logger = Logger(PathHandler::class)

private companion object {
val logger: Logger = Logger(PathHandler::class)
fun nestedMethods(handlers: List<HttpHandler>): Set<HttpMethod> =
handlers
.flatMap { it.handlerPredicate.methods.ifEmpty { ALL } }
Expand Down
2 changes: 2 additions & 0 deletions http/http_server/api/http_server.api
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public final class com/hexagonkt/http/server/HttpServer : java/io/Closeable {
public final fun copy (Lcom/hexagonkt/http/server/HttpServerPort;Lcom/hexagonkt/http/handlers/HttpHandler;Lcom/hexagonkt/http/server/HttpServerSettings;)Lcom/hexagonkt/http/server/HttpServer;
public static synthetic fun copy$default (Lcom/hexagonkt/http/server/HttpServer;Lcom/hexagonkt/http/server/HttpServerPort;Lcom/hexagonkt/http/handlers/HttpHandler;Lcom/hexagonkt/http/server/HttpServerSettings;ILjava/lang/Object;)Lcom/hexagonkt/http/server/HttpServer;
public fun equals (Ljava/lang/Object;)Z
public final fun getBinding ()Ljava/net/URL;
public final fun getHandler ()Lcom/hexagonkt/http/handlers/HttpHandler;
public final fun getPortName ()Ljava/lang/String;
public final fun getRuntimePort ()I
Expand All @@ -23,6 +24,7 @@ public final class com/hexagonkt/http/server/HttpServer : java/io/Closeable {

public final class com/hexagonkt/http/server/HttpServer$Companion {
public final fun getBanner ()Ljava/lang/String;
public final fun getLogger ()Lcom/hexagonkt/core/logging/Logger;
}

public final class com/hexagonkt/http/server/HttpServerFeature : java/lang/Enum {
Expand Down
Loading