From aead3c4b5c25e5c749af7275246a8357e9ba0f8e Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 Jan 2024 15:46:00 +0100 Subject: [PATCH 1/3] fix(timeout): request timeput don't seem to be appliaed, using HttpTiemout module instead, adding socket and connect timeout. --- .../zeldigas/confclient/ConfluenceClientConfig.kt | 4 +++- .../zeldigas/confclient/ConfluenceClientImpl.kt | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt b/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt index 66c50d02..4e6d1243 100644 --- a/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt +++ b/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt @@ -11,5 +11,7 @@ data class ConfluenceClientConfig( val skipSsl: Boolean, val auth: ConfluenceAuth, val httpLogLevel: LogLevel = LogLevel.NONE, - val requestTimeout: Long? = null, + val requestTimeout: Long = 30000, + val connectTimeout: Long = 30000, + val socketTimeout: Long = 30000 ) \ No newline at end of file diff --git a/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientImpl.kt b/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientImpl.kt index 6cb2944a..3e220600 100644 --- a/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientImpl.kt +++ b/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientImpl.kt @@ -340,7 +340,7 @@ private suspend inline fun HttpResponse.readApiResponse(expectSucces parseAndThrowConfluencError() } val contentType = contentType() - if (contentType != null && ContentType.Application.Json.match(contentType)){ + if (contentType != null && ContentType.Application.Json.match(contentType)) { try { return body() } catch (e: JsonConvertException) { @@ -357,7 +357,7 @@ private suspend fun HttpResponse.parseAndThrowConfluencError(): Nothing { } private data class PageSearchResult( - val results: List, + val results: List = emptyList(), val start: Int, val limit: Int, val size: Int @@ -367,10 +367,12 @@ fun confluenceClient( config: ConfluenceClientConfig ): ConfluenceClient { val client = HttpClient(CIO) { + install(HttpTimeout) { + requestTimeoutMillis = config.requestTimeout + connectTimeoutMillis = config.connectTimeout + socketTimeoutMillis = config.socketTimeout + } engine { - if (config.requestTimeout != null) { - requestTimeout = config.requestTimeout - } if (config.skipSsl) { https { trustManager = object : X509TrustManager { From 6fc8a63f66d8cf5962a391c609d708f8a3ecb5d3 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 30 Jan 2024 16:02:04 +0100 Subject: [PATCH 2/3] fix(merge-conflict) --- .../zeldigas/text2confl/cli/CliOptions.kt | 18 ++++++++++++++++-- .../zeldigas/text2confl/cli/DumpToMarkdown.kt | 2 ++ .../github/zeldigas/text2confl/cli/Upload.kt | 3 +++ .../confclient/ConfluenceClientConfig.kt | 6 +++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt index 7bc587d9..218f6cd2 100644 --- a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt +++ b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt @@ -58,7 +58,17 @@ fun ParameterHolder.httpLoggingLevel() = option( fun ParameterHolder.httpRequestTimeout() = option( "--http-request-timeout", - help = "Http request timeout in milliseconds. Default " + help = "Http request timeout in milliseconds. Default 30 000 " +).long() + +fun ParameterHolder.httpSocketTimeout() = option( + "--http-socket-timeout", + help = "Http socket timeout in milliseconds. Default 30 000 " +).long() + +fun ParameterHolder.httpConnectTimeout() = option( + "--http-connect-timeout", + help = "Http connect timeout in milliseconds. Default 30 000 " ).long() internal interface WithConfluenceServerOptions { @@ -69,6 +79,8 @@ internal interface WithConfluenceServerOptions { val skipSsl: Boolean? val httpLogLevel: LogLevel val httpRequestTimeout: Long? + val httpConnectTimeout: Long? + val httpSocketTimeout: Long? val confluenceAuth: ConfluenceAuth get() = when { @@ -93,7 +105,9 @@ internal interface WithConfluenceServerOptions { skipSsl = skipSsl ?: defaultSslSkip, auth = confluenceAuth, httpLogLevel = httpLogLevel, - requestTimeout = httpRequestTimeout + requestTimeout = httpRequestTimeout, + connectTimeout = httpConnectTimeout, + socketTimeout = httpSocketTimeout ) fun askForSecret(prompt: String, requireConfirmation: Boolean = true): String? diff --git a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/DumpToMarkdown.kt b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/DumpToMarkdown.kt index 8923ce3f..bc0234e5 100644 --- a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/DumpToMarkdown.kt +++ b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/DumpToMarkdown.kt @@ -22,6 +22,8 @@ class DumpToMarkdown : CliktCommand(name = "export-to-md", help = "Exports confl override val skipSsl: Boolean? by skipSsl() override val httpLogLevel: LogLevel by httpLoggingLevel() override val httpRequestTimeout: Long? by httpRequestTimeout() + override val httpSocketTimeout: Long? by httpSocketTimeout() + override val httpConnectTimeout: Long? by httpConnectTimeout() val space: String? by confluenceSpace() private val pageId: String? by option("--page-id", help = "Id of page that you want to dump") diff --git a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/Upload.kt b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/Upload.kt index 5966f83e..4f2e2e52 100644 --- a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/Upload.kt +++ b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/Upload.kt @@ -33,6 +33,8 @@ class Upload : CliktCommand(name = "upload", help = "Converts source files and u override val skipSsl: Boolean? by skipSsl() override val httpLogLevel: LogLevel by httpLoggingLevel() override val httpRequestTimeout: Long? by httpRequestTimeout() + override val httpSocketTimeout: Long? by httpSocketTimeout() + override val httpConnectTimeout: Long? by httpConnectTimeout() override val spaceKey: String? by confluenceSpace() private val parentId: String? by option("--parent-id", help = "Id of parent page where root pages should be added") @@ -87,6 +89,7 @@ class Upload : CliktCommand(name = "upload", help = "Converts source files and u } else { converter.convertDir(docs.toPath()) } + serviceProvider.createContentValidator().validate(result) val confluenceClient = serviceProvider.createConfluenceClient(clientConfig, dryRun) val publishUnder = resolveParent(confluenceClient, uploadConfig, directoryStoredParams) diff --git a/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt b/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt index 4e6d1243..c1736bc3 100644 --- a/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt +++ b/confluence-client/src/main/kotlin/com/github/zeldigas/confclient/ConfluenceClientConfig.kt @@ -11,7 +11,7 @@ data class ConfluenceClientConfig( val skipSsl: Boolean, val auth: ConfluenceAuth, val httpLogLevel: LogLevel = LogLevel.NONE, - val requestTimeout: Long = 30000, - val connectTimeout: Long = 30000, - val socketTimeout: Long = 30000 + val requestTimeout: Long? = 30000, + val connectTimeout: Long? = 30000, + val socketTimeout: Long? = 30000 ) \ No newline at end of file From cc7e3cf1f89c9c69146513587b91cb1548fed7c9 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 31 Jan 2024 13:02:36 +0100 Subject: [PATCH 3/3] fix(default) : sets default values to timeouts --- .../kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt index 218f6cd2..f710643c 100644 --- a/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt +++ b/cli/src/main/kotlin/com/github/zeldigas/text2confl/cli/CliOptions.kt @@ -59,17 +59,17 @@ fun ParameterHolder.httpLoggingLevel() = option( fun ParameterHolder.httpRequestTimeout() = option( "--http-request-timeout", help = "Http request timeout in milliseconds. Default 30 000 " -).long() +).long().default(30000) fun ParameterHolder.httpSocketTimeout() = option( "--http-socket-timeout", help = "Http socket timeout in milliseconds. Default 30 000 " -).long() +).long().default(30000) fun ParameterHolder.httpConnectTimeout() = option( "--http-connect-timeout", help = "Http connect timeout in milliseconds. Default 30 000 " -).long() +).long().default(30000) internal interface WithConfluenceServerOptions { val confluenceUrl: Url?