diff options
author | Amichai Hemli <ah0398@intl.att.com> | 2019-08-22 13:50:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-08-22 13:50:23 +0000 |
commit | f73ae122a3141892a475902e327feff7559d6b1a (patch) | |
tree | 83c1e2ce96ac4164fa1ba3f509a39d9e946f3bac /vid-app-common/src/main | |
parent | b9c83f721a96353aac9d94c368b2ee23ba73f26e (diff) | |
parent | 6eef01205c39cc155a8b6f5de25a564b44c919f9 (diff) |
Merge "make scheduler client tolerance to error messages"
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java | 18 | ||||
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/utils/Logging.java | 4 |
2 files changed, 14 insertions, 8 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java index 78b3e9709..7878c2fb8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java @@ -21,6 +21,7 @@ package org.onap.vid.scheduler; import com.att.eelf.configuration.EELFLogger; +import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import io.joshworks.restclient.http.HttpResponse; @@ -43,6 +44,7 @@ import java.util.Collections; import java.util.Map; import java.util.function.Function; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY; @Service @@ -90,15 +92,19 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { .putAll(commonHeaders) .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()) .build(); - final HttpResponse<T> response = ((HttpResponse<T>) syncRestClient.get(url, requestHeaders, - Collections.emptyMap(), t.getClass())); + final HttpResponse<String> response = syncRestClient.get(url, requestHeaders, + Collections.emptyMap(), String.class); Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); status = response.getStatus(); restObject.setStatusCode(status); - + rawData = response.getBody(); if (status == 200) { - t = response.getBody(); - restObject.set(t); + if (t instanceof String) { + restObject.set((T)rawData); + } + else { + restObject.set(JACKSON_OBJECT_MAPPER.readValue(rawData, new TypeReference<T>() {})); + } logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE); logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE); } else { @@ -106,7 +112,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { } return new RestObjectWithRequestInfo<>(HttpMethod.GET, url, restObject, status, rawData); } - catch (RuntimeException e) { + catch (Exception e) { throw new ExceptionWithRequestInfo(HttpMethod.GET, url, rawData, status, e); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java index df7f20e49..71478fcf1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java @@ -119,7 +119,7 @@ public class Logging { response.bufferEntity(); logger.debug("Received {} {} Status: {} . Body: {}", method.name(), url, response.getStatus(), response.readEntity(entityClass)); } - catch (ProcessingException | IllegalStateException e) { + catch (Exception e) { logger.debug("Received {} {} Status: {} . Failed to read response as {}", method.name(), url, response.getStatus(), entityClass.getName()); } } @@ -128,7 +128,7 @@ public class Logging { try { logger.debug("Received {} {} Status: {} . Body: {}", method.name(), url, response.getStatus(), response.getBody()); } - catch (ProcessingException | IllegalStateException e) { + catch (Exception e) { logger.debug("Received {} {} Status: {} . Failed to read response", method.name(), url, response.getStatus()); } } |