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..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 @@ -58,8 +58,18 @@ fun ParameterHolder.httpLoggingLevel() = option( fun ParameterHolder.httpRequestTimeout() = option( "--http-request-timeout", - help = "Http request timeout in milliseconds. Default " -).long() + help = "Http request timeout in milliseconds. Default 30 000 " +).long().default(30000) + +fun ParameterHolder.httpSocketTimeout() = option( + "--http-socket-timeout", + help = "Http socket timeout in milliseconds. Default 30 000 " +).long().default(30000) + +fun ParameterHolder.httpConnectTimeout() = option( + "--http-connect-timeout", + help = "Http connect timeout in milliseconds. Default 30 000 " +).long().default(30000) internal interface WithConfluenceServerOptions { val confluenceUrl: Url? @@ -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 66c50d02..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,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 {