use of com.cloudhopper.smpp.type.Address in project smscgateway by RestComm.
the class TxSmppServerSbbTest method testSubmitMulti.
@Test(groups = { "TxSmppServer" })
public void testSubmitMulti() throws Exception {
if (!this.cassandraDbInited)
return;
this.smppSess = new SmppSessionsProxy();
this.sbb.setSmppServerSessions(smppSess);
int windowSize = SmppConstants.DEFAULT_WINDOW_SIZE;
long connectTimeout = SmppConstants.DEFAULT_CONNECT_TIMEOUT;
long clientBindTimeout = SmppConstants.DEFAULT_BIND_TIMEOUT;
long requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
long windowMonitorInterval = SmppConstants.DEFAULT_WINDOW_MONITOR_INTERVAL;
long windowWaitTimeout = SmppConstants.DEFAULT_WINDOW_WAIT_TIMEOUT;
Esme esme = new Esme("Esme_1", "Esme_systemId_1", "pwd", "host", 0, false, null, SmppInterfaceVersionType.SMPP34, -1, -1, null, SmppBindType.TRANSCEIVER, SmppSession.Type.CLIENT, windowSize, connectTimeout, requestExpiryTimeout, clientBindTimeout, windowMonitorInterval, windowWaitTimeout, "Esme_1", true, 30000, 0, 0, -1, -1, "^[0-9a-zA-Z]*", -1, -1, "^[0-9a-zA-Z]*", 0, false, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1);
ActivityContextInterface aci = new SmppTransactionProxy(esme);
SubmitMulti event = new SubmitMulti();
Date curDate = new Date();
this.fillSm(event, curDate, true);
event.setShortMessage(msgUcs2);
Address destAddr = new Address();
destAddr.setAddress("5555");
destAddr.setTon(SmppConstants.TON_INTERNATIONAL);
destAddr.setNpi(SmppConstants.NPI_E164);
event.addDestAddresses(destAddr);
Address destAddr2 = new Address();
destAddr2.setAddress("5556");
destAddr2.setTon(SmppConstants.TON_INTERNATIONAL);
destAddr2.setNpi(SmppConstants.NPI_E164);
event.addDestAddresses(destAddr2);
long dueSlot = this.pers.c2_getDueSlotForTime(scheduleDeliveryTime);
PreparedStatementCollection psc = this.pers.getStatementCollection(scheduleDeliveryTime);
int b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
long b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
assertEquals(b1, 0);
assertEquals(b2, 0L);
b1 = this.pers.checkSmsExists(dueSlot, ta2.getTargetId());
b2 = this.pers.c2_getDueSlotForTargetId(psc, ta2.getTargetId());
assertEquals(b1, 0);
assertEquals(b2, 0L);
TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Unicode);
this.sbb.onSubmitMulti(event, aci);
b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
assertEquals(b1, 1);
b1 = this.pers.checkSmsExists(dueSlot, ta2.getTargetId());
assertEquals(b1, 1);
SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
this.checkSmsSet(smsSet, curDate, true);
Sms sms = smsSet.getSms(0);
// msgUcs2
assertEquals(sms.getShortMessageText(), sMsg);
assertEquals(sms.getShortMessageBin(), udhCode);
assertEquals(this.smppSess.getReqList().size(), 0);
assertEquals(this.smppSess.getRespList().size(), 1);
SubmitMultiResp resp = (SubmitMultiResp) this.smppSess.getRespList().get(0);
assertEquals(resp.getCommandStatus(), 0);
assertEquals(resp.getOptionalParameterCount(), 0);
assertEquals(resp.getUnsucessfulSmes().size(), 0);
}
use of com.cloudhopper.smpp.type.Address in project smscgateway by RestComm.
the class RxSmppServerSbb method sendDeliverSm.
// *********
// Main service methods
/**
* Sending of a set of messages after initial message or when all sent messages was sent
*
* @param smsSet
* @throws SmscProcessingException
*/
private void sendDeliverSm(SmsSet smsSet) throws SmscProcessingException {
try {
int deliveryMsgCnt = this.obtainNextMessagesSendingPool(maxMessagesPerStep, ProcessingType.SMPP);
if (deliveryMsgCnt == 0) {
this.markDeliveringIsEnded(true);
return;
}
EsmeManagement esmeManagement = EsmeManagement.getInstance();
Esme esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
if (esme == null) {
String s = "RxSmppServerSbb.sendDeliverSm(): Received DELIVER_SM SmsEvent but no Esme found for destClusterName: " + smsSet.getDestClusterName() + ", smsSet=" + smsSet;
logger.warning(s);
this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SC_SYSTEM_ERROR, s, EventType.OUT_SMPP_ERROR, -1);
return;
}
smsSet.setDestSystemId(esme.getSystemId());
smsSet.setDestEsmeName(esme.getName());
List<ChunkData> pendingMessages = new ArrayList<ChunkData>();
boolean destAddressLimitationEnabled = esme.getDestAddrSendLimit() != 0;
for (int poolIndex = 0; poolIndex < deliveryMsgCnt; poolIndex++) {
smscStatAggregator.updateMsgOutTryAll();
smscStatAggregator.updateMsgOutTrySmpp();
Sms sms = this.getMessageInSendingPool(poolIndex);
if (sms == null) {
// this should not be
throw new SmscProcessingException("sendDeliverSm: getCurrentMessage() returns null sms for msgNum in SendingPool " + poolIndex, 0, 0, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_SEND_DELIVER_SM_000007);
}
sms.setTimestampA(System.currentTimeMillis());
// message splitting staff
boolean esmeAllowSplitting = esme.getSplitLongMessages();
int esmClass = sms.getEsmClass();
boolean udhPresent = (esmClass & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
Tlv sarMsgRefNum = sms.getTlvSet().getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
Tlv sarTotalSegments = sms.getTlvSet().getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
Tlv sarSegmentSeqnum = sms.getTlvSet().getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
boolean sarTlvPresent = sarMsgRefNum != null && sarTotalSegments != null && sarSegmentSeqnum != null;
ArrayList<String> lstStrings = new ArrayList<String>();
ArrayList<byte[]> lstUdhs = new ArrayList<byte[]>();
lstStrings.add(sms.getShortMessageText());
lstUdhs.add(sms.getShortMessageBin());
if (esmeAllowSplitting && !udhPresent && !sarTlvPresent) {
DataCodingScheme dataCodingScheme = this.mapSmsTpduParameterFactory.createDataCodingScheme(sms.getDataCoding());
String[] segmentsStrings = MessageUtil.sliceMessage(sms.getShortMessageText(), dataCodingScheme, sms.getNationalLanguageLockingShift(), sms.getNationalLanguageSingleShift());
if (segmentsStrings != null && segmentsStrings.length > 1) {
// we need to split a message for segments
lstStrings.clear();
lstUdhs.clear();
int messageReferenceNumber = getNextMessageReferenceNumber();
esmClass |= SmppConstants.ESM_CLASS_UDHI_MASK;
int messageSegmentCount = segmentsStrings.length;
for (int ii1 = 0; ii1 < messageSegmentCount; ii1++) {
lstStrings.add(segmentsStrings[ii1]);
byte[] bf1 = new byte[7];
// total UDH length
bf1[0] = 6;
// UDH id
bf1[1] = UserDataHeader._InformationElementIdentifier_ConcatenatedShortMessages16bit;
// UDH length
bf1[2] = 4;
bf1[3] = (byte) (messageReferenceNumber & 0x00FF);
bf1[4] = (byte) ((messageReferenceNumber & 0xFF00) >> 8);
// segmCnt
bf1[5] = (byte) messageSegmentCount;
// segmNum
bf1[6] = (byte) (ii1 + 1);
lstUdhs.add(bf1);
}
}
}
int sequenceNumber = 0;
int[] sequenceNumberExt = null;
int segmCnt = lstStrings.size();
if (segmCnt > 1) {
sequenceNumberExt = new int[segmCnt - 1];
}
for (int segmentIndex = 0; segmentIndex < segmCnt; segmentIndex++) {
if (esme.getSmppSessionType() == Type.CLIENT) {
SubmitSm submitSm = new SubmitSm();
submitSm.setSourceAddress(new Address((byte) sms.getSourceAddrTon(), (byte) sms.getSourceAddrNpi(), sms.getSourceAddr()));
submitSm.setDestAddress(new Address((byte) sms.getSmsSet().getDestAddrTon(), (byte) sms.getSmsSet().getDestAddrNpi(), sms.getSmsSet().getDestAddr()));
submitSm.setEsmClass((byte) esmClass);
submitSm.setProtocolId((byte) sms.getProtocolId());
submitSm.setPriority((byte) sms.getPriority());
if (sms.getScheduleDeliveryTime() != null) {
submitSm.setScheduleDeliveryTime(MessageUtil.printSmppAbsoluteDate(sms.getScheduleDeliveryTime(), -(new Date()).getTimezoneOffset()));
}
if (sms.getValidityPeriod() != null) {
submitSm.setValidityPeriod(MessageUtil.printSmppAbsoluteDate(sms.getValidityPeriod(), -(new Date()).getTimezoneOffset()));
}
submitSm.setRegisteredDelivery((byte) sms.getRegisteredDelivery());
submitSm.setReplaceIfPresent((byte) sms.getReplaceIfPresent());
submitSm.setDataCoding((byte) sms.getDataCoding());
String msgStr = lstStrings.get(segmentIndex);
byte[] msgUdh = lstUdhs.get(segmentIndex);
if (msgStr != null || msgUdh != null) {
byte[] msg = recodeShortMessage(sms.getDataCoding(), msgStr, msgUdh);
if (msg.length <= 255) {
submitSm.setShortMessage(msg);
} else {
Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, msg, null);
submitSm.addOptionalParameter(tlv);
}
}
for (Tlv tlv : sms.getTlvSet().getOptionalParameters()) {
submitSm.addOptionalParameter(tlv);
}
int currLocalSequenceNumber = getLastLocalSequenceNumber();
if (currLocalSequenceNumber == Integer.MAX_VALUE)
setLastLocalSequenceNumber(0);
else
setLastLocalSequenceNumber(currLocalSequenceNumber + 1);
ChunkData currData = new ChunkData(submitSm, currLocalSequenceNumber);
int sentSequenceNumber = currData.getLocalSequenceNumber();
if (destAddressLimitationEnabled) {
pendingMessages.add(currData);
} else {
SentItem sentItem = sendNextChunk(currData, smsSet, esme);
long t = System.currentTimeMillis();
sms.setTimestampB(t);
sentSequenceNumber = sentItem.getRemoteSequenceNumber();
sms.putMsgPartDeliveryTime(sentSequenceNumber, t);
}
if (logger.isInfoEnabled()) {
logger.info(String.format("Sent submitSm to ESME: %s, msgNumInSendingPool: %d, sms=%s", esme.getName(), poolIndex, sms.toString()));
}
if (segmentIndex == 0) {
sequenceNumber = sentSequenceNumber;
} else {
sequenceNumberExt[segmentIndex - 1] = sentSequenceNumber;
}
} else {
DeliverSm deliverSm = new DeliverSm();
deliverSm.setSourceAddress(new Address((byte) sms.getSourceAddrTon(), (byte) sms.getSourceAddrNpi(), sms.getSourceAddr()));
deliverSm.setDestAddress(new Address((byte) sms.getSmsSet().getDestAddrTon(), (byte) sms.getSmsSet().getDestAddrNpi(), sms.getSmsSet().getDestAddr()));
deliverSm.setEsmClass((byte) esmClass);
deliverSm.setProtocolId((byte) sms.getProtocolId());
deliverSm.setPriority((byte) sms.getPriority());
if (sms.getScheduleDeliveryTime() != null) {
deliverSm.setScheduleDeliveryTime(MessageUtil.printSmppAbsoluteDate(sms.getScheduleDeliveryTime(), -(new Date()).getTimezoneOffset()));
}
if (sms.getValidityPeriod() != null && esme.getSmppVersion() == SmppInterfaceVersionType.SMPP50) {
deliverSm.setValidityPeriod(MessageUtil.printSmppAbsoluteDate(sms.getValidityPeriod(), -(new Date()).getTimezoneOffset()));
}
deliverSm.setRegisteredDelivery((byte) sms.getRegisteredDelivery());
deliverSm.setReplaceIfPresent((byte) sms.getReplaceIfPresent());
deliverSm.setDataCoding((byte) sms.getDataCoding());
String msgStr = lstStrings.get(segmentIndex);
byte[] msgUdh = lstUdhs.get(segmentIndex);
if (msgStr != null || msgUdh != null) {
byte[] msg = recodeShortMessage(sms.getDataCoding(), msgStr, msgUdh);
if (msg.length <= 255) {
deliverSm.setShortMessage(msg);
} else {
Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, msg, null);
deliverSm.addOptionalParameter(tlv);
}
}
for (Tlv tlv : sms.getTlvSet().getOptionalParameters()) {
deliverSm.addOptionalParameter(tlv);
}
// TODO : waiting for 2 secs for window to accept our
// request,
// is it good? Should time be more here?
int currLocalSequenceNumber = getLastLocalSequenceNumber();
if (currLocalSequenceNumber == Integer.MAX_VALUE)
setLastLocalSequenceNumber(0);
else
setLastLocalSequenceNumber(currLocalSequenceNumber + 1);
ChunkData currData = new ChunkData(deliverSm, currLocalSequenceNumber);
int sentSequenceNumber = currData.getLocalSequenceNumber();
if (destAddressLimitationEnabled) {
pendingMessages.add(currData);
} else {
SentItem sentItem = sendNextChunk(currData, smsSet, esme);
long t = System.currentTimeMillis();
sms.setTimestampB(t);
sentSequenceNumber = sentItem.getRemoteSequenceNumber();
sms.putMsgPartDeliveryTime(sentSequenceNumber, t);
}
if (logger.isInfoEnabled()) {
logger.info(String.format("Sent deliverSm to ESME: %s, msgNumInSendingPool: %d, sms=%s", esme.getName(), poolIndex, sms.toString()));
}
if (segmentIndex == 0) {
sequenceNumber = sentSequenceNumber;
} else {
sequenceNumberExt[segmentIndex - 1] = sentSequenceNumber;
}
}
}
this.registerMessageInSendingPool(poolIndex, sequenceNumber, sequenceNumberExt);
}
this.endRegisterMessageInSendingPool();
if (destAddressLimitationEnabled) {
ChunkDataList pendingChunks = retreivePendingChunks();
pendingChunks.getPendingList().addAll(pendingMessages);
SentItemsList sentChunks = retreiveSentChunks();
int pdusToSendSize = pendingChunks.getPendingList().size();
int allowedSendWindowSize = esme.getDestAddrSendLimit() - sentChunks.getSentList().size();
if (allowedSendWindowSize < pdusToSendSize)
pdusToSendSize = allowedSendWindowSize;
List<ChunkData> pdusToSend = new ArrayList<ChunkData>();
for (int i = 0; i < pdusToSendSize; i++) {
pdusToSend.add(pendingChunks.getPendingList().remove(0));
}
setPendingChunks(pendingChunks);
ArrayList<SentItem> sentResults = new ArrayList<SentItem>();
while (pdusToSend.size() > 0) {
SentItem result = sendNextChunk(pdusToSend.remove(0), smsSet, esme);
if (result != null)
sentResults.add(result);
}
if (!sentResults.isEmpty()) {
sentChunks.getSentList().addAll(sentResults);
setSentChunks(sentChunks);
}
}
} catch (Throwable e) {
throw new SmscProcessingException("RxSmppServerSbb.sendDeliverSm(): Exception while trying to send DELIVERY Report for received SmsEvent=" + e.getMessage() + "smsSet: " + smsSet, 0, 0, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_SEND_DELIVER_SM_000008);
}
}
use of com.cloudhopper.smpp.type.Address in project traccar by tananaev.
the class SmppClient method sendMessageSync.
public synchronized void sendMessageSync(String destAddress, String message, boolean command) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, 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);
}
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());
}
} else {
throw new SmppChannelException("SMPP session is not connected");
}
}
use of com.cloudhopper.smpp.type.Address in project load-balancer by RestComm.
the class ConfigInit method getSubmitSm.
static SubmitSm getSubmitSm() throws SmppInvalidArgumentException {
String text160 = "Hello world!";
byte[] textBytes = CharsetUtil.encode(text160, CharsetUtil.CHARSET_GSM);
SubmitSm submit = new SubmitSm();
submit.setSourceAddress(new Address((byte) 0x03, (byte) 0x00, "40404"));
submit.setDestAddress(new Address((byte) 0x01, (byte) 0x01, "44555519205"));
submit.setShortMessage(textBytes);
return submit;
}
use of com.cloudhopper.smpp.type.Address in project smscgateway by RestComm.
the class TxSmppServerSbb method createSmsEventMulti.
protected SubmitMultiParseResult createSmsEventMulti(SubmitMulti event, Esme origEsme, PersistenceRAInterface store, int networkId) throws SmscProcessingException {
List<Address> addrList = event.getDestAddresses();
if (addrList == null || addrList.size() == 0) {
throw new SmscProcessingException("For received SubmitMulti no DestAddresses found: ", SmppConstants.STATUS_INVDLNAME, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_DST_ADDR_INVALID);
}
if (event.getSourceAddress() == null || event.getSourceAddress().getAddress() == null || event.getSourceAddress().getAddress().isEmpty()) {
throw new SmscProcessingException("SourceAddress digits are absent", SmppConstants.STATUS_INVSRCADR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_SRC_ADDR_INVALID);
}
// checking parameters first
String sourceAddr = event.getSourceAddress().getAddress();
int sourceAddrTon = event.getSourceAddress().getTon();
int sourceAddrNpi = event.getSourceAddress().getNpi();
int dcs = event.getDataCoding();
String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
if (err != null) {
throw new SmscProcessingException("TxSmpp DataCoding scheme does not supported: " + dcs + " - " + err, SmppExtraConstants.ESME_RINVDCS, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_DATA_CODING_INVALID);
}
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
Tlv sarMsgRefNum = event.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
Tlv sarTotalSegments = event.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
Tlv sarSegmentSeqnum = event.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
boolean segmentTlvFlag = (sarMsgRefNum != null && sarTotalSegments != null && sarSegmentSeqnum != null);
// short message data
byte[] data = event.getShortMessage();
if (event.getShortMessageLength() == 0) {
// Probably the message_payload Optional Parameter is being used
Tlv messagePaylod = event.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
if (messagePaylod != null) {
data = messagePaylod.getValue();
}
}
if (data == null) {
data = new byte[0];
}
byte[] udhData;
byte[] textPart;
String msg;
udhData = null;
textPart = data;
if (udhPresent && data.length > 2) {
// UDH exists
int udhLen = (textPart[0] & 0xFF) + 1;
if (udhLen <= textPart.length) {
textPart = new byte[textPart.length - udhLen];
udhData = new byte[udhLen];
System.arraycopy(data, udhLen, textPart, 0, textPart.length);
System.arraycopy(data, 0, udhData, 0, udhLen);
}
}
msg = parseShortMessageText(event);
// checking max message length
int nationalLanguageLockingShift = 0;
int nationalLanguageSingleShift = 0;
if (udhPresent || segmentTlvFlag) {
// here splitting by SMSC is not supported
UserDataHeader udh = null;
int lenSolid = MessageUtil.getMaxSolidMessageBytesLength();
if (udhPresent)
udh = new UserDataHeaderImpl(udhData);
else {
udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
if (udh != null && udh.getNationalLanguageLockingShift() != null) {
lenSolid -= 3;
nationalLanguageLockingShift = udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode();
}
if (udh != null && udh.getNationalLanguageSingleShift() != null) {
lenSolid -= 3;
nationalLanguageSingleShift = udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode();
}
}
int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
if (udhData != null)
messageLen += udhData.length;
if (messageLen > lenSolid) {
throw new SmscProcessingException("Message length in bytes is too big for solid message: " + messageLen + ">" + lenSolid, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
}
} else {
// here splitting by SMSC is supported
int lenSegmented = MessageUtil.getMaxSegmentedMessageBytesLength();
if (msg.length() * 2 > (lenSegmented - 6) * 255) {
// firstly draft length check
UserDataHeader udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
if (udh != null && udh.getNationalLanguageLockingShift() != null) {
lenSegmented -= 3;
nationalLanguageLockingShift = udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode();
}
if (udh != null && udh.getNationalLanguageSingleShift() != null) {
lenSegmented -= 3;
nationalLanguageSingleShift = udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode();
}
if (messageLen > lenSegmented * 255) {
throw new SmscProcessingException("Message length in bytes is too big for segmented message: " + messageLen + ">" + lenSegmented, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
}
}
}
// ValidityPeriod processing
Tlv tlvQosTimeToLive = event.getOptionalParameter(SmppConstants.TAG_QOS_TIME_TO_LIVE);
Date validityPeriod;
if (tlvQosTimeToLive != null) {
long valTime;
try {
valTime = (new Date()).getTime() + tlvQosTimeToLive.getValueAsInt();
} catch (TlvConvertException e) {
throw new SmscProcessingException("TlvConvertException when getting TAG_QOS_TIME_TO_LIVE tlv field: " + e.getMessage(), SmppConstants.STATUS_INVOPTPARAMVAL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
}
validityPeriod = new Date(valTime);
} else {
try {
validityPeriod = MessageUtil.parseSmppDate(event.getValidityPeriod());
} catch (ParseException e) {
throw new SmscProcessingException("ParseException when parsing ValidityPeriod field: " + e.getMessage(), SmppConstants.STATUS_INVEXPIRY, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
}
}
// ScheduleDeliveryTime processing
Date scheduleDeliveryTime;
try {
scheduleDeliveryTime = MessageUtil.parseSmppDate(event.getScheduleDeliveryTime());
} catch (ParseException e) {
throw new SmscProcessingException("ParseException when parsing ScheduleDeliveryTime field: " + e.getMessage(), SmppConstants.STATUS_INVSCHED, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_SCHEDULER_DELIVERY_TIME_PARSING);
}
long messageId = store.c2_getNextMessageId();
SmscStatProvider.getInstance().setCurrentMessageId(messageId);
ArrayList<Sms> msgList = new ArrayList<Sms>(addrList.size());
ArrayList<UnsucessfulSME> badAddresses = new ArrayList<UnsucessfulSME>(addrList.size());
for (Address address : addrList) {
boolean succAddr = false;
TargetAddress ta = null;
try {
ta = createDestTargetAddress(address, networkId);
succAddr = true;
} catch (SmscProcessingException e) {
Address addr = (Address) e.getExtraErrorData();
if (addr != null) {
UnsucessfulSME asme = new UnsucessfulSME(e.getSmppErrorCode(), addr);
badAddresses.add(asme);
}
}
if (succAddr) {
Sms sms = new Sms();
sms.setDbId(UUID.randomUUID());
sms.setOriginationType(OriginationType.SMPP);
sms.setSourceAddr(sourceAddr);
sms.setSourceAddrTon(sourceAddrTon);
sms.setSourceAddrNpi(sourceAddrNpi);
sms.setOrigNetworkId(networkId);
sms.setDataCoding(dcs);
sms.setNationalLanguageLockingShift(nationalLanguageLockingShift);
sms.setNationalLanguageSingleShift(nationalLanguageSingleShift);
sms.setOrigSystemId(origEsme.getSystemId());
sms.setOrigEsmeName(origEsme.getName());
sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
sms.setServiceType(event.getServiceType());
sms.setEsmClass(event.getEsmClass());
sms.setProtocolId(event.getProtocolId());
sms.setPriority(event.getPriority());
sms.setRegisteredDelivery(event.getRegisteredDelivery());
sms.setReplaceIfPresent(event.getReplaceIfPresent());
sms.setDefaultMsgId(event.getDefaultMsgId());
sms.setShortMessageText(msg);
sms.setShortMessageBin(udhData);
MessageUtil.applyValidityPeriod(sms, validityPeriod, true, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
MessageUtil.applyScheduleDeliveryTime(sms, scheduleDeliveryTime);
// storing additional parameters
ArrayList<Tlv> optionalParameters = event.getOptionalParameters();
if (optionalParameters != null && optionalParameters.size() > 0) {
for (Tlv tlv : optionalParameters) {
if (tlv.getTag() != SmppConstants.TAG_MESSAGE_PAYLOAD) {
sms.getTlvSet().addOptionalParameter(tlv);
}
}
}
SmsSet smsSet;
smsSet = new SmsSet();
smsSet.setDestAddr(ta.getAddr());
smsSet.setDestAddrNpi(ta.getAddrNpi());
smsSet.setDestAddrTon(ta.getAddrTon());
smsSet.setNetworkId(origEsme.getNetworkId());
smsSet.addSms(sms);
sms.setSmsSet(smsSet);
sms.setMessageId(messageId);
msgList.add(sms);
}
}
return new SubmitMultiParseResult(msgList, badAddresses);
}
Aggregations