aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/smpp/SmppClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/smpp/SmppClient.java')
-rw-r--r--src/org/traccar/smpp/SmppClient.java47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java
index 3680d20e2..bef2abbf6 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);
@@ -184,31 +193,41 @@ public class SmppClient {
}
}
- 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;
+ if (command) {
+ textBytes = CharsetUtil.encode(message, commandsCharsetName);
+ submit.setDataCoding(commandsDataCoding);
+ } else {
+ textBytes = CharsetUtil.encode(message, notificationsCharsetName);
+ submit.setDataCoding(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 submited, msg_id: " + submitResponce.getMessageId());
+ } else {
+ throw new IllegalStateException(submitResponce.getResultMessage());
+ }
} else {
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);
}
}