diff --git a/build.gradle.kts b/build.gradle.kts index 8cb8e22..adb3093 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ plugins { val artifactName = "sdk-jvm" val artifactGroup = "io.kuzzle" -val artifactVersion = "1.3.1" +val artifactVersion = "1.3.2" val pomUrl = "https://github.com/kuzzleio/sdk-jvm" val pomScmUrl = "https://github.com/kuzzleio/sdk-jvm" @@ -35,7 +35,7 @@ val pomDeveloperId = "kuzzleio" val pomDeveloperName = "kuzzle" group = "io.kuzzle.sdk" -version = "1.3.1" +version = "1.3.2" val ktorVersion = "1.6.8" repositories { @@ -61,11 +61,11 @@ dependencies { testImplementation("org.jetbrains.kotlin:kotlin-test-junit") testImplementation("io.mockk:mockk:1.8.13") - testImplementation("io.ktor:ktor-client-mock:1.3.1") + testImplementation("io.ktor:ktor-client-mock:1.3.2") testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion") testImplementation("io.ktor:ktor-client-json-jvm:$ktorVersion") - testImplementation("io.ktor:ktor-client-mock-js:1.3.1") - testImplementation("io.ktor:ktor-client-mock-native:1.3.1") + testImplementation("io.ktor:ktor-client-mock-js:1.3.2") + testImplementation("io.ktor:ktor-client-mock-native:1.3.2") testImplementation("org.mock-server:mockserver-netty:5.3.0") testImplementation("io.cucumber:cucumber-java8:7.0.0") testImplementation("io.cucumber:cucumber-junit:7.0.0") diff --git a/doc/1/getting-started/java/index.md b/doc/1/getting-started/java/index.md index d09928e..1a921f9 100644 --- a/doc/1/getting-started/java/index.md +++ b/doc/1/getting-started/java/index.md @@ -61,7 +61,7 @@ To build the project, add the following lines: io.kuzzle sdk-jvm - 1.3.1 + 1.3.2 pom ``` @@ -70,14 +70,14 @@ To build the project, add the following lines: ```groovy dependencies { - compile 'io.kuzzle:sdk-jvm:1.3.1' + compile 'io.kuzzle:sdk-jvm:1.3.2' } ``` ### Ivy ```html - + ``` diff --git a/doc/1/getting-started/kotlin/index.md b/doc/1/getting-started/kotlin/index.md index 7e3f9aa..23da68e 100644 --- a/doc/1/getting-started/kotlin/index.md +++ b/doc/1/getting-started/kotlin/index.md @@ -73,7 +73,7 @@ To build the project, add the following lines: io.kuzzle sdk-jvm - 1.3.1 + 1.3.2 pom ``` @@ -82,14 +82,14 @@ To build the project, add the following lines: ```groovy dependencies { - compile 'io.kuzzle:sdk-jvm:1.3.1' + compile 'io.kuzzle:sdk-jvm:1.3.2' } ``` ### Ivy ```html - + ``` diff --git a/src/main/kotlin/io/kuzzle/sdk/Kuzzle.kt b/src/main/kotlin/io/kuzzle/sdk/Kuzzle.kt index ecd15d7..fb79570 100644 --- a/src/main/kotlin/io/kuzzle/sdk/Kuzzle.kt +++ b/src/main/kotlin/io/kuzzle/sdk/Kuzzle.kt @@ -80,6 +80,10 @@ open class Kuzzle { return } + if (! jsonObject.containsKey("headers") && event.headers != null) { + jsonObject = jsonObject.plus("headers" to event.headers) + } + // If the message is empty, we take the requestId of the event, // to avoid error in fromMap function. if (! jsonObject.containsKey("requestId") && event.requestId != null) { diff --git a/src/main/kotlin/io/kuzzle/sdk/events/MessageReceivedEvent.kt b/src/main/kotlin/io/kuzzle/sdk/events/MessageReceivedEvent.kt index 2aa23c4..3cdb173 100644 --- a/src/main/kotlin/io/kuzzle/sdk/events/MessageReceivedEvent.kt +++ b/src/main/kotlin/io/kuzzle/sdk/events/MessageReceivedEvent.kt @@ -1,3 +1,3 @@ package io.kuzzle.sdk.events -data class MessageReceivedEvent(var message: String?, var requestId: String?) +data class MessageReceivedEvent(var message: String?, var requestId: String? = null, var headers: Map>? = null) diff --git a/src/main/kotlin/io/kuzzle/sdk/protocol/Http.kt b/src/main/kotlin/io/kuzzle/sdk/protocol/Http.kt index e4156b7..2bc4ffb 100644 --- a/src/main/kotlin/io/kuzzle/sdk/protocol/Http.kt +++ b/src/main/kotlin/io/kuzzle/sdk/protocol/Http.kt @@ -5,6 +5,7 @@ import io.ktor.client.call.* import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* +import io.ktor.util.* import io.kuzzle.sdk.coreClasses.exceptions.* import io.kuzzle.sdk.coreClasses.http.Route import io.kuzzle.sdk.coreClasses.json.JsonSerializer @@ -222,7 +223,7 @@ open class Http : AbstractProtocol { this.body = JsonSerializer.serialize(payload) } // trigger messageReceived - super.trigger(MessageReceivedEvent(response.receive(), payload["requestId"] as String?)) + super.trigger(MessageReceivedEvent(response.receive(), payload["requestId"] as String?, response.headers.toMap())) } catch (e: Exception) { super.trigger(RequestErrorEvent(e, payload["requestId"] as String?)) } finally { @@ -253,7 +254,7 @@ open class Http : AbstractProtocol { this.body = if (requestInfo.body != null) JsonSerializer.serialize(requestInfo.body) else "" } // trigger messageReceived - super.trigger(MessageReceivedEvent(response.receive(), payload["requestId"] as String?)) + super.trigger(MessageReceivedEvent(response.receive(), payload["requestId"] as String?, response.headers.toMap())) } catch (e: Exception) { super.trigger(RequestErrorEvent(e, payload["requestId"] as String?)) } finally { @@ -303,20 +304,19 @@ open class Http : AbstractProtocol { val route = this.routes["$controller:$action"] - if (route == null) { - super.trigger(RequestErrorEvent(URLNotFoundException(controller, action), payload["requestId"] as String?)) - return - } - - try { - val requestInfo = route.buildRequest(KuzzleMap.from(payload)) - queryHTTPEndpoint(payload, requestInfo) - } catch (e: MissingURLParamException) { - /** - * Fallback if we could not find a matching route with the given parameters - * Try to make the request using directly using /_query endpoint - */ - query(payload) + if (route != null) { + try { + val requestInfo = route.buildRequest(KuzzleMap.from(payload)) + queryHTTPEndpoint(payload, requestInfo) + return + } catch (e: MissingURLParamException) { + // Fallback to query + } } + /** + * Fallback if we could not find a matching route with the given parameters + * Try to make the request using directly using /_query endpoint + */ + query(payload) } } diff --git a/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt b/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt index 3b543fc..ca82baa 100644 --- a/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt +++ b/src/main/kotlin/io/kuzzle/sdk/protocol/WebSocket.kt @@ -130,9 +130,9 @@ open class WebSocket : AbstractProtocol { for (frame in incoming) { when (frame) { // @TODO Create enums for events - is Frame.Text -> super.trigger(MessageReceivedEvent(frame.readText(), null)) + is Frame.Text -> super.trigger(MessageReceivedEvent(frame.readText())) // @TODO Create enums for events - is Frame.Binary -> super.trigger(MessageReceivedEvent(frame.readBytes().toString(), null)) + is Frame.Binary -> super.trigger(MessageReceivedEvent(frame.readBytes().toString())) is Frame.Close -> TODO() is Frame.Ping -> TODO() is Frame.Pong -> TODO()