| 1 | package fr.sii.ogham.core.service; | |
| 2 | ||
| 3 | import fr.sii.ogham.core.exception.MessagingException; | |
| 4 | import fr.sii.ogham.core.exception.MessagingRuntimeException; | |
| 5 | import fr.sii.ogham.core.message.Message; | |
| 6 | ||
| 7 | /** | |
| 8 | * Decorator that catch all exceptions including {@link RuntimeException}. It | |
| 9 | * translates any exceptions into {@link MessagingException}. | |
| 10 | * | |
| 11 | * @author Aurélien Baudet | |
| 12 | */ | |
| 13 | public class WrapExceptionMessagingService implements MessagingService { | |
| 14 | /** | |
| 15 | * The delegate service that will really send messages | |
| 16 | */ | |
| 17 | private MessagingService delegate; | |
| 18 | ||
| 19 | public WrapExceptionMessagingService(MessagingService delegate) { | |
| 20 | super(); | |
| 21 | this.delegate = delegate; | |
| 22 | } | |
| 23 | ||
| 24 | /** | |
| 25 | * Sends the message. The message can be anything with any content and that | |
| 26 | * must be delivered to something or someone. | |
| 27 | * | |
| 28 | * If there is any exception, it caught and translated in | |
| 29 | * {@link MessagingException}. | |
| 30 | * | |
| 31 | * @param message | |
| 32 | * the message to send | |
| 33 | * @throws MessagingException | |
| 34 | * when the message couldn't be sent | |
| 35 | */ | |
| 36 | @Override | |
| 37 | @SuppressWarnings("squid:S2221") | |
| 38 | public void send(Message message) throws MessagingException { | |
| 39 | try { | |
| 40 |
6
1. send : removed call to fr/sii/ogham/core/service/MessagingService::send → NO_COVERAGE 2. send : removed call to fr/sii/ogham/core/service/MessagingService::send → TIMED_OUT 3. send : removed call to fr/sii/ogham/core/service/MessagingService::send → KILLED 4. send : removed call to fr/sii/ogham/core/service/MessagingService::send → KILLED 5. send : removed call to fr/sii/ogham/core/service/MessagingService::send → KILLED 6. send : removed call to fr/sii/ogham/core/service/MessagingService::send → KILLED |
delegate.send(message); |
| 41 | } catch (MessagingException e) { | |
| 42 | throw e; // this is wanted to avoid wrapping MessagingException with | |
| 43 | // MessagingException | |
| 44 | } catch (MessagingRuntimeException e) { | |
| 45 | throw new MessagingException("Message can't be sent due to technical exception. Cause: " + e.getMessage(), e); | |
| 46 | } catch (IllegalArgumentException e) { | |
| 47 | throw new MessagingException("Message can't be sent due to precondition not met. Cause: " + e.getMessage(), e); | |
| 48 | } catch (IllegalStateException e) { | |
| 49 | throw new MessagingException("Message can't be sent due to some illegal use. Cause: " + e.getMessage(), e); | |
| 50 | } catch (Exception e) { | |
| 51 | throw new MessagingException("Message can't be sent due to uncaught exception. Cause: " + e.getMessage(), e); | |
| 52 | } | |
| 53 | } | |
| 54 | } | |
Mutations | ||
| 40 |
1.1 2.2 3.3 4.4 5.5 6.6 |