From 88753b87947fdacb003a9aec4142c2f5745ea006 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Thu, 25 Jul 2019 20:33:03 +0300 Subject: Patch NPE in Unirest HttpResponse::getBody when getRawBody is null Issue-ID: VID-267 Change-Id: I469bbeea52d6e86f8f12f88e9754af81b3ae6ae6 Signed-off-by: Ittay Stern --- .../java/org/onap/vid/client/SyncRestClient.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java b/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java index 5f76044bb..50556e7ec 100644 --- a/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java @@ -20,12 +20,28 @@ package org.onap.vid.client; +import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.onap.vid.client.UnirestPatchKt.patched; + import io.joshworks.restclient.http.HttpResponse; import io.joshworks.restclient.http.JsonNode; import io.joshworks.restclient.http.RestClient; import io.joshworks.restclient.http.exceptions.RestClientException; import io.joshworks.restclient.http.mapper.ObjectMapper; import io.joshworks.restclient.request.GetRequest; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.util.Map; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLException; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; @@ -36,16 +52,6 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.properties.VidProperties; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLException; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.*; -import java.security.cert.CertificateException; -import java.util.Map; - public class SyncRestClient implements SyncRestClientInterface { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SyncRestClient.class); private static final String[] SUPPORTED_SSL_VERSIONS = {"TLSv1", "TLSv1.2"}; @@ -151,11 +157,11 @@ public class SyncRestClient implements SyncRestClientInterface { private HttpResponse callWithRetryOverHttpThrows(String url, HttpRequest httpRequest) throws IOException { try { - return httpRequest.apply(url); + return patched(httpRequest.apply(url)); } catch (RestClientException e) { if (causedBySslHandshakeError(e)) { logger.warn(EELFLoggerDelegate.debugLogger, "SSL Handshake problem occured. Will try to retry over Http.", e); - return httpRequest.apply(url.replaceFirst(HTTPS_SCHEMA, HTTP_SCHEMA)); + return patched(httpRequest.apply(url.replaceFirst(HTTPS_SCHEMA, HTTP_SCHEMA))); } throw e; } @@ -172,7 +178,7 @@ public class SyncRestClient implements SyncRestClientInterface { @Override public T readValue(String value, Class aClass) { try { - return objectMapper.readValue(value, aClass); + return isEmpty(value) ? null : objectMapper.readValue(value, aClass); } catch (IOException e) { throw new SyncRestClientException("IOException while reading value", e); } -- cgit 1.2.3-korg