From 59d3d1c6e4c69055962fd652f057b0f15a2e3d4a Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Tue, 14 Apr 2020 10:55:10 +0200 Subject: log SL2.0 response in case of an non-parseable VDA response --- .../gv/egiz/sl20/utils/SL20JSONExtractorUtils.java | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'pdf-as-lib') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl20/utils/SL20JSONExtractorUtils.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl20/utils/SL20JSONExtractorUtils.java index 5fbce83b..8ed27e3c 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl20/utils/SL20JSONExtractorUtils.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl20/utils/SL20JSONExtractorUtils.java @@ -12,6 +12,7 @@ import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.utils.URIBuilder; +import org.apache.http.util.EntityUtils; import org.jose4j.base64url.Base64Url; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -380,18 +381,26 @@ public class SL20JSONExtractorUtils { } private static JsonObject parseSL20ResultFromResponse(HttpEntity resp) throws Exception { - if (resp != null && resp.getContent() != null) { - JsonElement sl20Resp = new JsonParser().parse(new InputStreamReader(resp.getContent())); - if (sl20Resp != null && sl20Resp.isJsonObject()) { - return sl20Resp.getAsJsonObject(); + if (resp != null && resp.getContent() != null) { + String htmlRespBody = EntityUtils.toString(resp); + try { + JsonElement sl20Resp = new JsonParser().parse(htmlRespBody); + if (sl20Resp != null && sl20Resp.isJsonObject()) { + return sl20Resp.getAsJsonObject(); - } else { - log.warn("SL2.0 can NOT parse to a JSON object"); - throw new SLCommandoParserException(); + } else { + log.warn("SL2.0 can NOT parse to a JSON object"); + throw new SLCommandoParserException(); + + } + + } catch (Exception e) { + log.info("Can NOT parse SL2.0 respone from VDA. Raw SL2.0 response: {}", + htmlRespBody); + throw new SLCommandoParserException(e); } - - + } else { log.warn("Can NOT find content in http response"); throw new SLCommandoParserException(); -- cgit v1.2.3