From 3231f9da257830005d7f269501e5586f578aa1e0 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Sun, 14 Apr 2024 22:50:04 +0300 Subject: [PATCH] Rename modules to match `ktor` plugins and migrate them to new ktor API --- .../api/ktor-client-rsocket.api | 18 +---- .../ktor-client-rsocket}/build.gradle.kts | 3 +- .../io/rsocket/kotlin/ktor/client/Builders.kt | 19 +---- .../kotlin/ktor/client/RSocketSupport.kt | 74 +++++++++++++++++++ .../api/ktor-server-rsocket.api | 16 ++++ .../ktor-server-rsocket}/build.gradle.kts | 7 +- .../kotlin/ktor/server/RSocketSupport.kt | 61 +++++++++++++++ .../io/rsocket/kotlin/ktor/server/Routing.kt | 29 ++++++++ .../server/WebSocketConnectionTest.kt | 14 ++-- .../api/rsocket-ktor-client.api | 0 .../rsocket-ktor-client}/build.gradle.kts | 6 +- .../src/commonMain/kotlin/dummy.kt | 19 +++++ .../api/rsocket-ktor-server.api | 0 .../rsocket-ktor-server/build.gradle.kts | 34 +++++++++ .../src/commonMain/kotlin/dummy.kt | 19 +++++ .../kotlin/ktor/client/RSocketSupport.kt | 48 ------------ .../api/rsocket-ktor-server.api | 22 ------ .../kotlin/ktor/server/RSocketSupport.kt | 46 ------------ .../io/rsocket/kotlin/ktor/server/Routing.kt | 51 ------------- .../kotlin/io/rsocket/kotlin/ktor/dummy.kt | 3 - settings.gradle.kts | 7 +- 21 files changed, 278 insertions(+), 218 deletions(-) rename rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api => ktor-plugins/ktor-client-rsocket/api/ktor-client-rsocket.api (51%) rename {rsocket-ktor/rsocket-ktor-client => ktor-plugins/ktor-client-rsocket}/build.gradle.kts (89%) rename {rsocket-ktor/rsocket-ktor-client => ktor-plugins/ktor-client-rsocket}/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt (70%) create mode 100644 ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt create mode 100644 ktor-plugins/ktor-server-rsocket/api/ktor-server-rsocket.api rename {rsocket-ktor/rsocket-ktor-server => ktor-plugins/ktor-server-rsocket}/build.gradle.kts (82%) create mode 100644 ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt create mode 100644 ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt rename {rsocket-ktor/rsocket-ktor-server => ktor-plugins/ktor-server-rsocket}/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt (91%) rename rsocket-ktor/api/rsocket-ktor.api => ktor-plugins/rsocket-ktor-client/api/rsocket-ktor-client.api (100%) rename {rsocket-ktor => ktor-plugins/rsocket-ktor-client}/build.gradle.kts (80%) create mode 100644 ktor-plugins/rsocket-ktor-client/src/commonMain/kotlin/dummy.kt create mode 100644 ktor-plugins/rsocket-ktor-server/api/rsocket-ktor-server.api create mode 100644 ktor-plugins/rsocket-ktor-server/build.gradle.kts create mode 100644 ktor-plugins/rsocket-ktor-server/src/commonMain/kotlin/dummy.kt delete mode 100644 rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt delete mode 100644 rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api delete mode 100644 rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt delete mode 100644 rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt delete mode 100644 rsocket-ktor/src/commonMain/kotlin/io/rsocket/kotlin/ktor/dummy.kt diff --git a/rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api b/ktor-plugins/ktor-client-rsocket/api/ktor-client-rsocket.api similarity index 51% rename from rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api rename to ktor-plugins/ktor-client-rsocket/api/ktor-client-rsocket.api index 3209d534c..a4271f8c8 100644 --- a/rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api +++ b/ktor-plugins/ktor-client-rsocket/api/ktor-client-rsocket.api @@ -6,22 +6,12 @@ public final class io/rsocket/kotlin/ktor/client/BuildersKt { public static synthetic fun rSocket$default (Lio/ktor/client/HttpClient;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } -public final class io/rsocket/kotlin/ktor/client/RSocketSupport { - public static final field Plugin Lio/rsocket/kotlin/ktor/client/RSocketSupport$Plugin; - public synthetic fun (Lio/rsocket/kotlin/core/RSocketConnector;Lkotlin/jvm/internal/DefaultConstructorMarker;)V -} - -public final class io/rsocket/kotlin/ktor/client/RSocketSupport$Config { +public final class io/rsocket/kotlin/ktor/client/RSocketSupportConfig { + public final fun connector (Lio/rsocket/kotlin/core/RSocketConnector;)V public final fun connector (Lkotlin/jvm/functions/Function1;)V - public final fun getConnector ()Lio/rsocket/kotlin/core/RSocketConnector; - public final fun setConnector (Lio/rsocket/kotlin/core/RSocketConnector;)V } -public final class io/rsocket/kotlin/ktor/client/RSocketSupport$Plugin : io/ktor/client/plugins/HttpClientPlugin { - public fun getKey ()Lio/ktor/util/AttributeKey; - public fun install (Lio/rsocket/kotlin/ktor/client/RSocketSupport;Lio/ktor/client/HttpClient;)V - public synthetic fun install (Ljava/lang/Object;Lio/ktor/client/HttpClient;)V - public fun prepare (Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/ktor/client/RSocketSupport; - public synthetic fun prepare (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; +public final class io/rsocket/kotlin/ktor/client/RSocketSupportKt { + public static final fun getRSocketSupport ()Lio/ktor/client/plugins/api/ClientPlugin; } diff --git a/rsocket-ktor/rsocket-ktor-client/build.gradle.kts b/ktor-plugins/ktor-client-rsocket/build.gradle.kts similarity index 89% rename from rsocket-ktor/rsocket-ktor-client/build.gradle.kts rename to ktor-plugins/ktor-client-rsocket/build.gradle.kts index df4db279f..9d9b43f8e 100644 --- a/rsocket-ktor/rsocket-ktor-client/build.gradle.kts +++ b/ktor-plugins/ktor-client-rsocket/build.gradle.kts @@ -29,7 +29,8 @@ kotlin { sourceSets { commonMain.dependencies { - api(projects.rsocketKtor) + implementation(projects.rsocketTransportKtorWebsocketInternal) + api(projects.rsocketCore) api(libs.ktor.client.websockets) } } diff --git a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt b/ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt similarity index 70% rename from rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt rename to ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt index 5b8f6778b..85d000701 100644 --- a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt +++ b/ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt @@ -17,20 +17,13 @@ package io.rsocket.kotlin.ktor.client import io.ktor.client.* -import io.ktor.client.plugins.* -import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* import io.ktor.http.* import io.rsocket.kotlin.* -import io.rsocket.kotlin.transport.* -import io.rsocket.kotlin.transport.ktor.websocket.internal.* -import kotlin.coroutines.* public suspend fun HttpClient.rSocket( request: HttpRequestBuilder.() -> Unit, -): RSocket = plugin(RSocketSupport).run { - connector.connect(KtorClientTransport(this@rSocket, request)) -} +): RSocket = connectRSocket(request) public suspend fun HttpClient.rSocket( urlString: String, @@ -59,13 +52,3 @@ public suspend fun HttpClient.rSocket( } request() } - -private class KtorClientTransport( - private val client: HttpClient, - private val request: HttpRequestBuilder.() -> Unit, -) : ClientTransport { - override val coroutineContext: CoroutineContext get() = client.coroutineContext - - @TransportApi - override suspend fun connect(): Connection = WebSocketConnection(client.webSocketSession(request)) -} diff --git a/ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt b/ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt new file mode 100644 index 000000000..f81e8bca1 --- /dev/null +++ b/ktor-plugins/ktor-client-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.ktor.client + +import io.ktor.client.* +import io.ktor.client.plugins.* +import io.ktor.client.plugins.api.* +import io.ktor.client.plugins.websocket.* +import io.ktor.client.request.* +import io.ktor.util.* +import io.rsocket.kotlin.* +import io.rsocket.kotlin.core.* +import io.rsocket.kotlin.transport.* +import io.rsocket.kotlin.transport.ktor.websocket.internal.* +import kotlinx.coroutines.* +import kotlin.coroutines.* + +private val RSocketSupportConfigKey = AttributeKey("RSocketSupportConfig") + +public val RSocketSupport: ClientPlugin = createClientPlugin("RSocketSupport", ::RSocketSupportConfig) { + client.pluginOrNull(WebSockets) ?: error("RSocket require WebSockets to work. You must install WebSockets plugin first.") + client.attributes.put(RSocketSupportConfigKey, pluginConfig.toInternal()) +} + +public class RSocketSupportConfig internal constructor() { + private var connector = RSocketConnector() + + public fun connector(connector: RSocketConnector) { + this.connector = connector + } + + public fun connector(block: RSocketConnectorBuilder.() -> Unit) { + this.connector = RSocketConnector(block) + } + + internal fun toInternal(): Internal = Internal(connector) + internal class Internal(val connector: RSocketConnector) +} + +internal suspend fun HttpClient.connectRSocket(request: HttpRequestBuilder.() -> Unit): RSocket { + val config = attributes.getOrNull(RSocketSupportConfigKey) + ?: error("Plugin `RSocketSupport` is not installed. Consider using `install(RSocketSupport)` in client config first.") + + return config.connector.connect(RSocketSupportTarget(this, request)) +} + +@OptIn(RSocketTransportApi::class) +private class RSocketSupportTarget( + private val client: HttpClient, + private val request: HttpRequestBuilder.() -> Unit, +) : RSocketClientTarget { + override val coroutineContext: CoroutineContext get() = client.coroutineContext + + @RSocketTransportApi + override fun connectClient(handler: RSocketConnectionHandler): Job = launch { + client.webSocket(request) { + handler.handleKtorWebSocketConnection(this) + } + } +} diff --git a/ktor-plugins/ktor-server-rsocket/api/ktor-server-rsocket.api b/ktor-plugins/ktor-server-rsocket/api/ktor-server-rsocket.api new file mode 100644 index 000000000..fb6ff7ec8 --- /dev/null +++ b/ktor-plugins/ktor-server-rsocket/api/ktor-server-rsocket.api @@ -0,0 +1,16 @@ +public final class io/rsocket/kotlin/ktor/server/RSocketSupportConfig { + public final fun server (Lio/rsocket/kotlin/core/RSocketServer;)V + public final fun server (Lkotlin/jvm/functions/Function1;)V +} + +public final class io/rsocket/kotlin/ktor/server/RSocketSupportKt { + public static final fun getRSocketSupport ()Lio/ktor/server/application/ApplicationPlugin; +} + +public final class io/rsocket/kotlin/ktor/server/RoutingKt { + public static final fun rSocket (Lio/ktor/server/routing/Route;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;)V + public static final fun rSocket (Lio/ktor/server/routing/Route;Ljava/lang/String;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;)V + public static synthetic fun rSocket$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;ILjava/lang/Object;)V + public static synthetic fun rSocket$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;ILjava/lang/Object;)V +} + diff --git a/rsocket-ktor/rsocket-ktor-server/build.gradle.kts b/ktor-plugins/ktor-server-rsocket/build.gradle.kts similarity index 82% rename from rsocket-ktor/rsocket-ktor-server/build.gradle.kts rename to ktor-plugins/ktor-server-rsocket/build.gradle.kts index 32a1f6a84..7ebb510e9 100644 --- a/rsocket-ktor/rsocket-ktor-server/build.gradle.kts +++ b/ktor-plugins/ktor-server-rsocket/build.gradle.kts @@ -28,12 +28,13 @@ kotlin { sourceSets { commonMain.dependencies { - api(projects.rsocketKtor) + implementation(projects.rsocketTransportKtorWebsocketInternal) + api(projects.rsocketCore) api(libs.ktor.server.websockets) } commonTest.dependencies { - implementation(projects.rsocketKtorClient) - implementation(projects.rsocketTransportTests) //port provider + implementation(projects.ktorClientRsocket) + implementation(projects.rsocketTest) implementation(libs.ktor.client.cio) implementation(libs.ktor.server.cio) } diff --git a/ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt b/ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt new file mode 100644 index 000000000..5346e7da0 --- /dev/null +++ b/ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt @@ -0,0 +1,61 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.ktor.server + +import io.ktor.server.application.* +import io.ktor.server.routing.* +import io.ktor.server.websocket.* +import io.ktor.util.* +import io.rsocket.kotlin.* +import io.rsocket.kotlin.core.* +import io.rsocket.kotlin.transport.* +import io.rsocket.kotlin.transport.ktor.websocket.internal.* + +private val RSocketSupportConfigKey = AttributeKey("RSocketSupportConfig") + +public val RSocketSupport: ApplicationPlugin = createApplicationPlugin("RSocketSupport", ::RSocketSupportConfig) { + application.pluginOrNull(WebSockets) ?: error("RSocket require WebSockets to work. You must install WebSockets plugin first.") + application.attributes.put(RSocketSupportConfigKey, pluginConfig.toInternal()) +} + +public class RSocketSupportConfig internal constructor() { + private var server: RSocketServer = RSocketServer() + + public fun server(server: RSocketServer) { + this.server = server + } + + public fun server(block: RSocketServerBuilder.() -> Unit) { + server = RSocketServer(block) + } + + + internal fun toInternal(): Internal = Internal(server) + internal class Internal(val server: RSocketServer) +} + + +@OptIn(RSocketTransportApi::class) +internal fun Route.rSocketHandler(acceptor: ConnectionAcceptor): suspend DefaultWebSocketServerSession.() -> Unit { + val config = application.attributes.getOrNull(RSocketSupportConfigKey) + ?: error("Plugin RSocketSupport is not installed. Consider using `install(RSocketSupport)` in server config first.") + + val handler = config.server.createHandler(acceptor) + return { + handler.handleKtorWebSocketConnection(this) + } +} diff --git a/ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt b/ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt new file mode 100644 index 000000000..3d9e9c783 --- /dev/null +++ b/ktor-plugins/ktor-server-rsocket/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.ktor.server + +import io.ktor.server.routing.* +import io.ktor.server.websocket.* +import io.rsocket.kotlin.* + +public fun Route.rSocket(protocol: String? = null, acceptor: ConnectionAcceptor) { + webSocket(protocol, rSocketHandler(acceptor)) +} + +public fun Route.rSocket(path: String, protocol: String? = null, acceptor: ConnectionAcceptor) { + webSocket(path, protocol, rSocketHandler(acceptor)) +} diff --git a/rsocket-ktor/rsocket-ktor-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt b/ktor-plugins/ktor-server-rsocket/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt similarity index 91% rename from rsocket-ktor/rsocket-ktor-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt rename to ktor-plugins/ktor-server-rsocket/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt index 4f9a8b75e..0b5a981ef 100644 --- a/rsocket-ktor/rsocket-ktor-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt +++ b/ktor-plugins/ktor-server-rsocket/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketConnectionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,11 +40,13 @@ class WebSocketConnectionTest : SuspendTest, TestWithLeakCheck { private val client = HttpClient(ClientCIO) { install(ClientWebSockets) install(ClientRSocketSupport) { - connector = TestConnector { - connectionConfig { - keepAlive = KeepAlive(500) + connector( + TestConnector { + connectionConfig { + keepAlive = KeepAlive(500) + } } - } + ) } } @@ -53,7 +55,7 @@ class WebSocketConnectionTest : SuspendTest, TestWithLeakCheck { private val server = embeddedServer(ServerCIO, port = 0) { install(ServerWebSockets) install(ServerRSocketSupport) { - server = TestServer() + server(TestServer()) } install(Routing) { rSocket { diff --git a/rsocket-ktor/api/rsocket-ktor.api b/ktor-plugins/rsocket-ktor-client/api/rsocket-ktor-client.api similarity index 100% rename from rsocket-ktor/api/rsocket-ktor.api rename to ktor-plugins/rsocket-ktor-client/api/rsocket-ktor-client.api diff --git a/rsocket-ktor/build.gradle.kts b/ktor-plugins/rsocket-ktor-client/build.gradle.kts similarity index 80% rename from rsocket-ktor/build.gradle.kts rename to ktor-plugins/rsocket-ktor-client/build.gradle.kts index fce83a060..3312f542f 100644 --- a/rsocket-ktor/build.gradle.kts +++ b/ktor-plugins/rsocket-ktor-client/build.gradle.kts @@ -20,7 +20,7 @@ plugins { id("rsocketbuild.multiplatform-library") } -description = "rsocket-kotlin ktor integration" +description = "OLD ARTIFACT - migrate to ktor-client-rsocket" kotlin { jvmTarget() @@ -29,9 +29,7 @@ kotlin { sourceSets { commonMain.dependencies { - api(projects.rsocketCore) - api(projects.rsocketTransportKtorWebsocketInternal) - //TODO ContentNegotiation will be here later + implementation(projects.ktorClientRsocket) } } } diff --git a/ktor-plugins/rsocket-ktor-client/src/commonMain/kotlin/dummy.kt b/ktor-plugins/rsocket-ktor-client/src/commonMain/kotlin/dummy.kt new file mode 100644 index 000000000..1a5ede95d --- /dev/null +++ b/ktor-plugins/rsocket-ktor-client/src/commonMain/kotlin/dummy.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.deprecated + +private val dummy = 0 diff --git a/ktor-plugins/rsocket-ktor-server/api/rsocket-ktor-server.api b/ktor-plugins/rsocket-ktor-server/api/rsocket-ktor-server.api new file mode 100644 index 000000000..e69de29bb diff --git a/ktor-plugins/rsocket-ktor-server/build.gradle.kts b/ktor-plugins/rsocket-ktor-server/build.gradle.kts new file mode 100644 index 000000000..a7aeeba4d --- /dev/null +++ b/ktor-plugins/rsocket-ktor-server/build.gradle.kts @@ -0,0 +1,34 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import rsocketbuild.* + +plugins { + id("rsocketbuild.multiplatform-library") +} + +description = "OLD ARTIFACT - migrate to ktor-server-rsocket" + +kotlin { + jvmTarget() + nixTargets() + + sourceSets { + commonMain.dependencies { + implementation(projects.ktorServerRsocket) + } + } +} diff --git a/ktor-plugins/rsocket-ktor-server/src/commonMain/kotlin/dummy.kt b/ktor-plugins/rsocket-ktor-server/src/commonMain/kotlin/dummy.kt new file mode 100644 index 000000000..1a5ede95d --- /dev/null +++ b/ktor-plugins/rsocket-ktor-server/src/commonMain/kotlin/dummy.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.rsocket.kotlin.deprecated + +private val dummy = 0 diff --git a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt b/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt deleted file mode 100644 index 02d90584f..000000000 --- a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.kotlin.ktor.client - -import io.ktor.client.* -import io.ktor.client.plugins.* -import io.ktor.client.plugins.websocket.* -import io.ktor.util.* -import io.rsocket.kotlin.core.* - -public class RSocketSupport private constructor( - internal val connector: RSocketConnector, -) { - - public class Config internal constructor() { - public var connector: RSocketConnector = RSocketConnector() - public fun connector(block: RSocketConnectorBuilder.() -> Unit) { - connector = RSocketConnector(block) - } - } - - public companion object Plugin : HttpClientPlugin { - override val key: AttributeKey = AttributeKey("RSocket") - override fun prepare(block: Config.() -> Unit): RSocketSupport = Config().run { - block() - RSocketSupport(connector) - } - - override fun install(plugin: RSocketSupport, scope: HttpClient) { - scope.pluginOrNull(WebSockets) - ?: error("RSocket require WebSockets to work. You must install WebSockets plugin first.") - } - } -} diff --git a/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api b/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api deleted file mode 100644 index 101de2983..000000000 --- a/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api +++ /dev/null @@ -1,22 +0,0 @@ -public final class io/rsocket/kotlin/ktor/server/RSocketSupport { - public static final field Feature Lio/rsocket/kotlin/ktor/server/RSocketSupport$Feature; - public synthetic fun (Lio/rsocket/kotlin/core/RSocketServer;Lkotlin/jvm/internal/DefaultConstructorMarker;)V -} - -public final class io/rsocket/kotlin/ktor/server/RSocketSupport$Config { - public final fun getServer ()Lio/rsocket/kotlin/core/RSocketServer; - public final fun server (Lkotlin/jvm/functions/Function1;)V - public final fun setServer (Lio/rsocket/kotlin/core/RSocketServer;)V -} - -public final class io/rsocket/kotlin/ktor/server/RSocketSupport$Feature : io/ktor/server/application/BaseApplicationPlugin { - public fun getKey ()Lio/ktor/util/AttributeKey; - public fun install (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/ktor/server/RSocketSupport; - public synthetic fun install (Lio/ktor/util/pipeline/Pipeline;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; -} - -public final class io/rsocket/kotlin/ktor/server/RoutingKt { - public static final fun rSocket (Lio/ktor/server/routing/Route;Ljava/lang/String;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;)V - public static synthetic fun rSocket$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Ljava/lang/String;Lio/rsocket/kotlin/ConnectionAcceptor;ILjava/lang/Object;)V -} - diff --git a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt b/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt deleted file mode 100644 index d7373750e..000000000 --- a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2015-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.kotlin.ktor.server - -import io.ktor.server.application.* -import io.ktor.server.websocket.* -import io.ktor.util.* -import io.rsocket.kotlin.core.* - -public class RSocketSupport private constructor( - internal val server: RSocketServer, -) { - public class Config internal constructor() { - public var server: RSocketServer = RSocketServer() - public fun server(block: RSocketServerBuilder.() -> Unit) { - server = RSocketServer(block) - } - } - - public companion object Feature : BaseApplicationPlugin { - override val key: AttributeKey = AttributeKey("RSocket") - override fun install(pipeline: Application, configure: Config.() -> Unit): RSocketSupport { - pipeline.pluginOrNull(WebSockets) - ?: error("RSocket require WebSockets to work. You must install WebSockets plugin first.") - - return Config().run { - configure() - RSocketSupport(server) - } - } - } -} diff --git a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt b/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt deleted file mode 100644 index 7cdd09831..000000000 --- a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.rsocket.kotlin.ktor.server - -import io.ktor.server.application.* -import io.ktor.server.routing.* -import io.ktor.server.websocket.* -import io.rsocket.kotlin.* -import io.rsocket.kotlin.transport.* -import io.rsocket.kotlin.transport.ktor.websocket.internal.* -import kotlinx.coroutines.* - -public fun Route.rSocket( - path: String? = null, - protocol: String? = null, - acceptor: ConnectionAcceptor, -): Unit = application.plugin(RSocketSupport).run { - server.bindIn(application, KtorServerTransport(this@rSocket, path, protocol), acceptor) -} - -private class KtorServerTransport( - private val route: Route, - private val path: String?, - private val protocol: String?, -) : ServerTransport { - @TransportApi - override fun CoroutineScope.start(accept: suspend CoroutineScope.(Connection) -> Unit) { - val handler: suspend DefaultWebSocketServerSession.() -> Unit = { - val connection = WebSocketConnection(this) - accept(connection) - } - when (path) { - null -> route.webSocket(protocol, handler) - else -> route.webSocket(path, protocol, handler) - } - } -} diff --git a/rsocket-ktor/src/commonMain/kotlin/io/rsocket/kotlin/ktor/dummy.kt b/rsocket-ktor/src/commonMain/kotlin/io/rsocket/kotlin/ktor/dummy.kt deleted file mode 100644 index df46d5bd2..000000000 --- a/rsocket-ktor/src/commonMain/kotlin/io/rsocket/kotlin/ktor/dummy.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.rsocket.kotlin.ktor - -private val dummy: Int = 0 diff --git a/settings.gradle.kts b/settings.gradle.kts index 7699bca3f..e278615f8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -48,8 +48,11 @@ projects("rsocket-kotlin") { module("netty-quic") } - //deep ktor integration module - module("rsocket-ktor", prefix = null) { + // ktor integration plugins + folder("ktor-plugins", null) { + module("ktor-client-rsocket") + module("ktor-server-rsocket") + // for migration from old names module("rsocket-ktor-client") module("rsocket-ktor-server") }