Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HttpTriplestoreConnector): Always decode triplestore responses as UTF-8 (DSP-1238) #1789

Merged
merged 3 commits into from Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,6 +22,7 @@ package org.knora.webapi.store.triplestore.http
import java.io.BufferedInputStream
import java.net.URI
import java.nio.file.{Files, Path, Paths, StandardCopyOption}
import java.nio.charset.StandardCharsets
import java.util

import akka.actor.{Actor, ActorLogging, ActorSystem, Status}
Expand Down Expand Up @@ -604,7 +605,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat

val responseTry: Try[String] = Try {
maybeResponse = Some(queryHttpClient.execute(targetHost, httpGet, context))
EntityUtils.toString(maybeResponse.get.getEntity)
EntityUtils.toString(maybeResponse.get.getEntity, StandardCharsets.UTF_8)
}

maybeResponse.foreach(_.close())
Expand Down Expand Up @@ -712,7 +713,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat

val responseTry: Try[String] = Try {
maybeResponse = Some(queryHttpClient.execute(targetHost, httpGet, context))
EntityUtils.toString(maybeResponse.get.getEntity)
EntityUtils.toString(maybeResponse.get.getEntity, StandardCharsets.UTF_8)
}

maybeResponse.foreach(_.close())
Expand Down Expand Up @@ -1008,7 +1009,8 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat
val statusCategory: Int = statusCode / 100

if (statusCategory != 2) {
Option(response.getEntity).map(responseEntity => EntityUtils.toString(responseEntity)) match {
Option(response.getEntity)
.map(responseEntity => EntityUtils.toString(responseEntity, StandardCharsets.UTF_8)) match {
case Some(responseEntityStr) =>
log.error(s"Triplestore responded with HTTP code $statusCode: $responseEntityStr")
throw TriplestoreResponseException(s"Triplestore responded with HTTP code $statusCode: $responseEntityStr")
Expand Down Expand Up @@ -1043,7 +1045,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat
case None => ""

case Some(responseEntity) =>
EntityUtils.toString(responseEntity)
EntityUtils.toString(responseEntity, StandardCharsets.UTF_8)
}
}

Expand All @@ -1055,7 +1057,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat

case Some(responseEntity: HttpEntity) =>
NamedGraphDataResponse(
turtle = EntityUtils.toString(responseEntity)
turtle = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8)
)
}
}
Expand Down