summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreschcam <cameron.scholes@est.tech>2022-11-18 12:02:27 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-11-19 16:36:38 +0000
commit83bbca087a66d5ea4cff1f5d066f7761948a2cb3 (patch)
treeecbb6ea97f3e6ce42ac78d6407d00e0d968d1b0f
parent75e64ef5a7904a1a512272c14f75bc91d5c00de7 (diff)
Added null check in ExternalTestingManagerImpl
Added missing null checks in ExternalTestingManagerImpl. Issue-ID: SDC-4269 Change-Id: Ic66f30ab7d78014ad7311ce53c03498168909a61 Signed-off-by: eschcam <cameron.scholes@est.tech>
-rw-r--r--openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java42
1 files changed, 26 insertions, 16 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java
index f115a98e5b..b6cc045a3e 100644
--- a/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-impl/src/main/java/org/openecomp/core/externaltesting/impl/ExternalTestingManagerImpl.java
@@ -612,12 +612,15 @@ public class ExternalTestingManagerImpl implements ExternalTestingManager {
} else {
logger.debug("GET request to {} for {}", url, responseType.getType().getTypeName());
}
+
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
+ ResponseEntity<T> re;
+
if (rf != null) {
rf.setReadTimeout(10000);
rf.setConnectTimeout(10000);
}
- ResponseEntity<T> re;
+
try {
if (request != null) {
re = restTemplate.exchange(url, HttpMethod.POST, request, responseType);
@@ -626,22 +629,28 @@ public class ExternalTestingManagerImpl implements ExternalTestingManager {
}
} catch (HttpStatusCodeException ex) {
// make my own exception out of this.
+ HttpHeaders httpHeaders = ex.getResponseHeaders();
logger.warn("Unexpected HTTP Status from endpoint {}", ex.getRawStatusCode());
- if ((ex.getResponseHeaders().getContentType() != null) && (
- (ex.getResponseHeaders().getContentType().isCompatibleWith(MediaType.APPLICATION_JSON))
- || (ex.getResponseHeaders().getContentType()
- .isCompatibleWith(MediaType.parseMediaType("application/problem+json"))))) {
- String s = ex.getResponseBodyAsString();
- logger.warn("endpoint body content is {}", s);
- try {
- JsonObject o = new GsonBuilder().create().fromJson(s, JsonObject.class);
- throw buildTestingException(ex.getRawStatusCode(), o);
- } catch (JsonParseException e) {
- logger.warn("unexpected JSON response", e);
- throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(),
- ex.getResponseBodyAsString(), ex);
- }
- } else {
+
+ if (httpHeaders == null) {
+ throw new ExternalTestingException(ENDPOINT_ERROR_CODE, 500, "Failed to get HTTP Response Headers", ex);
+ }
+
+ MediaType responseHeadersContentType = httpHeaders.getContentType();
+
+ if (responseHeadersContentType == null || (!responseHeadersContentType.isCompatibleWith(MediaType.APPLICATION_JSON)
+ && !responseHeadersContentType.isCompatibleWith(MediaType.parseMediaType("application/problem+json")))) {
+ throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(), ex.getResponseBodyAsString(), ex);
+ }
+
+ String s = ex.getResponseBodyAsString();
+ logger.warn("endpoint body content is {}", s);
+
+ try {
+ JsonObject o = new GsonBuilder().create().fromJson(s, JsonObject.class);
+ throw buildTestingException(ex.getRawStatusCode(), o);
+ } catch (JsonParseException e) {
+ logger.warn("unexpected JSON response", e);
throw new ExternalTestingException(ENDPOINT_ERROR_CODE, ex.getStatusCode().value(),
ex.getResponseBodyAsString(), ex);
}
@@ -650,6 +659,7 @@ public class ExternalTestingManagerImpl implements ExternalTestingManager {
} catch (Exception ex) {
throw new ExternalTestingException(ENDPOINT_ERROR_CODE, 500, "Generic Exception " + ex.getMessage(), ex);
}
+
if (re != null) {
logger.debug("http status of {} from external testing entity {}", re.getStatusCodeValue(), url);
return re.getBody();