use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class TxSipServerSbb method createSmsEvent.
// *********
// Messages processing
protected Sms createSmsEvent(String fromUser, byte[] message, TargetAddress ta, PersistenceRAInterface store, byte[] udh, DataCodingSchemeImpl dataCodingScheme, Date validityPeriod, int regDeliveryInt, int networkId) throws SmscProcessingException {
Sms sms = new Sms();
sms.setDbId(UUID.randomUUID());
sms.setOriginationType(OriginationType.SIP);
sms.setRegisteredDelivery(regDeliveryInt);
// checking of source address
if (fromUser == null)
fromUser = "???";
boolean isDigital = true;
for (char ch : fromUser.toCharArray()) {
if (ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && ch != '6' && ch != '7' && ch != '8' && ch != '9' && ch != '*' && ch != '#' && ch != 'a' && ch != 'b' && ch != 'c') {
isDigital = false;
break;
}
}
if (isDigital) {
if (fromUser.length() > 20) {
fromUser = fromUser.substring(0, 20);
}
sms.setSourceAddr(fromUser);
sms.setSourceAddrTon(smscPropertiesManagement.getDefaultTon());
sms.setSourceAddrNpi(smscPropertiesManagement.getDefaultNpi());
} else {
if (fromUser.length() > 11) {
fromUser = fromUser.substring(0, 11);
}
sms.setSourceAddr(fromUser);
sms.setSourceAddrTon(SmppConstants.TON_ALPHANUMERIC);
sms.setSourceAddrNpi(smscPropertiesManagement.getDefaultNpi());
}
int messageingMode = (smscPropertiesManagement.getSipDefaultMessagingMode() & 0x03);
sms.setEsmClass(messageingMode);
sms.setOrigNetworkId(networkId);
// checking for a destination address
isDigital = true;
for (char ch : ta.getAddr().toCharArray()) {
if (ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && ch != '6' && ch != '7' && ch != '8' && ch != '9' && ch != '*' && ch != '#' && ch != 'a' && ch != 'b' && ch != 'c') {
isDigital = false;
break;
}
}
if (!isDigital) {
throw new SmscProcessingException("Destination address contains not only digits, *, #, a, b, or c characters: " + ta.getAddr(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, null);
}
if (ta.getAddr().length() > 20) {
throw new SmscProcessingException("Destination address has too long length: " + ta.getAddr(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, null);
}
if (ta.getAddr().length() == 0) {
throw new SmscProcessingException("Destination address has no digits", SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, null);
}
// processing of a message text
if (message == null)
message = new byte[0];
String msg = new String(message, utf8);
sms.setShortMessageText(msg);
if (udh != null) {
sms.setShortMessageBin(udh);
int esmClass = sms.getEsmClass();
// Add UDH
esmClass = esmClass | 0x40;
sms.setEsmClass(esmClass);
}
sms.setDataCoding(dataCodingScheme.getCode());
// checking max message length
int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, null);
int lenSolid = MessageUtil.getMaxSolidMessageBytesLength();
int lenSegmented = MessageUtil.getMaxSegmentedMessageBytesLength();
// splitting by SMSC is supported for all messages from SIP
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);
}
sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
sms.setPriority(0);
MessageUtil.applyValidityPeriod(sms, validityPeriod, false, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
SmsSet smsSet;
smsSet = new SmsSet();
smsSet.setDestAddr(ta.getAddr());
smsSet.setDestAddrNpi(ta.getAddrNpi());
smsSet.setDestAddrTon(ta.getAddrTon());
smsSet.setNetworkId(networkId);
smsSet.addSms(sms);
sms.setSmsSet(smsSet);
long messageId = store.c2_getNextMessageId();
SmscStatProvider.getInstance().setCurrentMessageId(messageId);
sms.setMessageId(messageId);
return sms;
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class DeliveryCommonSbbTest method testFailureLists.
@Test(groups = { "DeliveryCommonSbb" })
public void testFailureLists() {
if (!this.cassandraDbInited)
return;
SmsSetCache.SMSSET_MSG_PRO_SEGMENT_LIMIT = 3;
DeliveryCommonSbbProxy sbb = initiateSbb(null);
loadSbb(sbb);
SmsSet smsSet = new SmsSet();
for (int i1 = 0; i1 < 20; i1++) {
Sms sms = createSms(i1);
SmsSet smsSet2 = new SmsSet();
smsSet2.addSms(sms);
smsSet.addSmsSet(smsSet2);
}
smsSet.getSms(3).setStoringAfterFailure(true);
smsSet.getSms(5).setStoringAfterFailure(true);
Date curDate = new Date();
int year = curDate.getYear();
smsSet.getSms(1).setStored(true);
// validity period is too far (more then several days)
smsSet.getSms(1).setValidityPeriod(new Date(year + 1, 1, 1));
smsSet.getSms(2).setStored(true);
smsSet.getSms(2).setValidityPeriod(new Date(year - 1, 1, 1));
smsSet.getSms(6).setStored(true);
smsSet.getSms(6).setValidityPeriod(new Date(year - 1, 1, 1));
smsSet.getSms(7).setStored(true);
// validity period is not far - 20 min
smsSet.getSms(7).setValidityPeriod(new Date(curDate.getTime() + 20 * 60 * 1000));
smsSet.getSms(8).setStored(true);
// validity period is not far - 10 min
smsSet.getSms(8).setValidityPeriod(new Date(curDate.getTime() + 10 * 60 * 1000));
sbb.addInitialMessageSet(smsSet);
SmsSetCache.getInstance().addProcessingSmsSet(smsSet.getTargetId(), smsSet, 0);
storeSbb(sbb);
// 02
sbb = initiateSbb(sbb);
loadSbb(sbb);
int cnt = sbb.obtainNextMessagesSendingPool(5, ProcessingType.SMPP);
sbb.registerMessageInSendingPool(0, 100, null);
sbb.registerMessageInSendingPool(1, 101, null);
sbb.registerMessageInSendingPool(2, 102, null);
sbb.registerMessageInSendingPool(3, 103, null);
sbb.registerMessageInSendingPool(4, 104, null);
sbb.endRegisterMessageInSendingPool();
assertEquals(sbb.getCurrentMsgNumValue(), 6);
assertEquals(sbb.getSendingPoolMessageCount(), 5);
assertEquals(sbb.getTotalUnsentMessageCount(), 19);
assertEquals(sbb.getUnconfirmedMessageCountInSendingPool(), 5);
assertEquals(sbb.getMessageInSendingPool(0).getMessageId(), 0);
assertEquals(sbb.getMessageInSendingPool(1).getMessageId(), 1);
assertEquals(sbb.getMessageInSendingPool(2).getMessageId(), 3);
assertEquals(sbb.getMessageInSendingPool(3).getMessageId(), 4);
assertEquals(sbb.getMessageInSendingPool(4).getMessageId(), 5);
assertNull(sbb.getMessageInSendingPool(5));
sbb.confirmMessageInSendingPool(100);
sbb.confirmMessageInSendingPool(102);
ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
ArrayList<Sms> lstTempFailured = new ArrayList<Sms>();
sbb.createFailureLists(lstPermFailured, lstTempFailured, ErrorAction.temporaryFailure, new Date(curDate.getTime() + 30 * 60 * 1000));
assertEquals(lstTempFailured.size(), 3);
assertEquals(lstPermFailured.size(), 14);
assertEquals(lstTempFailured.get(0).getMessageId(), 1);
assertEquals(lstTempFailured.get(1).getMessageId(), 5);
assertEquals(lstTempFailured.get(2).getMessageId(), 7);
assertEquals(lstPermFailured.get(0).getMessageId(), 4);
assertEquals(lstPermFailured.get(1).getMessageId(), 6);
assertEquals(lstPermFailured.get(2).getMessageId(), 8);
assertEquals(lstPermFailured.get(3).getMessageId(), 9);
assertEquals(lstPermFailured.get(13).getMessageId(), 19);
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class DeliveryCommonSbbTest method createSms.
private Sms createSms(int num) {
Sms sms = new Sms();
sms.setDbId(UUID.randomUUID());
sms.setMessageId(num);
return sms;
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class MProcRuleDefaultTest method testTlvOptions.
@Test(groups = { "MProcRule" })
public void testTlvOptions() throws Exception {
Sms sms = new Sms();
MProcRuleDefaultImpl pmr = null;
MProcMessage message = null;
TlvSet tlvSet = null;
// FIXME:add more failing tests
// test tlvbyte_*
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 7 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
pmr = new MProcRuleDefaultImpl();
pmr.setInitialRuleParameters("tlv_byte_1550 7");
assertEquals(pmr.getRuleParameters(), "tlvByte_1550=7", "error");
assertTrue(pmr.matchesPostArrival(message));
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 13 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
assertFalse(pmr.matchesPostArrival(message));
pmr.setInitialRuleParameters("tlv_byte_1550 13");
assertEquals(pmr.getRuleParameters(), "tlvByte_1550=13", "error");
assertTrue(pmr.matchesPostArrival(message));
// test tlvint_*
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 0, 0, 0, 7 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
pmr = new MProcRuleDefaultImpl();
pmr.setInitialRuleParameters("tlv_int_1550 7");
assertEquals(pmr.getRuleParameters(), "tlvInt_1550=7", "error");
assertTrue(pmr.matchesPostArrival(message));
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 0, 0, 0, 13 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
assertFalse(pmr.matchesPostArrival(message));
pmr.setInitialRuleParameters("tlv_int_1550 13");
assertEquals(pmr.getRuleParameters(), "tlvInt_1550=13", "error");
assertTrue(pmr.matchesPostArrival(message));
// test tlvstring_*
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, "7".getBytes()));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
pmr = new MProcRuleDefaultImpl();
pmr.setInitialRuleParameters("tlv_string_1550 7");
assertEquals(pmr.getRuleParameters(), "tlvString_1550=7", "error");
assertTrue(pmr.matchesPostArrival(message));
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, "13".getBytes()));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
assertFalse(pmr.matchesPostArrival(message));
pmr.setInitialRuleParameters("tlv_string_1550 13");
assertEquals(pmr.getRuleParameters(), "tlvString_1550=13", "error");
assertTrue(pmr.matchesPostArrival(message));
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class MProcUtility method createNewCopyMessage.
public static MProcNewMessage createNewCopyMessage(MProcMessage message, boolean backDest, int defaultValidityPeriodHours, int maxValidityPeriodHours) {
MProcMessageImpl msg = (MProcMessageImpl) message;
Sms sms0 = msg.getSmsContent();
Sms sms = new Sms();
sms.setDbId(UUID.randomUUID());
sms.setOrigNetworkId(sms0.getOrigNetworkId());
if (backDest) {
sms.setSourceAddr(sms0.getSmsSet().getDestAddr());
sms.setSourceAddrNpi(sms0.getSmsSet().getDestAddrNpi());
sms.setSourceAddrTon(sms0.getSmsSet().getDestAddrTon());
} else {
sms.setSourceAddr(sms0.getSourceAddr());
sms.setSourceAddrNpi(sms0.getSourceAddrNpi());
sms.setSourceAddrTon(sms0.getSourceAddrTon());
}
sms.setMessageId(sms0.getMessageId());
if (backDest) {
sms.setShortMessageText("???");
sms.setShortMessageBin(null);
} else {
sms.setShortMessageText(sms0.getShortMessageText());
sms.setShortMessageBin(sms0.getShortMessageBin());
}
Date now = new Date();
if (backDest) {
sms.setSubmitDate(now);
sms.setValidityPeriod(addHours(now, defaultValidityPeriodHours));
sms.setScheduleDeliveryTime(null);
} else {
sms.setSubmitDate(sms0.getSubmitDate());
sms.setValidityPeriod(sms0.getValidityPeriod());
sms.setScheduleDeliveryTime(sms0.getScheduleDeliveryTime());
}
sms.setDataCoding(sms0.getDataCoding());
sms.setNationalLanguageLockingShift(sms0.getNationalLanguageLockingShift());
sms.setNationalLanguageSingleShift(sms0.getNationalLanguageSingleShift());
if (backDest) {
sms.setEsmClass(sms0.getEsmClass() & 0x03);
} else {
sms.setEsmClass(sms0.getEsmClass());
}
sms.setPriority(sms0.getPriority());
if (backDest) {
} else {
sms.setRegisteredDelivery(sms0.getRegisteredDelivery());
}
if (backDest) {
} else {
sms.setOrigSystemId(sms0.getOrigSystemId());
sms.setOrigEsmeName(sms0.getOrigEsmeName());
sms.setOriginationType(sms0.getOriginationType());
sms.setMoMessageRef(sms0.getMoMessageRef());
sms.setServiceType(sms0.getServiceType());
sms.setProtocolId(sms0.getProtocolId());
sms.setReplaceIfPresent(sms0.getReplaceIfPresent());
}
if (backDest) {
} else {
sms.setDefaultMsgId(sms0.getDefaultMsgId());
sms.getTlvSet().addAllOptionalParameter(sms0.getTlvSet().getOptionalParameters());
}
SmsSet smsSet = new SmsSet();
if (backDest) {
smsSet.setDestAddr(sms0.getSourceAddr());
smsSet.setDestAddrNpi(sms0.getSourceAddrNpi());
smsSet.setDestAddrTon(sms0.getSourceAddrTon());
} else {
smsSet.setDestAddr(sms0.getSmsSet().getDestAddr());
smsSet.setDestAddrNpi(sms0.getSmsSet().getDestAddrNpi());
smsSet.setDestAddrTon(sms0.getSmsSet().getDestAddrTon());
smsSet.setCorrelationId(sms0.getSmsSet().getCorrelationId());
}
smsSet.setNetworkId(sms0.getSmsSet().getNetworkId());
smsSet.addSms(sms);
return new MProcNewMessageImpl(sms, defaultValidityPeriodHours, maxValidityPeriodHours);
}
Aggregations