aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/smpp/SmppClient.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-03-05 20:05:55 +1300
committerGitHub <noreply@github.com>2017-03-05 20:05:55 +1300
commit8163115306af5f82a3c7664daf03e375da3f6a3d (patch)
tree3d52b57791001ca91737c2ab20284cef7b1a0792 /src/org/traccar/smpp/SmppClient.java
parent644d9c440eb193dabeb14ad81c838dbb824bb950 (diff)
parent075307c35605cb6ad9ebbdf547fee8e649507098 (diff)
downloadtrackermap-server-8163115306af5f82a3c7664daf03e375da3f6a3d.tar.gz
trackermap-server-8163115306af5f82a3c7664daf03e375da3f6a3d.tar.bz2
trackermap-server-8163115306af5f82a3c7664daf03e375da3f6a3d.zip
Merge pull request #2971 from Abyss777/sms_commands
Implement SMS commands
Diffstat (limited to 'src/org/traccar/smpp/SmppClient.java')
-rw-r--r--src/org/traccar/smpp/SmppClient.java50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java
index 0bec60fd2..317d6debf 100644
--- a/src/org/traccar/smpp/SmppClient.java
+++ b/src/org/traccar/smpp/SmppClient.java
@@ -60,8 +60,10 @@ public class SmppClient {
private String sourceAddress;
private int submitTimeout;
- private String charsetName;
- private byte dataCoding;
+ private String notificationsCharsetName;
+ private byte notificationsDataCoding;
+ private String commandsCharsetName;
+ private byte commandsDataCoding;
private byte sourceTon;
private byte sourceNpi;
@@ -84,8 +86,15 @@ public class SmppClient {
sourceAddress = Context.getConfig().getString("sms.smpp.sourceAddress", "");
submitTimeout = Context.getConfig().getInteger("sms.smpp.submitTimeout", 10000);
- charsetName = Context.getConfig().getString("sms.smpp.charsetName", CharsetUtil.NAME_UCS_2);
- dataCoding = (byte) Context.getConfig().getInteger("sms.smpp.dataCoding", SmppConstants.DATA_CODING_UCS2);
+ notificationsCharsetName = Context.getConfig().getString("sms.smpp.notificationsCharset",
+ CharsetUtil.NAME_UCS_2);
+ notificationsDataCoding = (byte) Context.getConfig().getInteger("sms.smpp.notificationsDataCoding",
+ SmppConstants.DATA_CODING_UCS2);
+ commandsCharsetName = Context.getConfig().getString("sms.smpp.commandsCharset",
+ CharsetUtil.NAME_GSM);
+ commandsDataCoding = (byte) Context.getConfig().getInteger("sms.smpp.commandsDataCoding",
+ SmppConstants.DATA_CODING_DEFAULT);
+
sourceTon = (byte) Context.getConfig().getInteger("sms.smpp.sourceTon", SmppConstants.TON_ALPHANUMERIC);
sourceNpi = (byte) Context.getConfig().getInteger("sms.smpp.sourceNpi", SmppConstants.NPI_UNKNOWN);
@@ -140,10 +149,10 @@ public class SmppClient {
smppSession = clientBootstrap.bind(sessionConfig, sessionHandler);
stopReconnectionkTask();
runEnquireLinkTask();
- Log.info("Smpp session connected");
+ Log.info("SMPP session connected");
} catch (SmppTimeoutException | SmppChannelException
| UnrecoverablePduException | InterruptedException error) {
- Log.warning("Unable to connect to smpp server: ", error);
+ Log.warning("Unable to connect to SMPP server: ", error);
}
}
@@ -180,37 +189,42 @@ public class SmppClient {
private void destroySession() {
if (smppSession != null) {
- Log.debug("Cleaning up smpp session... ");
+ Log.debug("Cleaning up SMPP session... ");
smppSession.destroy();
smppSession = null;
}
}
- public synchronized void sendMessageSync(String destAddress, String message) throws RecoverablePduException,
- UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
+ public synchronized void sendMessageSync(String destAddress, String message, boolean command)
+ throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException,
+ InterruptedException, IllegalStateException {
if (getSession() != null && getSession().isBound()) {
- byte[] textBytes = CharsetUtil.encode(message, charsetName);
-
SubmitSm submit = new SubmitSm();
+ byte[] textBytes;
+ textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
+ submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
+ submit.setShortMessage(textBytes);
submit.setSourceAddress(new Address(sourceTon, sourceNpi, sourceAddress));
submit.setDestAddress(new Address(destTon, destNpi, destAddress));
- submit.setDataCoding(dataCoding);
- submit.setShortMessage(textBytes);
SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout);
- Log.debug("SMS submited, msg_id: " + submitResponce.getMessageId());
+ if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) {
+ Log.debug("SMS submitted, message id: " + submitResponce.getMessageId());
+ } else {
+ throw new IllegalStateException(submitResponce.getResultMessage());
+ }
} else {
- throw new SmppChannelException("Smpp session is not connected");
+ throw new SmppChannelException("SMPP session is not connected");
}
}
- public void sendMessageAsync(final String destAddress, final String message) {
+ public void sendMessageAsync(final String destAddress, final String message, final boolean command) {
executorService.execute(new Runnable() {
@Override
public void run() {
try {
- sendMessageSync(destAddress, message);
+ sendMessageSync(destAddress, message, command);
} catch (InterruptedException | RecoverablePduException | UnrecoverablePduException
- | SmppTimeoutException | SmppChannelException error) {
+ | SmppTimeoutException | SmppChannelException | IllegalStateException error) {
Log.warning(error);
}
}