From 6f1a6d516c234547c8b67cd1c32ec25d6e33ffcd Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 15 Jul 2019 14:10:18 -0700 Subject: [PATCH 1/2] Adding a base Exception to extend into specific exceptions. --- .../plugins/console/ConsoleInput.java | 2 +- .../plugins/http/DocumentController.java | 22 ++++++++++------- .../rabbitmq/RabbitMqDocumentInput.java | 9 +++++-- .../rabbitmq/RabbitMqDocumentOutput.java | 2 +- .../RabbitMqDocumentReadyService.java | 2 +- .../plugins/rabbitmq/RedisStorageService.java | 2 +- .../services/DocumentReadyHandler.java | 3 ++- .../rabbitmq/RabbitMqDocumentInputTester.java | 8 +++---- .../rest/DocumentControllerTester.java | 8 +++---- .../services/DocumentReadyHandlerTester.java | 6 ++--- .../RabbitMqDocumentOutputTester.java | 4 ++-- .../RabbitMqDocumentReadyServiceTester.java | 8 +++---- .../services/RedisStorageServiceTester.java | 6 ++--- .../open/jrccaccess/libs/DocumentOutput.java | 4 +++- .../jrccaccess/libs/DocumentReadyService.java | 2 +- .../open/jrccaccess/libs/StorageService.java | 2 +- .../exceptions/DocumentMessageException.java | 24 +++++++++++++++++++ .../ServiceUnavailableException.java | 4 ++-- 18 files changed, 77 insertions(+), 41 deletions(-) create mode 100644 jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java rename jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/{ => exceptions}/ServiceUnavailableException.java (89%) diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java index 4e505214..8c05206f 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java @@ -40,7 +40,7 @@ public void run(String... args) throws Exception { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { - documentReadyHandler.Handle(scanner.nextLine(), appName); + documentReadyHandler.handle(scanner.nextLine(), appName); } scanner.close(); diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java index 96d94d17..70acc0e6 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java @@ -20,7 +20,8 @@ import ca.bc.gov.open.api.model.DocumentReceivedResponse; import ca.bc.gov.open.api.model.Error; import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The document controller provides an endpoint to submit a document. @@ -59,20 +60,23 @@ public ResponseEntity postDocument(@NotNull @Valid Str response.setAcknowledge(true); try { - documentReadyHandler.Handle(getContent(body.getInputStream()), sender); - } catch (IOException e) { - // TODO Auto-generated catch block - - Error error = new Error(); - error.setCode(Integer.toString(HttpStatus.INTERNAL_SERVER_ERROR.value())); - error.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); - return new ResponseEntity(error, HttpStatus.INTERNAL_SERVER_ERROR); + documentReadyHandler.handle(getContent(body.getInputStream()), sender); + } catch (ServiceUnavailableException e) { Error error = new Error(); error.setCode(Integer.toString(HttpStatus.SERVICE_UNAVAILABLE.value())); error.setMessage(e.getMessage()); return new ResponseEntity(error, HttpStatus.SERVICE_UNAVAILABLE); + + } catch (IOException | DocumentMessageException e) { + // TODO Auto-generated catch block + + Error error = new Error(); + error.setCode(Integer.toString(HttpStatus.INTERNAL_SERVER_ERROR.value())); + error.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); + return new ResponseEntity(error, HttpStatus.INTERNAL_SERVER_ERROR); + } return ResponseEntity.ok(response); diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java index 1054d0db..3bec74fc 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java @@ -13,7 +13,8 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The RabbitMqDocumentInput handles document from the rabbitMq message listener @@ -66,7 +67,7 @@ public void receiveMessage(DocumentReadyMessage documentReadyMessage, try { - this.documentReadyHandler.Handle("not implemented yet", + this.documentReadyHandler.handle("not implemented yet", documentReadyMessage.getTransactionInfo().getSender()); logger.info("message successfully aknoledge"); @@ -75,6 +76,10 @@ public void receiveMessage(DocumentReadyMessage documentReadyMessage, logger.warn("Service unavailable exception, message will be put into the dead letter queue."); throw new AmqpRejectAndDontRequeueException(e.getCause()); + } catch (DocumentMessageException e) { + + logger.warn("Service unavailable exception, message will be put into the dead letter queue."); + throw new AmqpRejectAndDontRequeueException(e.getCause()); } } diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java index 1a6498fe..c9cf0880 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java @@ -11,7 +11,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The rabbitMqDocumentOutput provides service to send document ready message diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java index 8801265a..083faa97 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java @@ -11,7 +11,7 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.AccessProperties; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyService; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The RabbitMqDocumentReadyService provides services to interact with rabbitMq diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java index e0baaf7c..83a6fb9b 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java @@ -14,7 +14,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.StorageService; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The redisStorageService provides services to interact with Redis cache. diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java index a275c4c5..82a19797 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java @@ -8,6 +8,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentOutput; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; /** * The document ready handler is the global handler for incoming documents @@ -37,7 +38,7 @@ public DocumentReadyHandler(DocumentOutput documentOutput) { * @param inputStream * @param sender */ - public void Handle(String message, String sender) { + public void handle(String message, String sender) throws DocumentMessageException { logger.debug("New document in {}", this.getClass().getName()); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java index 9fe942d9..20dc6d04 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java @@ -14,7 +14,7 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; public class RabbitMqDocumentInputTester { @@ -36,10 +36,10 @@ public class RabbitMqDocumentInputTester { private RabbitMqInputProperties rabbitMqInputProperties; @Before - public void init() { + public void init() throws Exception { MockitoAnnotations.initMocks(this); - Mockito.doNothing().when(documentReadyHandlerMock).Handle(Mockito.anyString(), Mockito.anyString()); - Mockito.doThrow(ServiceUnavailableException.class).when(documentReadyHandlerMock).Handle(Mockito.anyString(), Mockito.eq(SERVICE_UNAVAILABLE_EXCEPTION)); + Mockito.doNothing().when(documentReadyHandlerMock).handle(Mockito.anyString(), Mockito.anyString()); + Mockito.doThrow(ServiceUnavailableException.class).when(documentReadyHandlerMock).handle(Mockito.anyString(), Mockito.eq(SERVICE_UNAVAILABLE_EXCEPTION)); Mockito.when(rabbitMqInputProperties.getRetryCount()).thenReturn(3); sut = new RabbitMqDocumentInput(documentReadyHandlerMock, rabbitMqInputProperties); } diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java index fd9f9919..413950cd 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java @@ -18,7 +18,7 @@ import ca.bc.gov.open.api.model.DocumentReceivedResponse; import ca.gov.bc.open.jrccaccess.autoconfigure.plugins.http.DocumentController; import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; public class DocumentControllerTester { @@ -40,11 +40,11 @@ public class DocumentControllerTester { @Before - public void init() throws IOException { + public void init() throws Exception { MockitoAnnotations.initMocks(this); - Mockito.doNothing().when(this.documentReadyHandler).Handle(Mockito.anyString(), Mockito.eq(VALID)); - Mockito.doThrow(new ServiceUnavailableException(SERVICE_UNAVAILABLE)).when(this.documentReadyHandler).Handle(Mockito.anyString(), Mockito.eq(SERVICE_UNAVAILABLE)); + Mockito.doNothing().when(this.documentReadyHandler).handle(Mockito.anyString(), Mockito.eq(VALID)); + Mockito.doThrow(new ServiceUnavailableException(SERVICE_UNAVAILABLE)).when(this.documentReadyHandler).handle(Mockito.anyString(), Mockito.eq(SERVICE_UNAVAILABLE)); Mockito.when(this.resourceWithException.getInputStream()).thenThrow(IOException.class); sut = new DocumentController(this.documentReadyHandler); } diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java index 1f10f0a9..2670104d 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java @@ -24,7 +24,7 @@ public class DocumentReadyHandlerTester { private TransactionInfo transactionInfoMock; @Before - public void init() { + public void init() throws Exception { MockitoAnnotations.initMocks(this); Mockito.doNothing().when(this.documentOutput).send(Mockito.anyString(), Mockito.any()); @@ -34,10 +34,10 @@ public void init() { @Test - public void send_with_valid_input_should_process() { + public void send_with_valid_input_should_process() throws Exception { - sut.Handle("awesome content", "bcgov"); + sut.handle("awesome content", "bcgov"); } diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java index d4e8dd36..f7a04879 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java @@ -28,7 +28,7 @@ public class RabbitMqDocumentOutputTester { private RedisStorageService storageService; @Before - public void init() { + public void init() throws Exception { MockitoAnnotations.initMocks(this); Mockito.doNothing().when(this.documentReadyService).Publish(Mockito.any()); Mockito.when(this.storageService.putString(Mockito.anyString())).thenReturn(new DocumentStorageProperties("key", "A1")); @@ -40,7 +40,7 @@ public void init() { } @Test - public void send_with_valid_input_should_store_and_publish_a_message() { + public void send_with_valid_input_should_store_and_publish_a_message() throws Exception { String content = "my awesome content"; TransactionInfo transactionInfo = new TransactionInfo("testfile.txt", "me", LocalDateTime.now()); this.sut.send(content, transactionInfo); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java index 60b2bc14..21240aa0 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java @@ -22,7 +22,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; @RunWith(SpringRunner.class) @SpringBootTest( @@ -60,21 +60,21 @@ public void init() { } @Test - public void publish_with_valid_input_shoud_publish() { + public void publish_with_valid_input_shoud_publish() throws Exception { sut.Publish(MESSAGE_1); } @Test(expected = ServiceUnavailableException.class) - public void publish_with_AmqpConnectException_shoud_throw_ServiceUnavailableException() { + public void publish_with_AmqpConnectException_shoud_throw_ServiceUnavailableException() throws Exception { sut.Publish(MESSAGE_2); } @Test(expected = ServiceUnavailableException.class) - public void publish_with_AmqpIOException_shoud_throw_ServiceUnavailableException() { + public void publish_with_AmqpIOException_shoud_throw_ServiceUnavailableException() throws Exception { sut.Publish(MESSAGE_3); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java index 3e6066a2..4ca985a9 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java @@ -17,7 +17,7 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.plugins.rabbitmq.RedisStorageService; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; public class RedisStorageServiceTester { @@ -47,7 +47,7 @@ public void Init() { @Test - public void with_valid_content_should_return_document_properties() { + public void with_valid_content_should_return_document_properties() throws Exception { String content = VALID; String myHash = "9F7D0EE82B6A6CA7DDEAE841F3253059"; @@ -69,7 +69,7 @@ public void with_valid_content_should_return_document_properties() { @Test(expected = ServiceUnavailableException.class) - public void with_RedisConnectionFailureException_should_throw_ServiceUnavailableException() { + public void with_RedisConnectionFailureException_should_throw_ServiceUnavailableException() throws Exception { String content = REDIS_CONNECTION_FAILURE_EXCEPTION; diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java index 7cafc53a..dc97be08 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java @@ -1,5 +1,7 @@ package ca.gov.bc.open.jrccaccess.libs; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; + /** * Specification for the document output services * @author alexjoybc @@ -13,7 +15,7 @@ public interface DocumentOutput { * @param documentInfo The document informations * @param transactionInfo The transaction Informations */ - void send(String content, TransactionInfo transactionInfo); + void send(String content, TransactionInfo transactionInfo) throws DocumentMessageException; } diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java index ffec27d5..79a65731 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java @@ -1,6 +1,6 @@ package ca.gov.bc.open.jrccaccess.libs; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * Represents a service to manipulate document ready message diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java index 904ec6f5..33418f78 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java @@ -1,6 +1,6 @@ package ca.gov.bc.open.jrccaccess.libs; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The StorageService interface provides implementation details for the service. diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java new file mode 100644 index 00000000..98d26ea7 --- /dev/null +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java @@ -0,0 +1,24 @@ +package ca.gov.bc.open.jrccaccess.libs.services.exceptions; + +public class DocumentMessageException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -5684913345261766887L; + + public DocumentMessageException() { + super(); + } + + public DocumentMessageException(String message) { + super(message); + } + + public DocumentMessageException(String message, Throwable cause) { + super(message, cause); + } + + + +} diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/ServiceUnavailableException.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/ServiceUnavailableException.java similarity index 89% rename from jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/ServiceUnavailableException.java rename to jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/ServiceUnavailableException.java index a6aa0001..76dca766 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/ServiceUnavailableException.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/ServiceUnavailableException.java @@ -1,4 +1,4 @@ -package ca.gov.bc.open.jrccaccess.libs.services; +package ca.gov.bc.open.jrccaccess.libs.services.exceptions; /** * The {@link RuntimeException} extension to indicate that a service (server) @@ -6,7 +6,7 @@ * @author alexjoybc * @since 0.1.0 */ -public class ServiceUnavailableException extends RuntimeException { +public class ServiceUnavailableException extends DocumentMessageException { private static final long serialVersionUID = 1L; From 147f24e065b02de76ae76240d59ec04f80d8e89b Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 15 Jul 2019 14:10:18 -0700 Subject: [PATCH 2/2] Adding a base Exception to extend into specific exceptions. --- .../plugins/console/ConsoleInput.java | 2 +- .../plugins/http/DocumentController.java | 22 +++++++++------- .../rabbitmq/RabbitMqDocumentInput.java | 25 ++++++------------- .../rabbitmq/RabbitMqDocumentOutput.java | 2 +- .../RabbitMqDocumentReadyService.java | 2 +- .../plugins/rabbitmq/RedisStorageService.java | 2 +- .../services/DocumentReadyHandler.java | 3 ++- .../rabbitmq/RabbitMqDocumentInputTester.java | 4 +-- .../rest/DocumentControllerTester.java | 8 +++--- .../services/DocumentReadyHandlerTester.java | 6 ++--- .../RabbitMqDocumentOutputTester.java | 4 +-- .../RabbitMqDocumentReadyServiceTester.java | 8 +++--- .../services/RedisStorageServiceTester.java | 6 ++--- .../open/jrccaccess/libs/DocumentOutput.java | 4 ++- .../jrccaccess/libs/DocumentReadyService.java | 2 +- .../open/jrccaccess/libs/StorageService.java | 2 +- .../exceptions/DocumentMessageException.java | 24 ++++++++++++++++++ .../ServiceUnavailableException.java | 4 +-- 18 files changed, 75 insertions(+), 55 deletions(-) create mode 100644 jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java rename jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/{ => exceptions}/ServiceUnavailableException.java (89%) diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java index 4e505214..8c05206f 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/console/ConsoleInput.java @@ -40,7 +40,7 @@ public void run(String... args) throws Exception { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { - documentReadyHandler.Handle(scanner.nextLine(), appName); + documentReadyHandler.handle(scanner.nextLine(), appName); } scanner.close(); diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java index 96d94d17..70acc0e6 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/http/DocumentController.java @@ -20,7 +20,8 @@ import ca.bc.gov.open.api.model.DocumentReceivedResponse; import ca.bc.gov.open.api.model.Error; import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The document controller provides an endpoint to submit a document. @@ -59,20 +60,23 @@ public ResponseEntity postDocument(@NotNull @Valid Str response.setAcknowledge(true); try { - documentReadyHandler.Handle(getContent(body.getInputStream()), sender); - } catch (IOException e) { - // TODO Auto-generated catch block - - Error error = new Error(); - error.setCode(Integer.toString(HttpStatus.INTERNAL_SERVER_ERROR.value())); - error.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); - return new ResponseEntity(error, HttpStatus.INTERNAL_SERVER_ERROR); + documentReadyHandler.handle(getContent(body.getInputStream()), sender); + } catch (ServiceUnavailableException e) { Error error = new Error(); error.setCode(Integer.toString(HttpStatus.SERVICE_UNAVAILABLE.value())); error.setMessage(e.getMessage()); return new ResponseEntity(error, HttpStatus.SERVICE_UNAVAILABLE); + + } catch (IOException | DocumentMessageException e) { + // TODO Auto-generated catch block + + Error error = new Error(); + error.setCode(Integer.toString(HttpStatus.INTERNAL_SERVER_ERROR.value())); + error.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()); + return new ResponseEntity(error, HttpStatus.INTERNAL_SERVER_ERROR); + } return ResponseEntity.ok(response); diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java index ac814099..29ab1f4d 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInput.java @@ -13,8 +13,9 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; /** * The RabbitMqDocumentInput handles document from the rabbitMq message listener @@ -71,23 +72,7 @@ public void receiveMessage(DocumentReadyMessage documentReadyMessage, try { - DocumentStorageProperties storageProperties = documentReadyMessage.getDocumentStorageProperties(); - - String key = storageProperties.getKey(); - String digest = storageProperties.getMD5(); - - if(logger.isDebugEnabled()) { - logger.debug("Request Document: key=" + key + ", digest=" + digest); - } - - String content = this.redisStorageService.getString(key, digest); - - if(logger.isDebugEnabled()) { - logger.debug(content); - } - - - this.documentReadyHandler.Handle(content, + this.documentReadyHandler.Handle("not implemented yet", documentReadyMessage.getTransactionInfo().getSender()); logger.info("message successfully acknowledged"); @@ -96,6 +81,10 @@ public void receiveMessage(DocumentReadyMessage documentReadyMessage, logger.warn("Service unavailable exception, message will be put into the dead letter queue."); throw new AmqpRejectAndDontRequeueException(e.getCause()); + } catch (DocumentMessageException e) { + + logger.warn("Service unavailable exception, message will be put into the dead letter queue."); + throw new AmqpRejectAndDontRequeueException(e.getCause()); } } diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java index 1a6498fe..c9cf0880 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentOutput.java @@ -11,7 +11,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The rabbitMqDocumentOutput provides service to send document ready message diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java index 8801265a..083faa97 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentReadyService.java @@ -11,7 +11,7 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.AccessProperties; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentReadyService; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The RabbitMqDocumentReadyService provides services to interact with rabbitMq diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java index a98336c9..95d0c4c6 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RedisStorageService.java @@ -15,7 +15,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.StorageService; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The redisStorageService provides services to interact with Redis cache. diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java index a275c4c5..82a19797 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandler.java @@ -8,6 +8,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentOutput; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; /** * The document ready handler is the global handler for incoming documents @@ -37,7 +38,7 @@ public DocumentReadyHandler(DocumentOutput documentOutput) { * @param inputStream * @param sender */ - public void Handle(String message, String sender) { + public void handle(String message, String sender) throws DocumentMessageException { logger.debug("New document in {}", this.getClass().getName()); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java index 25b5053c..b6f04732 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/plugins/rabbitmq/RabbitMqDocumentInputTester.java @@ -23,7 +23,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; public class RabbitMqDocumentInputTester { @@ -53,7 +53,7 @@ public class RabbitMqDocumentInputTester { private RedisStorageService storageService; @Before - public void init() { + public void init() throws Exception { MockitoAnnotations.initMocks(this); Mockito.doNothing().when(this.documentReadyService).Publish(Mockito.any()); Mockito.doNothing().when(documentReadyHandlerMock).Handle(Mockito.anyString(), Mockito.anyString()); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java index fd9f9919..413950cd 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/rest/DocumentControllerTester.java @@ -18,7 +18,7 @@ import ca.bc.gov.open.api.model.DocumentReceivedResponse; import ca.gov.bc.open.jrccaccess.autoconfigure.plugins.http.DocumentController; import ca.gov.bc.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; public class DocumentControllerTester { @@ -40,11 +40,11 @@ public class DocumentControllerTester { @Before - public void init() throws IOException { + public void init() throws Exception { MockitoAnnotations.initMocks(this); - Mockito.doNothing().when(this.documentReadyHandler).Handle(Mockito.anyString(), Mockito.eq(VALID)); - Mockito.doThrow(new ServiceUnavailableException(SERVICE_UNAVAILABLE)).when(this.documentReadyHandler).Handle(Mockito.anyString(), Mockito.eq(SERVICE_UNAVAILABLE)); + Mockito.doNothing().when(this.documentReadyHandler).handle(Mockito.anyString(), Mockito.eq(VALID)); + Mockito.doThrow(new ServiceUnavailableException(SERVICE_UNAVAILABLE)).when(this.documentReadyHandler).handle(Mockito.anyString(), Mockito.eq(SERVICE_UNAVAILABLE)); Mockito.when(this.resourceWithException.getInputStream()).thenThrow(IOException.class); sut = new DocumentController(this.documentReadyHandler); } diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java index 1f10f0a9..2670104d 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/DocumentReadyHandlerTester.java @@ -24,7 +24,7 @@ public class DocumentReadyHandlerTester { private TransactionInfo transactionInfoMock; @Before - public void init() { + public void init() throws Exception { MockitoAnnotations.initMocks(this); Mockito.doNothing().when(this.documentOutput).send(Mockito.anyString(), Mockito.any()); @@ -34,10 +34,10 @@ public void init() { @Test - public void send_with_valid_input_should_process() { + public void send_with_valid_input_should_process() throws Exception { - sut.Handle("awesome content", "bcgov"); + sut.handle("awesome content", "bcgov"); } diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java index d4e8dd36..f7a04879 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentOutputTester.java @@ -28,7 +28,7 @@ public class RabbitMqDocumentOutputTester { private RedisStorageService storageService; @Before - public void init() { + public void init() throws Exception { MockitoAnnotations.initMocks(this); Mockito.doNothing().when(this.documentReadyService).Publish(Mockito.any()); Mockito.when(this.storageService.putString(Mockito.anyString())).thenReturn(new DocumentStorageProperties("key", "A1")); @@ -40,7 +40,7 @@ public void init() { } @Test - public void send_with_valid_input_should_store_and_publish_a_message() { + public void send_with_valid_input_should_store_and_publish_a_message() throws Exception { String content = "my awesome content"; TransactionInfo transactionInfo = new TransactionInfo("testfile.txt", "me", LocalDateTime.now()); this.sut.send(content, transactionInfo); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java index 60b2bc14..21240aa0 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RabbitMqDocumentReadyServiceTester.java @@ -22,7 +22,7 @@ import ca.gov.bc.open.jrccaccess.libs.DocumentReadyMessage; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; import ca.gov.bc.open.jrccaccess.libs.TransactionInfo; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; @RunWith(SpringRunner.class) @SpringBootTest( @@ -60,21 +60,21 @@ public void init() { } @Test - public void publish_with_valid_input_shoud_publish() { + public void publish_with_valid_input_shoud_publish() throws Exception { sut.Publish(MESSAGE_1); } @Test(expected = ServiceUnavailableException.class) - public void publish_with_AmqpConnectException_shoud_throw_ServiceUnavailableException() { + public void publish_with_AmqpConnectException_shoud_throw_ServiceUnavailableException() throws Exception { sut.Publish(MESSAGE_2); } @Test(expected = ServiceUnavailableException.class) - public void publish_with_AmqpIOException_shoud_throw_ServiceUnavailableException() { + public void publish_with_AmqpIOException_shoud_throw_ServiceUnavailableException() throws Exception { sut.Publish(MESSAGE_3); diff --git a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java index 3e6066a2..4ca985a9 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java +++ b/jrcc-access-spring-boot-autoconfigure/src/test/java/ca/gov/bc/open/jrccaccess/autoconfigure/services/RedisStorageServiceTester.java @@ -17,7 +17,7 @@ import ca.gov.bc.open.jrccaccess.autoconfigure.plugins.rabbitmq.RedisStorageService; import ca.gov.bc.open.jrccaccess.libs.DocumentStorageProperties; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; public class RedisStorageServiceTester { @@ -47,7 +47,7 @@ public void Init() { @Test - public void with_valid_content_should_return_document_properties() { + public void with_valid_content_should_return_document_properties() throws Exception { String content = VALID; String myHash = "9F7D0EE82B6A6CA7DDEAE841F3253059"; @@ -69,7 +69,7 @@ public void with_valid_content_should_return_document_properties() { @Test(expected = ServiceUnavailableException.class) - public void with_RedisConnectionFailureException_should_throw_ServiceUnavailableException() { + public void with_RedisConnectionFailureException_should_throw_ServiceUnavailableException() throws Exception { String content = REDIS_CONNECTION_FAILURE_EXCEPTION; diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java index 7cafc53a..dc97be08 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentOutput.java @@ -1,5 +1,7 @@ package ca.gov.bc.open.jrccaccess.libs; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.DocumentMessageException; + /** * Specification for the document output services * @author alexjoybc @@ -13,7 +15,7 @@ public interface DocumentOutput { * @param documentInfo The document informations * @param transactionInfo The transaction Informations */ - void send(String content, TransactionInfo transactionInfo); + void send(String content, TransactionInfo transactionInfo) throws DocumentMessageException; } diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java index ffec27d5..79a65731 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/DocumentReadyService.java @@ -1,6 +1,6 @@ package ca.gov.bc.open.jrccaccess.libs; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * Represents a service to manipulate document ready message diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java index 246954c0..7fa03f05 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/StorageService.java @@ -1,6 +1,6 @@ package ca.gov.bc.open.jrccaccess.libs; -import ca.gov.bc.open.jrccaccess.libs.services.ServiceUnavailableException; +import ca.gov.bc.open.jrccaccess.libs.services.exceptions.ServiceUnavailableException; /** * The StorageService interface provides implementation details for the service. diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java new file mode 100644 index 00000000..98d26ea7 --- /dev/null +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/DocumentMessageException.java @@ -0,0 +1,24 @@ +package ca.gov.bc.open.jrccaccess.libs.services.exceptions; + +public class DocumentMessageException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -5684913345261766887L; + + public DocumentMessageException() { + super(); + } + + public DocumentMessageException(String message) { + super(message); + } + + public DocumentMessageException(String message, Throwable cause) { + super(message, cause); + } + + + +} diff --git a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/ServiceUnavailableException.java b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/ServiceUnavailableException.java similarity index 89% rename from jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/ServiceUnavailableException.java rename to jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/ServiceUnavailableException.java index a6aa0001..76dca766 100644 --- a/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/ServiceUnavailableException.java +++ b/jrcc-document-access-libs/src/main/java/ca/gov/bc/open/jrccaccess/libs/services/exceptions/ServiceUnavailableException.java @@ -1,4 +1,4 @@ -package ca.gov.bc.open.jrccaccess.libs.services; +package ca.gov.bc.open.jrccaccess.libs.services.exceptions; /** * The {@link RuntimeException} extension to indicate that a service (server) @@ -6,7 +6,7 @@ * @author alexjoybc * @since 0.1.0 */ -public class ServiceUnavailableException extends RuntimeException { +public class ServiceUnavailableException extends DocumentMessageException { private static final long serialVersionUID = 1L;