Skip to content

Commit

Permalink
eliminated own http layer/package in favour of standard HttpURLConnec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
gmuth committed Sep 16, 2023
1 parent a5fcf5e commit 8984623
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 475 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ tasks.compileKotlin {
// avoid warnings "jvm target compatibility should be set to the same Java version."
tasks.compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
jvmTarget = "1.8"
}
}

tasks.compileJava {
sourceCompatibility = tasks.compileKotlin.get().kotlinOptions.jvmTarget
targetCompatibility = tasks.compileKotlin.get().kotlinOptions.jvmTarget
Expand Down
66 changes: 0 additions & 66 deletions src/main/kotlin/de/gmuth/http/Http.kt

This file was deleted.

65 changes: 0 additions & 65 deletions src/main/kotlin/de/gmuth/http/HttpURLConnectionClient.kt

This file was deleted.

77 changes: 0 additions & 77 deletions src/main/kotlin/de/gmuth/http/JavaHttpClient.kt

This file was deleted.

21 changes: 8 additions & 13 deletions src/main/kotlin/de/gmuth/ipp/client/CupsClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package de.gmuth.ipp.client
* Copyright (c) 2020-2023 Gerhard Muth
*/

import de.gmuth.http.Http
import de.gmuth.ipp.client.IppExchangeException.ClientErrorNotFoundException
import de.gmuth.ipp.core.IppOperation
import de.gmuth.ipp.core.IppOperation.*
Expand All @@ -21,23 +20,19 @@ import java.util.logging.Logger.getLogger
// https://www.cups.org/doc/spec-ipp.html
open class CupsClient(
val cupsUri: URI = URI.create("ipp://localhost"),
val ippConfig: IppConfig = IppConfig(),
httpClient: Http.Client = Http.defaultImplementation.createClient(Http.Config())
val ippClient: IppClient = IppClient()
) {
constructor(host: String = "localhost") : this(URI.create("ipp://$host"))

val log = getLogger(javaClass.name)
var userName: String? by ippConfig::userName
val httpConfig: Http.Config by httpClient::config
val config: IppConfig by ippClient::config
var userName: String? by config::userName
var cupsClientWorkDirectory = File("cups-${cupsUri.host}")
val ippClient = IppClient(ippConfig, httpClient = httpClient)

init {
if (cupsUri.scheme == "ipps") httpConfig.trustAnyCertificateAndSSLHostname()
if (cupsUri.scheme == "ipps") config.trustAnyCertificateAndSSLHostname()
}

fun getIppServer() = ippClient.getHttpServer()

fun getPrinters() = try {
exchange(ippRequest(CupsGetPrinters))
.getAttributesGroups(Printer)
Expand Down Expand Up @@ -326,14 +321,14 @@ open class CupsClient(
}
tryToGetDocuments()
if (ippExchangeException != null && ippExchangeException!!.httpStatus == 401) {
val configuredUserName = ippConfig.userName
val configuredUserName = config.userName
val jobOwnersIterator = jobOwners.iterator()
while (jobOwnersIterator.hasNext() && ippExchangeException != null) {
ippConfig.userName = jobOwnersIterator.next()
log.fine { "set userName '${ippConfig.userName}'" }
config.userName = jobOwnersIterator.next()
log.fine { "set userName '${config.userName}'" }
tryToGetDocuments()
}
ippConfig.userName = configuredUserName
config.userName = configuredUserName
}
documents.onEach { document ->
document.save(job.printerDirectory(), overwrite = true)
Expand Down
Loading

0 comments on commit 8984623

Please sign in to comment.