use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.
the class MtTest method SuccessDeliveryBTest.
/**
* MAP V3, 1 message, 1 segment, GSM7
* 160 chars including [] -> 2 segments
*/
@Test(groups = { "Mt" })
public void SuccessDeliveryBTest() throws Exception {
if (!this.cassandraDbInited)
return;
MAPServiceSmsProxy serviceSri = (MAPServiceSmsProxy) this.sriSbb.mapProvider.getMAPServiceSms();
MAPServiceSmsProxy serviceMt = (MAPServiceSmsProxy) this.mtSbb.mapProvider.getMAPServiceSms();
MAPServiceSmsProxy serviceRsds = (MAPServiceSmsProxy) this.rsdsSbb.mapProvider.getMAPServiceSms();
SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
MProcManagement.getInstance("Test");
ArrayList<SmsDef> lst = new ArrayList<SmsDef>();
SmsDef sd1 = new SmsDef();
lst.add(sd1);
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i1 = 0; i1 < 15; i1++) {
sb.append(" 123456789");
}
sb.append(" 1234567]");
String totalMsg = sb.toString();
// int segmlen = MessageUtil.getMaxSegmentedMessageBytesLength(new DataCodingSchemeImpl(8)) / 2;
String msga1 = totalMsg.substring(0, 151);
String msga2 = totalMsg.substring(151);
sd1.msg = totalMsg;
sd1.dataCodingScheme = 0;
SmsSet smsSet = prepareDatabase(lst);
Sms sms1 = smsSet.getSms(0);
UUID smsId = sms1.getDbId();
SmsProxy smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId);
assertNull(smsx1);
SmsSet smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
assertNotNull(smsSetX);
Sms smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[0]);
assertEquals(smsX.getSmsSet().getInSystem(), 0);
assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 1);
// initial onSms message
SmsSetEvent event = new SmsSetEvent();
event.setSmsSet(smsSet);
this.sriSbb.onSms(event, null, null);
MAPDialogSmsProxy dlg = serviceSri.getLastMAPDialogSms();
MAPApplicationContextVersion acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version3);
ArrayList<MAPTestEvent> lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
assertNull(serviceMt.getLastMAPDialogSms());
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
assertEquals(dlg.getLocalAddress().getGlobalTitle().getDigits(), smscPropertiesManagement.getServiceCenterGt());
assertEquals(dlg.getRemoteAddress().getGlobalTitle().getDigits(), msdnDig);
MAPTestEvent evt = lstEvt.get(0);
assertEquals(evt.testEventType, MAPTestEventType.componentAdded);
SendRoutingInfoForSMRequest sriReq = (SendRoutingInfoForSMRequest) evt.event;
assertEquals(sriReq.getMsisdn().getAddress(), msdnDig);
assertEquals(sriReq.getServiceCentreAddress().getAddress(), smscPropertiesManagement.getServiceCenterGt());
evt = lstEvt.get(1);
assertEquals(evt.testEventType, MAPTestEventType.send);
// SRI response
IMSI imsi = new IMSIImpl(imsiDig);
ISDNAddressString networkNodeNumber = new ISDNAddressStringImpl(AddressNature.international_number, org.restcomm.protocols.ss7.map.api.primitives.NumberingPlan.ISDN, nnnDig);
LocationInfoWithLMSI locationInfoWithLMSI = new LocationInfoWithLMSIImpl(networkNodeNumber, null, null, false, null);
SendRoutingInfoForSMResponse evt1 = new SendRoutingInfoForSMResponseImpl(imsi, locationInfoWithLMSI, null, true, null);
evt1.setMAPDialog(dlg);
this.sriSbb.onSendRoutingInfoForSMResponse(evt1, null);
this.sriSbb.onDialogDelimiter(null, null);
dlg = serviceMt.getLastMAPDialogSms();
acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version3);
lstEvt = dlg.getEventList();
// Empty TC-BEGIN for MAP V3
assertEquals(lstEvt.size(), 3);
evt = lstEvt.get(0);
assertEquals(evt.testEventType, MAPTestEventType.componentAdded);
evt = lstEvt.get(1);
assertEquals(evt.testEventType, MAPTestEventType.cancelInvoke);
evt = lstEvt.get(2);
assertEquals(evt.testEventType, MAPTestEventType.send);
// Empty TC-CONTINUE
DialogDelimiter evt6 = new DialogDelimiter(dlg);
this.mtSbb.onDialogDelimiter(evt6, null);
dlg = serviceMt.getLastMAPDialogSms();
acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version3);
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 5);
evt = lstEvt.get(3);
assertEquals(evt.testEventType, MAPTestEventType.componentAdded);
MtForwardShortMessageRequestImpl mtFsmReq = (MtForwardShortMessageRequestImpl) evt.event;
assertTrue(mtFsmReq.getMoreMessagesToSend());
SM_RP_DA sm_RP_DA = mtFsmReq.getSM_RP_DA();
IMSI daImsi = sm_RP_DA.getIMSI();
assertEquals(daImsi.getData(), imsiDig);
SM_RP_OA sm_RP_OA = mtFsmReq.getSM_RP_OA();
AddressString scas = sm_RP_OA.getServiceCentreAddressOA();
assertEquals(scas.getAddress(), smscPropertiesManagement.getServiceCenterGt());
SmsSignalInfo ssi = mtFsmReq.getSM_RP_UI();
SmsDeliverTpdu tpdu = (SmsDeliverTpdu) ssi.decodeTpdu(false);
assertEquals(tpdu.getDataCodingScheme().getCode(), 0);
assertFalse(tpdu.getForwardedOrSpawned());
assertTrue(tpdu.getMoreMessagesToSend());
assertEquals(tpdu.getOriginatingAddress().getAddressValue(), origDig);
assertFalse(tpdu.getReplyPathExists());
assertEquals(tpdu.getSmsTpduType(), SmsTpduType.SMS_DELIVER);
assertFalse(tpdu.getStatusReportIndication());
assertTrue(tpdu.getUserDataHeaderIndicator());
UserData ud = tpdu.getUserData();
ud.decode();
UserDataHeader udh = ud.getDecodedUserDataHeader();
ConcatenatedShortMessagesIdentifier csm = udh.getConcatenatedShortMessagesIdentifier();
assertEquals(csm.getReference(), 1);
assertEquals(csm.getMesageSegmentCount(), 2);
assertEquals(csm.getMesageSegmentNumber(), 1);
String msg1 = ud.getDecodedMessage();
assertEquals(msg1, msga1);
evt = lstEvt.get(4);
assertEquals(evt.testEventType, MAPTestEventType.send);
smsId = sms1.getDbId();
smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId);
assertNull(smsx1);
smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
assertNotNull(smsSetX);
smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[0]);
assertEquals(smsX.getSmsSet().getInSystem(), 0);
assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 1);
// Mt response 1
MtForwardShortMessageResponseImpl evt2 = new MtForwardShortMessageResponseImpl(null, null);
evt2.setMAPDialog(dlg);
DialogAccept daevt = new DialogAccept(dlg, null);
this.mtSbb.onDialogAccept(daevt, null);
this.mtSbb.onMtForwardShortMessageResponse(evt2, null);
DialogClose dcl = new DialogClose(dlg);
this.mtSbb.onDialogClose(dcl, null);
dlg = serviceMt.getLastMAPDialogSms();
acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version3);
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
evt = lstEvt.get(0);
assertEquals(evt.testEventType, MAPTestEventType.componentAdded);
mtFsmReq = (MtForwardShortMessageRequestImpl) evt.event;
assertFalse(mtFsmReq.getMoreMessagesToSend());
sm_RP_DA = mtFsmReq.getSM_RP_DA();
daImsi = sm_RP_DA.getIMSI();
assertEquals(daImsi.getData(), imsiDig);
sm_RP_OA = mtFsmReq.getSM_RP_OA();
scas = sm_RP_OA.getServiceCentreAddressOA();
assertEquals(scas.getAddress(), smscPropertiesManagement.getServiceCenterGt());
ssi = mtFsmReq.getSM_RP_UI();
tpdu = (SmsDeliverTpdu) ssi.decodeTpdu(false);
assertEquals(tpdu.getDataCodingScheme().getCode(), 0);
assertFalse(tpdu.getForwardedOrSpawned());
assertFalse(tpdu.getMoreMessagesToSend());
assertEquals(tpdu.getOriginatingAddress().getAddressValue(), origDig);
assertFalse(tpdu.getReplyPathExists());
assertEquals(tpdu.getSmsTpduType(), SmsTpduType.SMS_DELIVER);
assertFalse(tpdu.getStatusReportIndication());
assertTrue(tpdu.getUserDataHeaderIndicator());
ud = tpdu.getUserData();
ud.decode();
udh = ud.getDecodedUserDataHeader();
csm = udh.getConcatenatedShortMessagesIdentifier();
assertEquals(csm.getReference(), 1);
assertEquals(csm.getMesageSegmentCount(), 2);
assertEquals(csm.getMesageSegmentNumber(), 2);
String msg2 = ud.getDecodedMessage();
assertEquals(msg2, msga2);
evt = lstEvt.get(1);
assertEquals(evt.testEventType, MAPTestEventType.send);
smsId = sms1.getDbId();
smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId);
assertNull(smsx1);
smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
assertNotNull(smsSetX);
smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[0]);
assertEquals(smsX.getSmsSet().getInSystem(), 0);
assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 1);
// Mt response 2
evt2 = new MtForwardShortMessageResponseImpl(null, null);
evt2.setMAPDialog(dlg);
daevt = new DialogAccept(dlg, null);
this.mtSbb.onDialogAccept(daevt, null);
this.mtSbb.onMtForwardShortMessageResponse(evt2, null);
dcl = new DialogClose(dlg);
this.mtSbb.onDialogClose(dcl, null);
dlg = serviceRsds.getLastMAPDialogSms();
assertNull(dlg);
dlg = serviceSri.getLastMAPDialogSms();
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
dlg = serviceMt.getLastMAPDialogSms();
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
smsId = sms1.getDbId();
smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId);
assertNotNull(smsx1);
smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
assertNull(smsSetX);
smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[0]);
assertNull(smsX);
assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 0);
}
use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.
the class DBOperations method createSms.
protected SmsSet createSms(final Row row, SmsSet smsSet, boolean shortMessageNewStringFormat, boolean addedCorrId, boolean addedNetworkId, boolean addedOrigNetworkId, boolean addedPacket1, boolean getMessageInProcessing) throws PersistenceException {
if (row == null) {
return smsSet;
}
int inSystem = row.getInt(Schema.COLUMN_IN_SYSTEM);
UUID smscUuid = row.getUUID(Schema.COLUMN_SMSC_UUID);
if (!getMessageInProcessing && (inSystem == IN_SYSTEM_SENT || inSystem == IN_SYSTEM_INPROCESS && smscUuid.equals(currentSessionUUID))) {
// inSystem it is in processing or processed - skip this
return smsSet;
}
Sms sms = new Sms();
sms.setStored(true);
sms.setDbId(row.getUUID(Schema.COLUMN_ID));
sms.setDueSlot(row.getLong(Schema.COLUMN_DUE_SLOT));
sms.setSourceAddr(row.getString(Schema.COLUMN_ADDR_SRC_DIGITS));
sms.setSourceAddrTon(row.getInt(Schema.COLUMN_ADDR_SRC_TON));
sms.setSourceAddrNpi(row.getInt(Schema.COLUMN_ADDR_SRC_NPI));
if (addedOrigNetworkId) {
sms.setOrigNetworkId(row.getInt(Schema.COLUMN_ORIG_NETWORK_ID));
}
sms.setMessageId(row.getLong(Schema.COLUMN_MESSAGE_ID));
sms.setMoMessageRef(row.getInt(Schema.COLUMN_MO_MESSAGE_REF));
sms.setOrigEsmeName(row.getString(Schema.COLUMN_ORIG_ESME_NAME));
sms.setOrigSystemId(row.getString(Schema.COLUMN_ORIG_SYSTEM_ID));
sms.setSubmitDate(getRowDate(row, Schema.COLUMN_SUBMIT_DATE));
sms.setServiceType(row.getString(Schema.COLUMN_SERVICE_TYPE));
sms.setEsmClass(row.getInt(Schema.COLUMN_ESM_CLASS));
sms.setProtocolId(row.getInt(Schema.COLUMN_PROTOCOL_ID));
sms.setPriority(row.getInt(Schema.COLUMN_PRIORITY));
sms.setRegisteredDelivery(row.getInt(Schema.COLUMN_REGISTERED_DELIVERY));
sms.setReplaceIfPresent(row.getInt(Schema.COLUMN_REPLACE));
sms.setDataCodingForDatabase(row.getInt(Schema.COLUMN_DATA_CODING));
sms.setDefaultMsgId(row.getInt(Schema.COLUMN_DEFAULT_MSG_ID));
if (shortMessageNewStringFormat) {
sms.setShortMessageText(row.getString(Schema.COLUMN_MESSAGE_TEXT));
ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE_BIN);
if (bb != null) {
byte[] buf = new byte[bb.limit() - bb.position()];
bb.get(buf);
sms.setShortMessageBin(buf);
}
} else {
ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE);
if (bb != null) {
byte[] buf = new byte[bb.limit() - bb.position()];
bb.get(buf);
sms.setShortMessage(buf);
// convert to a new format
byte[] shortMessage = sms.getShortMessage();
byte[] textPart = shortMessage;
byte[] udhData = null;
boolean udhExists = false;
DataCodingScheme dcs = new DataCodingSchemeImpl(sms.getDataCoding());
String msg = null;
if (dcs.getCharacterSet() == CharacterSet.GSM8) {
udhData = shortMessage;
} else {
if ((sms.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0) {
udhExists = true;
}
if (udhExists && shortMessage != null && shortMessage.length > 2) {
// UDH exists
int udhLen = (shortMessage[0] & 0xFF) + 1;
if (udhLen <= shortMessage.length) {
textPart = new byte[shortMessage.length - udhLen];
udhData = new byte[udhLen];
System.arraycopy(shortMessage, udhLen, textPart, 0, textPart.length);
System.arraycopy(shortMessage, 0, udhData, 0, udhLen);
}
}
switch(dcs.getCharacterSet()) {
case GSM7:
msg = new String(textPart);
break;
case UCS2:
Charset ucs2Charset = Charset.forName("UTF-16BE");
bb = ByteBuffer.wrap(textPart);
CharBuffer bf = ucs2Charset.decode(bb);
msg = bf.toString();
break;
default:
udhData = sms.getShortMessage();
break;
}
}
sms.setShortMessageText(msg);
sms.setShortMessageBin(udhData);
}
}
sms.setScheduleDeliveryTime(getRowDate(row, Schema.COLUMN_SCHEDULE_DELIVERY_TIME));
sms.setValidityPeriod(getRowDate(row, Schema.COLUMN_VALIDITY_PERIOD));
sms.setDeliveryCount(row.getInt(Schema.COLUMN_DELIVERY_COUNT));
if (addedPacket1) {
sms.setOriginatorSccpAddress(row.getString(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS));
// TODO: extra columns for further usage
sms.setStatusReportRequest(row.getBool(Schema.COLUMN_STATUS_REPORT_REQUEST));
sms.setDeliveryAttempt(row.getInt(Schema.COLUMN_DELIVERY_ATTEMPT));
sms.setUserData(row.getString(Schema.COLUMN_USER_DATA));
sms.setExtraData(row.getString(Schema.COLUMN_EXTRA_DATA));
sms.setExtraData_2(row.getString(Schema.COLUMN_EXTRA_DATA_2));
sms.setExtraData_3(row.getString(Schema.COLUMN_EXTRA_DATA_3));
sms.setExtraData_4(row.getString(Schema.COLUMN_EXTRA_DATA_4));
}
String s = row.getString(Schema.COLUMN_OPTIONAL_PARAMETERS);
if (s != null) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
XMLObjectReader reader = XMLObjectReader.newInstance(bais);
TlvSet copy = reader.read(TLV_SET, TlvSet.class);
sms.getTlvSet().clearAllOptionalParameter();
sms.getTlvSet().addAllOptionalParameter(copy.getOptionalParameters());
} catch (XMLStreamException e) {
String msg = "XMLStreamException when deserializing optional parameters for '" + sms.getDbId() + "'!";
throw new PersistenceException(msg, e);
}
}
if (smsSet == null) {
smsSet = new SmsSet();
String destAddr = null;
int destAddrTon = -1;
int destAddrNpi = -1;
destAddr = row.getString(Schema.COLUMN_ADDR_DST_DIGITS);
destAddrTon = row.getInt(Schema.COLUMN_ADDR_DST_TON);
destAddrNpi = row.getInt(Schema.COLUMN_ADDR_DST_NPI);
if (destAddr == null || destAddrTon == -1 || destAddrNpi == -1) {
throw new PersistenceException("destAddr or destAddrTon or destAddrNpi is absent for ID='" + sms.getDbId() + "'");
}
smsSet.setDestAddr(destAddr);
smsSet.setDestAddrTon(destAddrTon);
smsSet.setDestAddrNpi(destAddrNpi);
if (getMessageInProcessing) {
smsSet.setInSystem(inSystem);
smsSet.setStatus(ErrorCode.fromInt(row.getInt(Schema.COLUMN_SM_STATUS)));
}
if (addedNetworkId) {
smsSet.setNetworkId(row.getInt(Schema.COLUMN_NETWORK_ID));
} else {
String tagId = row.getString(Schema.COLUMN_TARGET_ID);
if (tagId != null) {
String[] ss = tagId.split("_");
if (ss.length == 4) {
String s1 = ss[3];
try {
int networkId = Integer.parseInt(s1);
smsSet.setNetworkId(networkId);
} catch (Exception e) {
}
}
}
}
if (addedCorrId)
smsSet.setCorrelationId(row.getString(Schema.COLUMN_CORR_ID));
else
smsSet.setCorrelationId(row.getString(Schema.COLUMN_IMSI));
}
int dueDelay = row.getInt(Schema.COLUMN_DUE_DELAY);
if (dueDelay > smsSet.getDueDelay())
smsSet.setDueDelay(dueDelay);
boolean alertingSupported = row.getBool(Schema.COLUMN_ALERTING_SUPPORTED);
if (alertingSupported)
smsSet.setAlertingSupported(true);
smsSet.addSms(sms);
return smsSet;
}
use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.
the class CdrGenerator method generateCdr.
public static void generateCdr(Sms smsEvent, String status, String reason, boolean generateReceiptCdr, boolean generateCdr, boolean messageIsSplitted, boolean lastSegment, boolean calculateMsgPartsLenCdr, boolean delayParametersInCdr, int seqNumber) {
if (!generateCdr)
return;
if (!generateReceiptCdr && smsEvent.isMcDeliveryReceipt())
// we do not generate CDR's for receipt if generateReceiptCdr option is off
return;
int msgParts = 0, charNumbers = 0;
if (calculateMsgPartsLenCdr) {
if (messageIsSplitted) {
msgParts = 1;
} else {
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(smsEvent.getDataCoding());
msgParts = MessageUtil.calculateMsgParts(smsEvent.getShortMessageText(), dataCodingScheme, smsEvent.getNationalLanguageLockingShift(), smsEvent.getNationalLanguageSingleShift());
}
if (lastSegment) {
charNumbers = smsEvent.getShortMessageText().length();
} else {
charNumbers = 0;
}
}
int dcs = smsEvent.getDataCoding();
Long receiptLocalMessageId = smsEvent.getReceiptLocalMessageId();
long msgPartDelTime = -1;
if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber - 1)) {
msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getMsgPartDelTime(seqNumber - 1);
} else if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber)) {
msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getSubmitDate().getTime();
}
DeliveryReceiptData deliveryReceiptData = MessageUtil.parseDeliveryReceipt(smsEvent.getShortMessageText(), smsEvent.getTlvSet());
String st = null;
int tlvMessageState = -1;
int err = -1;
if (deliveryReceiptData != null) {
st = deliveryReceiptData.getStatus();
tlvMessageState = deliveryReceiptData.getTlvMessageState() == null ? -1 : deliveryReceiptData.getTlvMessageState();
err = deliveryReceiptData.getError();
}
StringBuffer sb = new StringBuffer();
sb.append(DATE_FORMAT.format(smsEvent.getSubmitDate())).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(status).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginationType()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getReceiptLocalMessageId() == null ? "message" : "dlr").append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigSystemId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getDlvMessageId()).append(CdrGenerator.CDR_SEPARATOR).append((receiptLocalMessageId != null && receiptLocalMessageId == -1) ? "xxxx" : smsEvent.getReceiptLocalMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getLocationInfoWithLMSI() != null ? smsEvent.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddress() : null).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getImsi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getCorrelationId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginatorSccpAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMtServiceCenterAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMprocNotes()).append(CdrGenerator.CDR_SEPARATOR).append(msgParts).append(CdrGenerator.CDR_SEPARATOR).append(charNumbers).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getProcessingTime(smsEvent.getSubmitDate()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getScheduleDeliveryDelayMilis(smsEvent.getSubmitDate(), smsEvent.getScheduleDeliveryTime()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? smsEvent.getDeliveryCount() : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(msgPartDelTime != -1 ? msgPartDelTime : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(dcs).append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(getFirst20CharOfSMS(smsEvent.getShortMessageText()))).append("\"").append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(reason)).append("\"").append(CdrGenerator.CDR_SEPARATOR).append(st != null ? st : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(tlvMessageState != -1 ? tlvMessageState : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(err != -1 ? err : CdrGenerator.CDR_EMPTY);
CdrGenerator.generateCdr(sb.toString());
}
use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.
the class MessageUtil method sliceMessage.
public static String[] sliceMessage(String msg, DataCodingScheme dataCodingScheme, int nationalLanguageLockingShift, int nationalLanguageSingleShift) {
int lenSolid = MessageUtil.getMaxSolidMessageCharsLength(dataCodingScheme);
int lenSegmented = MessageUtil.getMaxSegmentedMessageCharsLength(dataCodingScheme);
UserDataHeader udh = null;
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7 && (nationalLanguageLockingShift > 0 || nationalLanguageSingleShift > 0)) {
udh = MessageUtil.getNationalLanguageIdentifierUdh(nationalLanguageLockingShift, nationalLanguageSingleShift);
if (nationalLanguageLockingShift > 0) {
lenSolid -= 3;
lenSegmented -= 3;
}
if (nationalLanguageSingleShift > 0) {
lenSolid -= 3;
lenSegmented -= 3;
}
}
int msgLenInChars = msg.length();
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7 && msgLenInChars * 2 > lenSolid) {
// GSM7 data coding. We need to care if some characters occupy two char places
msgLenInChars = UserDataImpl.checkEncodedDataLengthInChars(msg, udh);
}
if (msgLenInChars <= lenSolid) {
String[] res = new String[] { msg };
return res;
} else {
if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
String[] res = UserDataImpl.sliceString(msg, lenSegmented, udh);
return res;
} else {
ArrayList<String> res = new ArrayList<String>();
int segmCnt = (msg.length() - 1) / lenSegmented + 1;
for (int i1 = 0; i1 < segmCnt; i1++) {
if (i1 == segmCnt - 1) {
res.add(msg.substring(i1 * lenSegmented, msg.length()));
} else {
res.add(msg.substring(i1 * lenSegmented, (i1 + 1) * lenSegmented));
}
}
String[] ress = new String[res.size()];
res.toArray(ress);
return ress;
}
}
}
use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.
the class SmppTestingForm method submitMessage.
private void submitMessage(EncodingType encodingType, int messageClass, String messageText, SplittingType splittingType, ValidityType validityType, String destAddr, SmppSimulatorParameters.MessagingMode messagingMode, int specifiedSegmentLength) {
if (session0 == null)
return;
try {
int dcs = 0;
ArrayList<byte[]> msgLst = new ArrayList<byte[]>();
int msgRef = 0;
switch(encodingType) {
case GSM7_DCS_0:
dcs = 0;
break;
case GSM8_DCS_4:
dcs = 4;
break;
case UCS2_DCS_8:
dcs = 8;
break;
}
// if (messageClass) {
// dcs += 16;
// }
int messageClassVal = 0;
if (messageClass > 0) {
messageClassVal = messageClass;
}
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
int maxLen = MessageUtil.getMaxSolidMessageCharsLength(dataCodingScheme);
int maxSplLen = MessageUtil.getMaxSegmentedMessageCharsLength(dataCodingScheme);
if (splittingType == SplittingType.SplitWithParameters_SpecifiedSegmentLength || splittingType == SplittingType.SplitWithUdh_SpecifiedSegmentLength) {
maxLen = specifiedSegmentLength;
maxSplLen = specifiedSegmentLength;
}
int segmCnt = 0;
int esmClass = 0;
boolean addSegmTlv = false;
if (messageText.length() > maxLen) {
// may be message splitting
SplittingType st = splittingType;
switch(st) {
case DoNotSplit:
// we do not split
byte[] buf1 = encodeSegment(messageText, encodingType);
byte[] buf2;
if (encodingType == EncodingType.GSM8_DCS_4) {
// 4-bytes length
byte[] bf3 = new byte[7];
// total UDH length
bf3[0] = 6;
// UDH id
bf3[1] = 5;
// UDH length
bf3[2] = 4;
bf3[3] = 0x3E;
bf3[4] = (byte) 0x94;
bf3[5] = 0;
bf3[6] = 0;
// 0-bytes length
// bf3 = new byte[3];
// bf3[0] = 2; // total UDH length
// bf3[1] = 112; // UDH id
// bf3[2] = 0; // UDH length
buf2 = new byte[bf3.length + buf1.length];
System.arraycopy(bf3, 0, buf2, 0, bf3.length);
System.arraycopy(buf1, 0, buf2, bf3.length, buf1.length);
esmClass = 0x40;
} else {
buf2 = buf1;
}
msgLst.add(buf2);
ArrayList<String> r1 = this.splitStr(messageText, maxSplLen);
segmCnt = r1.size();
break;
case SplitWithParameters_DefaultSegmentLength:
case SplitWithParameters_SpecifiedSegmentLength:
msgRef = getNextMsgRef();
r1 = this.splitStr(messageText, maxSplLen);
for (String bf : r1) {
msgLst.add(encodeSegment(bf, encodingType));
}
segmCnt = msgLst.size();
addSegmTlv = true;
break;
case SplitWithUdh_DefaultSegmentLength:
case SplitWithUdh_SpecifiedSegmentLength:
msgRef = getNextMsgRef();
r1 = this.splitStr(messageText, maxSplLen);
byte[] bf1 = new byte[6];
// total UDH length
bf1[0] = 5;
// UDH id
bf1[1] = 0;
// UDH length
bf1[2] = 3;
// refNum
bf1[3] = (byte) msgRef;
// segmCnt
bf1[4] = (byte) r1.size();
int i1 = 0;
for (String bfStr : r1) {
byte[] bf = encodeSegment(bfStr, encodingType);
i1++;
// segmNum
bf1[5] = (byte) i1;
byte[] bf2 = new byte[bf1.length + bf.length];
System.arraycopy(bf1, 0, bf2, 0, bf1.length);
System.arraycopy(bf, 0, bf2, bf1.length, bf.length);
msgLst.add(bf2);
}
segmCnt = msgLst.size();
esmClass = 0x40;
break;
}
} else {
byte[] buf = encodeSegment(messageText, encodingType);
if (encodingType == EncodingType.GSM8_DCS_4) {
byte[] bf1 = new byte[7];
// total UDH length
bf1[0] = 6;
// UDH id
bf1[1] = 5;
// UDH length
bf1[2] = 4;
bf1[3] = 0x3e;
bf1[4] = (byte) 0x94;
bf1[5] = 0;
bf1[6] = 0;
// 0-bytes length
// bf1 = new byte[3];
// bf1[0] = 2; // total UDH length
// bf1[1] = 112; // UDH id
// bf1[2] = 0; // UDH length
byte[] bf2 = new byte[bf1.length + buf.length];
System.arraycopy(bf1, 0, bf2, 0, bf1.length);
System.arraycopy(buf, 0, bf2, bf1.length, buf.length);
msgLst.add(bf2);
esmClass = 0x40;
} else {
msgLst.add(buf);
}
segmCnt = 1;
}
esmClass |= messagingMode.getCode();
this.doSubmitMessage(dcs, msgLst, msgRef, addSegmTlv, esmClass, validityType, segmCnt, destAddr, messageClassVal);
} catch (Exception e) {
this.addMessage("Failure to submit message", e.toString());
return;
}
}
Aggregations