aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-07-25 20:33:03 +0300
committerIttay Stern <ittay.stern@att.com>2019-07-29 09:57:54 +0300
commit88753b87947fdacb003a9aec4142c2f5745ea006 (patch)
tree253d73bf2b481bf9397aad374f017f8e72caebb1 /vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java
parentb75aff807050009af821f2072417d8806efd56a2 (diff)
Patch NPE in Unirest HttpResponse::getBody when getRawBody is null
Issue-ID: VID-267 Change-Id: I469bbeea52d6e86f8f12f88e9754af81b3ae6ae6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java32
1 files changed, 19 insertions, 13 deletions
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 <T> HttpResponse<T> callWithRetryOverHttpThrows(String url, HttpRequest<T> 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> T readValue(String value, Class<T> 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);
}