aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/smpp
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2018-06-26 09:22:22 +0500
committerAbyss777 <abyss@fox5.ru>2018-06-26 09:22:22 +0500
commitaba402226403f8b3eb58cc01e8f536eb4104d35a (patch)
treeec884994ad90365fa9b385465a80391606f6d970 /src/org/traccar/smpp
parentc700bfdb66071ba224ddf01e9827e721562fed7a (diff)
parent575deac9e2df1cbd0601328f7ea7a9f22029fa43 (diff)
downloadtraccar-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.tar.gz
traccar-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.tar.bz2
traccar-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.zip
Merge remote-tracking branch 'ivanfmartinez/notifications'
# Conflicts: # src/org/traccar/Context.java
Diffstat (limited to 'src/org/traccar/smpp')
-rw-r--r--src/org/traccar/smpp/SmppClient.java60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java
index 967eed82c..d5e6820ab 100644
--- a/src/org/traccar/smpp/SmppClient.java
+++ b/src/org/traccar/smpp/SmppClient.java
@@ -25,6 +25,8 @@ import java.util.concurrent.TimeUnit;
import org.traccar.Context;
import org.traccar.helper.Log;
+import org.traccar.sms.SMSException;
+import org.traccar.sms.SMSManager;
import com.cloudhopper.commons.charset.CharsetUtil;
import com.cloudhopper.smpp.SmppBindType;
@@ -42,7 +44,7 @@ import com.cloudhopper.smpp.type.SmppChannelException;
import com.cloudhopper.smpp.type.SmppTimeoutException;
import com.cloudhopper.smpp.type.UnrecoverablePduException;
-public class SmppClient {
+public class SmppClient implements SMSManager {
private SmppSessionConfiguration sessionConfig = new SmppSessionConfiguration();
private SmppSession smppSession;
@@ -212,46 +214,52 @@ public class SmppClient {
}
}
+ @Override
public synchronized void sendMessageSync(String destAddress, String message, boolean command)
- throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException,
- InterruptedException, IllegalStateException {
+ throws SMSException, InterruptedException, IllegalStateException {
if (getSession() != null && getSession().isBound()) {
- SubmitSm submit = new SubmitSm();
- byte[] textBytes;
- textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
- submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
- if (requestDlr) {
- submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED);
- }
+ try {
+ SubmitSm submit = new SubmitSm();
+ byte[] textBytes;
+ textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
+ submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
+ if (requestDlr) {
+ submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED);
+ }
- if (textBytes != null && textBytes.length > 255) {
- submit.addOptionalParameter(new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, textBytes, "message_payload"));
- } else {
- submit.setShortMessage(textBytes);
- }
+ if (textBytes != null && textBytes.length > 255) {
+ submit.addOptionalParameter(new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, textBytes,
+ "message_payload"));
+ } else {
+ submit.setShortMessage(textBytes);
+ }
- submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress)
- : new Address(sourceTon, sourceNpi, sourceAddress));
- submit.setDestAddress(new Address(destTon, destNpi, destAddress));
- SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout);
- if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) {
- Log.debug("SMS submitted, message id: " + submitResponce.getMessageId());
- } else {
- throw new IllegalStateException(submitResponce.getResultMessage());
+ submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress)
+ : new Address(sourceTon, sourceNpi, sourceAddress));
+ submit.setDestAddress(new Address(destTon, destNpi, destAddress));
+ SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout);
+ if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) {
+ Log.debug("SMS submitted, message id: " + submitResponce.getMessageId());
+ } else {
+ throw new IllegalStateException(submitResponce.getResultMessage());
+ }
+ } catch (SmppChannelException | RecoverablePduException
+ | SmppTimeoutException | UnrecoverablePduException error) {
+ throw new SMSException(error);
}
} else {
- throw new SmppChannelException("SMPP session is not connected");
+ throw new SMSException(new SmppChannelException("SMPP session is not connected"));
}
}
+ @Override
public void sendMessageAsync(final String destAddress, final String message, final boolean command) {
executorService.execute(new Runnable() {
@Override
public void run() {
try {
sendMessageSync(destAddress, message, command);
- } catch (InterruptedException | RecoverablePduException | UnrecoverablePduException
- | SmppTimeoutException | SmppChannelException | IllegalStateException error) {
+ } catch (SMSException | InterruptedException | IllegalStateException error) {
Log.warning(error);
}
}