aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/client
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-09-01 15:02:06 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-09-01 15:02:06 +0300
commite6c30425575cd76a3955b03ab389150ed74fbb1d (patch)
treee1a668efc3bbd6b5da72ebd8b9825d5e1a96d74c /vid-app-common/src/main/java/org/onap/vid/client
parent406cc2fe614d089c2f7834f9a22d6dfa47b4fa16 (diff)
handle non OK response from SDC while getting model
Issue-ID: VID-378 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: Idc6e587abb24fbec65ed159db7008e50abee2581
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/client')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/client/UnirestPatch.kt13
1 files changed, 13 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/client/UnirestPatch.kt b/vid-app-common/src/main/java/org/onap/vid/client/UnirestPatch.kt
index 750646621..5730c11f1 100644
--- a/vid-app-common/src/main/java/org/onap/vid/client/UnirestPatch.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/client/UnirestPatch.kt
@@ -22,9 +22,11 @@ package org.onap.vid.client
import io.joshworks.restclient.http.Headers
import io.joshworks.restclient.http.HttpResponse
+import org.apache.commons.io.IOUtils
import org.apache.http.HttpVersion
import org.apache.http.message.BasicHttpResponse
import java.io.InputStream
+import java.nio.charset.StandardCharsets
/// Patch NPE in joshworks's Unirest HttpResponse::getBody when getRawBody is null
fun <T> patched(httpResponse: HttpResponse<T>) =
@@ -35,6 +37,17 @@ private fun <T> willGetBodyTriggerNPE(httpResponse: HttpResponse<T>) =
private val dummyHttpResponse = BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "ok")
+fun extractRawAsString(response: HttpResponse<*>?): String {
+ try {
+ if (response == null || response.rawBody==null) return ""
+ response.rawBody.reset()
+ return IOUtils.toString(response.rawBody, StandardCharsets.UTF_8.name())
+ } catch (e: Exception) {
+ //Nothing to do here
+ }
+
+ return ""
+}
/**
* This class inherits HttpResponse to have compatible interface,
* but implementation is done through delegation to another