Skip to content

Commit

Permalink
fix(HttpTriplestoreConnector): Always parse triplestore responses as …
Browse files Browse the repository at this point in the history
…UTF-8. (#1789)
  • Loading branch information
Benjamin Geer committed Jan 21, 2021
1 parent 3d5f802 commit 61d2e86
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 55 deletions.
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

0 comments on commit 61d2e86

Please sign in to comment.