make scheduler client tolerance to error messages 06/94106/2
authorEylon Malin <eylon.malin@intl.att.com>
Thu, 22 Aug 2019 12:22:17 +0000 (15:22 +0300)
committerEylon Malin <eylon.malin@intl.att.com>
Thu, 22 Aug 2019 13:33:04 +0000 (16:33 +0300)
Read response from scheduler as String save them as raw,
and only then parse them

Issue-ID: VID-378
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Change-Id: I38ed8f211b2c111b57741254cb5e90317fefdc7d
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientITTest.java
vid-app-common/src/test/java/org/onap/vid/testUtils/StubServerUtil.java
vid-automation/src/test/java/org/onap/vid/api/ProbeApiTest.java

index 78b3e97..7878c2f 100644 (file)
@@ -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);
         }
     }
index df7f20e..71478fc 100644 (file)
@@ -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());
         }
     }
index 126f300..589874d 100644 (file)
@@ -85,7 +85,7 @@ public class SdcRestClientITTest {
         String expectedEndpoint = String.format("/sdc/v1/catalog/services/%s/toscaModel", uuid);
 
         stubServer.prepareGetCall(
-                expectedEndpoint, stringContent("sampleFileContent"), "sampleFileContent", ok(), "application/octet-stream");
+                expectedEndpoint, stringContent("sampleFileContent"), ok(), "application/octet-stream");
 
 
         Path serviceToscaModel = sdcRestClient.getServiceToscaModel(uuid);
index 3f5bf81..848f80b 100644 (file)
@@ -64,7 +64,7 @@ public class StubServerUtil {
         return String.format("%s://localhost:%s/%s", protocol, stubServer.getPort(), relativePath);
     }
 
-    public void prepareGetCall(String path, Action actionToReturn,Object returnObj, Action expectedAction, String contentType) throws JsonProcessingException {
+    public void prepareGetCall(String path, Action actionToReturn, Action expectedAction, String contentType) throws JsonProcessingException {
         whenHttp(stubServer)
                 .match(Condition.get(path))
                 .then(expectedAction, actionToReturn, contentType(contentType));
@@ -72,7 +72,7 @@ public class StubServerUtil {
 
 
     public void prepareGetCall(String path, Object returnObj, Action expectedAction) throws JsonProcessingException {
-        prepareGetCall(path, jsonContent(returnObj),returnObj, expectedAction, APPLICATION_JSON);
+        prepareGetCall(path, jsonContent(returnObj), expectedAction, APPLICATION_JSON);
     }
 
     public void prepareDeleteCall(String path, Object returnObj, Action expectedAction) throws JsonProcessingException {
index dacee53..5ed3024 100644 (file)
@@ -142,7 +142,7 @@ public class ProbeApiTest extends BaseApiTest {
                                         200,
                                         SCHEDULER_PATH,
                                         "this payload is an invalid json",
-                                        "javax.ws.rs.ProcessingException"
+                                        "com.fasterxml.jackson.core.JsonParseException"
                                 )
                         ))
                 },
@@ -185,7 +185,7 @@ public class ProbeApiTest extends BaseApiTest {
                                         400,
                                         SCHEDULER_PATH,
                                         "this payload is an invalid json",
-                                        "org.apache.http.HttpException: Get with status = 400, url = " + SCHEDULER_PATH
+                                        "org.apache.http.HttpException"
                                 )
                         ))
                 }