diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2024-05-07 12:31:44 +0100 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2024-05-17 12:23:36 +0100 |
commit | 3ad3931017bafabbb78c43e82beb8f462e3796ac (patch) | |
tree | 76e1c2bd3ca93e4cca7bb27df574d8eab1e77b6b /cps-ncmp-rest | |
parent | 01d2f8e3cdb59ce11856b6e6e8ad4e3e4ec91804 (diff) |
Replaced RestTemplate with WebClient in synchronous DMI calls
- added DmiWebClientConfiguration
- use WebClient in DmiRestClient
- fixed unit tests
- encode query params for DMI request
- added configurable buffer size
- Re-used ncmp.dmi.httpclient.maximumConnectionsTotal parameter
(as documented in RTD) to control webclient connection poolsize
Issue-ID: CPS-2173
Change-Id: I21584563034d58e8ae3ff3cbcf172e0d14b408fb
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-rest')
2 files changed, 15 insertions, 12 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java index d323691916..7263000896 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java @@ -23,9 +23,10 @@ package org.onap.cps.ncmp.rest.exceptions; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException; import org.onap.cps.ncmp.api.impl.exception.DmiRequestException; -import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException; import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; +import org.onap.cps.ncmp.api.impl.exception.InvalidDmiResourceUrlException; import org.onap.cps.ncmp.api.impl.exception.NcmpException; import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException; import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController; @@ -69,14 +70,15 @@ public class NetworkCmProxyRestExceptionHandler { return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); } - @ExceptionHandler({HttpClientRequestException.class}) + @ExceptionHandler({DmiClientRequestException.class}) public static ResponseEntity<Object> handleClientRequestExceptions( - final HttpClientRequestException httpClientRequestException) { - return wrapDmiErrorResponse(httpClientRequestException); + final DmiClientRequestException dmiClientRequestException) { + return wrapDmiErrorResponse(dmiClientRequestException); } @ExceptionHandler({DmiRequestException.class, DataValidationException.class, OperationNotSupportedException.class, - HttpMessageNotReadableException.class, InvalidTopicException.class, InvalidDatastoreException.class}) + HttpMessageNotReadableException.class, InvalidTopicException.class, InvalidDatastoreException.class, + InvalidDmiResourceUrlException.class}) public static ResponseEntity<Object> handleDmiRequestExceptions(final Exception exception) { return buildErrorResponse(HttpStatus.BAD_REQUEST, exception); } @@ -115,13 +117,13 @@ public class NetworkCmProxyRestExceptionHandler { return new ResponseEntity<>(errorMessage, status); } - private static ResponseEntity<Object> wrapDmiErrorResponse(final HttpClientRequestException - httpClientRequestException) { + private static ResponseEntity<Object> wrapDmiErrorResponse(final DmiClientRequestException + dmiClientRequestException) { final var dmiErrorMessage = new DmiErrorMessage(); final var dmiErrorResponse = new DmiErrorMessageDmiResponse(); - dmiErrorResponse.setHttpCode(httpClientRequestException.getHttpStatus()); - dmiErrorResponse.setBody(httpClientRequestException.getDetails()); - dmiErrorMessage.setMessage(httpClientRequestException.getMessage()); + dmiErrorResponse.setHttpCode(dmiClientRequestException.getHttpStatusCode()); + dmiErrorResponse.setBody(dmiClientRequestException.getResponseBodyAsString()); + dmiErrorMessage.setMessage(dmiClientRequestException.getMessage()); dmiErrorMessage.setDmiResponse(dmiErrorResponse); return new ResponseEntity<>(dmiErrorMessage, HttpStatus.BAD_GATEWAY); } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy index a79ea25ab8..ea472cd931 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -31,13 +31,14 @@ import static org.onap.cps.ncmp.rest.exceptions.NetworkCmProxyRestExceptionHandl import static org.onap.cps.ncmp.rest.exceptions.NetworkCmProxyRestExceptionHandlerSpec.ApiType.NCMPINVENTORY import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post +import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA import groovy.json.JsonSlurper import org.mapstruct.factory.Mappers import org.onap.cps.TestUtils import org.onap.cps.ncmp.api.NetworkCmProxyDataService import org.onap.cps.ncmp.api.impl.exception.DmiRequestException -import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException +import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException import org.onap.cps.ncmp.rest.controller.NcmpRestInputMapper import org.onap.cps.ncmp.rest.controller.handlers.NcmpCachedResourceRequestHandler @@ -143,7 +144,7 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { def 'Failing DMI Request - passthrough scenario'() { given: 'failing DMI request' - setupTestException(new HttpClientRequestException('Error Message Details NCMP', 'Bad Request from DMI', 400), NCMP) + setupTestException(new DmiClientRequestException(400, 'Error Message Details NCMP', 'Bad Request from DMI', UNABLE_TO_READ_RESOURCE_DATA), NCMP) when: 'the DMI request is executed' def response = performTestRequest(NCMP) then: 'NCMP service responds with 502 Bad Gateway status' |