summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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();