aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/smpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/smpp')
-rw-r--r--src/org/traccar/smpp/ClientSmppSessionHandler.java8
-rw-r--r--src/org/traccar/smpp/SmppClient.java50
2 files changed, 36 insertions, 22 deletions
diff --git a/src/org/traccar/smpp/ClientSmppSessionHandler.java b/src/org/traccar/smpp/ClientSmppSessionHandler.java
index 721243f9f..2a538a40f 100644
--- a/src/org/traccar/smpp/ClientSmppSessionHandler.java
+++ b/src/org/traccar/smpp/ClientSmppSessionHandler.java
@@ -44,14 +44,14 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler {
try {
if (request instanceof DeliverSm) {
if (request.getOptionalParameters() != null) {
- Log.debug("Message Delivered: "
+ Log.debug("SMS Message Delivered: "
+ request.getOptionalParameter(SmppConstants.TAG_RECEIPTED_MSG_ID).getValueAsString()
+ ", State: "
+ request.getOptionalParameter(SmppConstants.TAG_MSG_STATE).getValueAsByte());
} else {
- Log.debug("Message Received: "
+ Log.debug("SMS Message Received: "
+ CharsetUtil.decode(((DeliverSm) request).getShortMessage(),
- smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding()))
+ smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding())).trim()
+ ", Source Address: "
+ ((DeliverSm) request).getSourceAddress().getAddress());
}
@@ -68,7 +68,7 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler {
@Override
public void fireChannelUnexpectedlyClosed() {
- Log.warning("Smpp session channel unexpectedly closed");
+ Log.warning("SMPP session channel unexpectedly closed");
smppClient.scheduleReconnect();
}
}
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);
}
}