| 1 | package fr.sii.ogham.sms.sender.impl; | |
| 2 | ||
| 3 | import static fr.sii.ogham.core.util.LogUtils.logString; | |
| 4 | import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_CLOUDHOPPER_IMPLEMENTATION_PRIORITY; | |
| 5 | ||
| 6 | import org.slf4j.Logger; | |
| 7 | import org.slf4j.LoggerFactory; | |
| 8 | ||
| 9 | import com.cloudhopper.smpp.SmppSession; | |
| 10 | import com.cloudhopper.smpp.pdu.SubmitSm; | |
| 11 | import com.cloudhopper.smpp.type.RecoverablePduException; | |
| 12 | import com.cloudhopper.smpp.type.SmppChannelException; | |
| 13 | import com.cloudhopper.smpp.type.SmppTimeoutException; | |
| 14 | import com.cloudhopper.smpp.type.UnrecoverablePduException; | |
| 15 | ||
| 16 | import fr.sii.ogham.core.builder.priority.Priority; | |
| 17 | import fr.sii.ogham.core.clean.Cleanable; | |
| 18 | import fr.sii.ogham.core.exception.MessageException; | |
| 19 | import fr.sii.ogham.core.exception.clean.CleanException; | |
| 20 | import fr.sii.ogham.core.sender.AbstractSpecializedSender; | |
| 21 | import fr.sii.ogham.sms.message.Sms; | |
| 22 | import fr.sii.ogham.sms.sender.impl.cloudhopper.ExtendedSmppSessionConfiguration; | |
| 23 | import fr.sii.ogham.sms.sender.impl.cloudhopper.exception.SmppException; | |
| 24 | import fr.sii.ogham.sms.sender.impl.cloudhopper.preparator.MessagePreparator; | |
| 25 | import fr.sii.ogham.sms.sender.impl.cloudhopper.session.SessionHandlingStrategy; | |
| 26 | ||
| 27 | /** | |
| 28 | * Implementation based on | |
| 29 | * <a href="https://github.com/twitter/cloudhopper-smpp">cloudhopper-smpp</a> | |
| 30 | * library. | |
| 31 | * | |
| 32 | * @author Aurélien Baudet | |
| 33 | */ | |
| 34 | @Priority(properties="${ogham.sms.implementation-priority.cloudhopper}", defaultValue = DEFAULT_CLOUDHOPPER_IMPLEMENTATION_PRIORITY) | |
| 35 | public class CloudhopperSMPPSender extends AbstractSpecializedSender<Sms> implements Cleanable { | |
| 36 | private static final Logger LOG = LoggerFactory.getLogger(CloudhopperSMPPSender.class); | |
| 37 | | |
| 38 | private final ExtendedSmppSessionConfiguration configuration; | |
| 39 | private final SessionHandlingStrategy sessionHandler; | |
| 40 | private final MessagePreparator messagePreparator; | |
| 41 | | |
| 42 | ||
| 43 | public CloudhopperSMPPSender(ExtendedSmppSessionConfiguration configuration, SessionHandlingStrategy sessionHandler, MessagePreparator messagePreparator) { | |
| 44 | super(); | |
| 45 | this.configuration = configuration; | |
| 46 | this.sessionHandler = sessionHandler; | |
| 47 | this.messagePreparator = messagePreparator; | |
| 48 | } | |
| 49 | ||
| 50 | @Override | |
| 51 | public void send(Sms sms) throws MessageException { | |
| 52 | try { | |
| 53 | LOG.debug("Sending SMS...\n{}", logString(sms)); | |
| 54 | SmppSession session = sessionHandler.getSession(); | |
| 55 | for (SubmitSm msg : messagePreparator.prepareMessages(sms)) { | |
| 56 | session.submit(msg, configuration.getResponseTimeout()); | |
| 57 | } | |
| 58 | LOG.debug("SMS sent\n{}", logString(sms)); | |
| 59 |
4
1. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageSent → NO_COVERAGE 2. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageSent → SURVIVED 3. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageSent → SURVIVED 4. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageSent → TIMED_OUT |
sessionHandler.messageSent(sms); |
| 60 | } catch (SmppException e) { | |
| 61 |
3
1. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageNotSent → NO_COVERAGE 2. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageNotSent → KILLED 3. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageNotSent → KILLED |
sessionHandler.messageNotSent(sms, e); |
| 62 | } catch (UnrecoverablePduException | RecoverablePduException | SmppTimeoutException | SmppChannelException e) { | |
| 63 |
2
1. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageNotSent → NO_COVERAGE 2. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageNotSent → KILLED |
sessionHandler.messageNotSent(sms, new SmppException("Failed to send SMS", e)); |
| 64 | } catch (InterruptedException e) { | |
| 65 |
1
1. send : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
| 66 |
1
1. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageNotSent → NO_COVERAGE |
sessionHandler.messageNotSent(sms, new SmppException("Failed to send SMS (interrupted)", e)); |
| 67 | } finally { | |
| 68 |
4
1. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageProcessed → NO_COVERAGE 2. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageProcessed → SURVIVED 3. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageProcessed → TIMED_OUT 4. send : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::messageProcessed → KILLED |
sessionHandler.messageProcessed(sms); |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | @Override | |
| 73 | public void clean() throws CleanException { | |
| 74 |
4
1. clean : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::clean → SURVIVED 2. clean : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::clean → SURVIVED 3. clean : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::clean → TIMED_OUT 4. clean : removed call to fr/sii/ogham/sms/sender/impl/cloudhopper/session/SessionHandlingStrategy::clean → KILLED |
sessionHandler.clean(); |
| 75 | } | |
| 76 | ||
| 77 | @Override | |
| 78 | public String toString() { | |
| 79 |
3
1. toString : replaced return value with "" for fr/sii/ogham/sms/sender/impl/CloudhopperSMPPSender::toString → SURVIVED 2. toString : replaced return value with "" for fr/sii/ogham/sms/sender/impl/CloudhopperSMPPSender::toString → SURVIVED 3. toString : replaced return value with "" for fr/sii/ogham/sms/sender/impl/CloudhopperSMPPSender::toString → TIMED_OUT |
return "CloudhopperSMPPSender"; |
| 80 | } | |
| 81 | } | |
Mutations | ||
| 59 |
1.1 2.2 3.3 4.4 |
|
| 61 |
1.1 2.2 3.3 |
|
| 63 |
1.1 2.2 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 68 |
1.1 2.2 3.3 4.4 |
|
| 74 |
1.1 2.2 3.3 4.4 |
|
| 79 |
1.1 2.2 3.3 |