1 | package fr.sii.ogham.testing.sms.simulator.jsmpp; | |
2 | ||
3 | import java.util.Date; | |
4 | ||
5 | import org.jsmpp.bean.DataCodings; | |
6 | import org.jsmpp.bean.DeliveryReceipt; | |
7 | import org.jsmpp.bean.ESMClass; | |
8 | import org.jsmpp.bean.GSMSpecificFeature; | |
9 | import org.jsmpp.bean.MessageMode; | |
10 | import org.jsmpp.bean.MessageType; | |
11 | import org.jsmpp.bean.NumberingPlanIndicator; | |
12 | import org.jsmpp.bean.RegisteredDelivery; | |
13 | import org.jsmpp.bean.SubmitMulti; | |
14 | import org.jsmpp.bean.SubmitSm; | |
15 | import org.jsmpp.bean.TypeOfNumber; | |
16 | import org.jsmpp.extra.SessionState; | |
17 | import org.jsmpp.session.SMPPServerSession; | |
18 | import org.jsmpp.util.DeliveryReceiptState; | |
19 | import org.jsmpp.util.MessageId; | |
20 | import org.slf4j.Logger; | |
21 | import org.slf4j.LoggerFactory; | |
22 | ||
23 | class DeliveryReceiptTask implements Runnable { | |
24 | private static final int TWO_BYTES = 16; | |
25 | ||
26 | private static final Logger LOG = LoggerFactory.getLogger(DeliveryReceiptTask.class); | |
27 | ||
28 | private final SMPPServerSession session; | |
29 | private final MessageId messageId; | |
30 | ||
31 | private final TypeOfNumber sourceAddrTon; | |
32 | private final NumberingPlanIndicator sourceAddrNpi; | |
33 | private final String sourceAddress; | |
34 | ||
35 | private final TypeOfNumber destAddrTon; | |
36 | private final NumberingPlanIndicator destAddrNpi; | |
37 | private final String destAddress; | |
38 | ||
39 | private final int totalSubmitted; | |
40 | private final int totalDelivered; | |
41 | ||
42 | private final byte[] shortMessage; | |
43 | ||
44 | public DeliveryReceiptTask(SMPPServerSession session, SubmitSm submitSm, MessageId messageId) { | |
45 | this.session = session; | |
46 | this.messageId = messageId; | |
47 | ||
48 | // reversing destination to source | |
49 | sourceAddrTon = TypeOfNumber.valueOf(submitSm.getDestAddrTon()); | |
50 | sourceAddrNpi = NumberingPlanIndicator.valueOf(submitSm.getDestAddrNpi()); | |
51 | sourceAddress = submitSm.getDestAddress(); | |
52 | ||
53 | // reversing source to destination | |
54 | destAddrTon = TypeOfNumber.valueOf(submitSm.getSourceAddrTon()); | |
55 | destAddrNpi = NumberingPlanIndicator.valueOf(submitSm.getSourceAddrNpi()); | |
56 | destAddress = submitSm.getSourceAddr(); | |
57 | ||
58 | totalSubmitted = totalDelivered = 1; | |
59 | ||
60 | shortMessage = submitSm.getShortMessage(); | |
61 | } | |
62 | ||
63 | public DeliveryReceiptTask(SMPPServerSession session, SubmitMulti submitMulti, MessageId messageId) { | |
64 | this.session = session; | |
65 | this.messageId = messageId; | |
66 | ||
67 | // set to unknown and null, since it was submit_multi | |
68 | sourceAddrTon = TypeOfNumber.UNKNOWN; | |
69 | sourceAddrNpi = NumberingPlanIndicator.UNKNOWN; | |
70 | sourceAddress = null; | |
71 | ||
72 | // reversing source to destination | |
73 | destAddrTon = TypeOfNumber.valueOf(submitMulti.getSourceAddrTon()); | |
74 | destAddrNpi = NumberingPlanIndicator.valueOf(submitMulti.getSourceAddrNpi()); | |
75 | destAddress = submitMulti.getSourceAddr(); | |
76 | ||
77 | // distribution list assumed only contains single address | |
78 | totalSubmitted = totalDelivered = submitMulti.getDestAddresses().length; | |
79 | ||
80 | shortMessage = submitMulti.getShortMessage(); | |
81 | } | |
82 | ||
83 | public void run() { | |
84 | SessionState state = session.getSessionState(); | |
85 |
2
1. run : negated conditional → NO_COVERAGE 2. run : negated conditional → TIMED_OUT |
if (!state.isReceivable()) { |
86 | LOG.debug("Not sending delivery receipt for message id {} since session state is {}", messageId, state); | |
87 | return; | |
88 | } | |
89 | String stringValue = Integer.valueOf(messageId.getValue(), TWO_BYTES).toString(); | |
90 | try { | |
91 | ||
92 | DeliveryReceipt delRec = new DeliveryReceipt(stringValue, totalSubmitted, totalDelivered, new Date(), new Date(), DeliveryReceiptState.DELIVRD, null, new String(shortMessage)); | |
93 |
2
1. run : removed call to org/jsmpp/session/SMPPServerSession::deliverShortMessage → NO_COVERAGE 2. run : removed call to org/jsmpp/session/SMPPServerSession::deliverShortMessage → TIMED_OUT |
session.deliverShortMessage("mc", sourceAddrTon, sourceAddrNpi, sourceAddress, destAddrTon, destAddrNpi, destAddress, new ESMClass(MessageMode.DEFAULT, |
94 | MessageType.SMSC_DEL_RECEIPT, GSMSpecificFeature.DEFAULT), (byte) 0, (byte) 0, new RegisteredDelivery(0), DataCodings.ZERO, delRec.toString().getBytes()); | |
95 | LOG.debug("Sending delivery receipt for message id {}: {}", messageId, stringValue); | |
96 | } catch (Exception e) { | |
97 | LOG.error("Failed sending delivery_receipt for message id {}: {}", messageId, stringValue, e); | |
98 | } | |
99 | } | |
100 | } | |
Mutations | ||
85 |
1.1 2.2 |
|
93 |
1.1 2.2 |