diff options
author | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2020-02-27 10:26:32 +0100 |
---|---|---|
committer | Tomasz Golabek <tomasz.golabek@nokia.com> | 2020-03-05 13:44:05 +0100 |
commit | d43531d4072653b86cc86459816e54806ad589c2 (patch) | |
tree | 1a19068cede89992c4f37e8e8b25ec6afc94b53c /certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java | |
parent | 8f26d1f4274f18bd9502386700919933045e2316 (diff) |
Create adapter for Cmpv2Client
connected-with: https://gerrit.onap.org/r/c/aaf/certservice/+/102401
Issue-ID: AAF-997
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
Change-Id: Ieb85cd9c93f7a5470fca37a9de4bead3c543199a
Diffstat (limited to 'certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java')
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java b/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java index 130a5167..d649f147 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationExceptionController.java @@ -21,10 +21,12 @@ package org.onap.aaf.certservice.certification; import com.google.gson.Gson; +import org.onap.aaf.certservice.certification.exception.Cmpv2ClientAdapterException; import org.onap.aaf.certservice.certification.exception.Cmpv2ServerNotFoundException; import org.onap.aaf.certservice.certification.exception.CsrDecryptionException; import org.onap.aaf.certservice.certification.exception.ErrorResponseModel; import org.onap.aaf.certservice.certification.exception.KeyDecryptionException; +import org.onap.aaf.certservice.cmpv2client.exceptions.CmpClientException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -40,19 +42,51 @@ public class CertificationExceptionController { @ExceptionHandler(value = CsrDecryptionException.class) public ResponseEntity<String> handle(CsrDecryptionException exception) { LOGGER.error("Exception occurred during decoding certificate sign request:", exception); - return getErrorResponseEntity("Wrong certificate signing request (CSR) format", HttpStatus.BAD_REQUEST); + return getErrorResponseEntity( + "Wrong certificate signing request (CSR) format", + HttpStatus.BAD_REQUEST + ); } @ExceptionHandler(value = KeyDecryptionException.class) public ResponseEntity<String> handle(KeyDecryptionException exception) { LOGGER.error("Exception occurred during decoding key:", exception); - return getErrorResponseEntity("Wrong key (PK) format", HttpStatus.BAD_REQUEST); + return getErrorResponseEntity( + "Wrong key (PK) format", + HttpStatus.BAD_REQUEST + ); } @ExceptionHandler(value = Cmpv2ServerNotFoundException.class) public ResponseEntity<String> handle(Cmpv2ServerNotFoundException exception) { LOGGER.error("Exception occurred selecting CMPv2 server:", exception); - return getErrorResponseEntity("Certification authority not found for given CAName", HttpStatus.NOT_FOUND); + return getErrorResponseEntity( + "Certification authority not found for given CAName", + HttpStatus.NOT_FOUND + ); + } + + @ExceptionHandler(value = CmpClientException.class) + public ResponseEntity<String> handle(CmpClientException exception) { + LOGGER.error("Exception occurred calling cmp client:", exception); + return getErrorResponseEntity( + "Exception occurred during call to cmp client", + HttpStatus.INTERNAL_SERVER_ERROR + ); + } + + @ExceptionHandler(value = RuntimeException.class) + public ResponseEntity<String> handle(RuntimeException exception) throws CmpClientException { + throw new CmpClientException("Runtime exception occurred calling cmp client business logic", exception); + } + + @ExceptionHandler(value = Cmpv2ClientAdapterException.class) + public ResponseEntity<String> handle(Cmpv2ClientAdapterException exception) { + LOGGER.error("Exception occurred parsing cmp client response:", exception); + return getErrorResponseEntity( + "Exception occurred parsing cmp client response", + HttpStatus.INTERNAL_SERVER_ERROR + ); } private ResponseEntity<String> getErrorResponseEntity(String errorMessage, HttpStatus status) { |