mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 16:06:51 +02:00
fix: Fix "Stream already closed" error
This commit is contained in:
+2
-4
@@ -38,10 +38,9 @@ class BahnApiService(
|
|||||||
val time = LocalTime.of(hourAtDay.hour.value, 0)
|
val time = LocalTime.of(hourAtDay.hour.value, 0)
|
||||||
val day = hourAtDay.date.format(dateFormatter)
|
val day = hourAtDay.date.format(dateFormatter)
|
||||||
val hour = time.format(timeFormatter)
|
val hour = time.format(timeFormatter)
|
||||||
val responseLogger = BahnResponseLogger()
|
|
||||||
val uri = "https://apis.deutschebahn.com/db-api-marketplace/apis/timetables/v1/plan/" +
|
val uri = "https://apis.deutschebahn.com/db-api-marketplace/apis/timetables/v1/plan/" +
|
||||||
"${eva.value}/${day}/${hour}"
|
"${eva.value}/${day}/${hour}"
|
||||||
val response = restClient.get()
|
val body = restClient.get()
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.headers {
|
.headers {
|
||||||
it.accept = mutableListOf(MediaType.APPLICATION_XML)
|
it.accept = mutableListOf(MediaType.APPLICATION_XML)
|
||||||
@@ -50,9 +49,8 @@ class BahnApiService(
|
|||||||
it.set("DB-Api-Key", properties.clientSecret)
|
it.set("DB-Api-Key", properties.clientSecret)
|
||||||
}
|
}
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.onStatus(responseLogger)
|
.body(BahnTimetable::class.java)
|
||||||
log.debug { "Response from DB API, station [${eva.value}], date [$day], hour [$hour], requestURI [$uri]" }
|
log.debug { "Response from DB API, station [${eva.value}], date [$day], hour [$hour], requestURI [$uri]" }
|
||||||
val body = response.body(BahnTimetable::class.java)
|
|
||||||
body!!.eva = eva
|
body!!.eva = eva
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
package de.twomartens.timetable.bahnApi.service
|
|
||||||
|
|
||||||
import mu.KotlinLogging
|
|
||||||
import org.springframework.http.client.ClientHttpResponse
|
|
||||||
import org.springframework.web.client.ResponseErrorHandler
|
|
||||||
|
|
||||||
class BahnResponseLogger : ResponseErrorHandler {
|
|
||||||
override fun hasError(response: ClientHttpResponse): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun handleError(response: ClientHttpResponse) {
|
|
||||||
val body = response.body.bufferedReader().use { it.readText() }
|
|
||||||
log.debug { "Status code [${response.statusCode.value()}], status text [${response.statusText}], headers [${response.headers}], body [$body]" }
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val log = KotlinLogging.logger {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user