use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class MoSbbTest method testMo3_Usc2.
@Test(groups = { "Mo" })
public void testMo3_Usc2() throws Exception {
if (!this.cassandraDbInited)
return;
// this.clearDatabase();
// SmppSessionsProxy smppServerSessions = new SmppSessionsProxy();
// this.sbb.setSmppServerSessions(smppServerSessions);
AddressString serviceCentreAddressDA = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "1111");
SM_RP_DA sm_RP_DA = new SM_RP_DAImpl(serviceCentreAddressDA);
ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "4444");
SM_RP_OAImpl sm_RP_OA = new SM_RP_OAImpl();
sm_RP_OA.setMsisdn(msisdn);
AddressField destinationAddress = new AddressFieldImpl(TypeOfNumber.InternationalNumber, NumberingPlanIdentification.ISDNTelephoneNumberingPlan, "5555");
ProtocolIdentifier protocolIdentifier = new ProtocolIdentifierImpl(12);
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(8);
UserData userData = new UserDataImpl(new String("������"), dataCodingScheme, null, null);
// String decodedMessage, DataCodingScheme dataCodingScheme, UserDataHeader decodedUserDataHeader, Charset gsm8Charset
SmsTpdu tpdu = new SmsSubmitTpduImpl(false, false, false, 150, destinationAddress, protocolIdentifier, null, userData);
// boolean rejectDuplicates, boolean replyPathExists, boolean statusReportRequest, int messageReference,
// AddressField destinationAddress, ProtocolIdentifier protocolIdentifier, ValidityPeriod validityPeriod, UserData userData
// tpdu.encodeData();
SmsSignalInfo sm_RP_UI = new SmsSignalInfoImpl(tpdu, null);
ForwardShortMessageRequest event = new ForwardShortMessageRequestImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, false);
// ActivityContextInterface aci = new SmppTransactionProxy(esme);
// Date curDate = new Date();
// this.fillSm(event, curDate, true);
// event.setShortMessage(msg);
long dueSlot = this.pers.c2_getDueSlotForTime(new Date());
PreparedStatementCollection psc = this.pers.getStatementCollection(new Date());
int b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
long b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
assertEquals(b1, 0);
assertEquals(b2, 0L);
MAPProviderProxy proxy = new MAPProviderProxy();
MAPDialogSmsProxy dialog = new MAPDialogSmsProxy(new MAPServiceSmsProxy(proxy), null, null, null);
event.setMAPDialog(dialog);
Date curDate = new Date();
MAPApplicationContext act = MAPApplicationContext.getInstance(MAPApplicationContextName.shortMsgMORelayContext, MAPApplicationContextVersion.version2);
dialog.setApplicationContext(act);
this.sbb.onForwardShortMessageRequest(event, null);
b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
dueSlot = b2;
b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
assertEquals(b1, 1);
assertEquals(b2, dueSlot);
assertEquals(dialog.getResponseCount(), 1);
assertEquals(dialog.getErrorList().size(), 0);
SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
assertEquals(smsSet.getDestAddr(), "5555");
assertEquals(smsSet.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
assertEquals(smsSet.getDestAddrNpi(), SmppConstants.NPI_E164);
assertEquals(smsSet.getInSystem(), 0);
assertEquals(smsSet.getDueDelay(), 0);
assertNull(smsSet.getStatus());
assertFalse(smsSet.isAlertingSupported());
Sms sms = smsSet.getSms(0);
assertNotNull(sms);
assertEquals(sms.getSourceAddr(), "4444");
assertEquals(sms.getSourceAddrTon(), SmppConstants.TON_INTERNATIONAL);
assertEquals(sms.getSourceAddrNpi(), SmppConstants.NPI_E164);
assertEquals(sms.getMessageId(), DBOperations.MESSAGE_ID_LAG + 1);
assertEquals(sms.getMoMessageRef(), 150);
assertEquals(sms.getDataCoding(), 8);
assertNull(sms.getOrigEsmeName());
assertNull(sms.getOrigSystemId());
assertNull(sms.getServiceType());
assertEquals(sms.getEsmClass() & 0xFF, 3);
assertEquals(sms.getRegisteredDelivery(), 0);
assertEquals(sms.getProtocolId(), 12);
assertEquals(sms.getPriority(), 0);
assertEquals(sms.getReplaceIfPresent(), 0);
assertEquals(sms.getDefaultMsgId(), 0);
assertEquals(sms.getTlvSet().getOptionalParameterCount(), 0);
assertNull(sms.getScheduleDeliveryTime());
assertDateEq(sms.getValidityPeriod(), MessageUtil.addHours(curDate, 24 * 3));
assertEquals(sms.getDeliveryCount(), 0);
// assertDateEq(smsSet.getDueDate(), new Date(curDate.getTime() + 1 * 60 * 1000));
// Charset ucs2Charset = Charset.forName("UTF-16BE");
// ByteBuffer bb = ByteBuffer.wrap(sms.getShortMessage());
// CharBuffer bf = ucs2Charset.decode(bb);
// String s = bf.toString();
// assertEquals(s, "������");
assertEquals(sms.getShortMessageText(), "������");
assertNull(sms.getShortMessageBin());
}
use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class MtTest method SuccessDelivery3Test.
/**
* MAP V1, 1 message, long message with 2 segments, GSM7
* no TC-BEGIN message because of MAP V1
* SRI response with MwdSet, but no ReportSMDeliveryStatusRequest because of MAP V1
*/
@Test(groups = { "Mt" })
public void SuccessDelivery3Test() 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();
for (int i1 = 0; i1 < 18; i1++) {
// msg len = 180
sb.append("0123456789");
}
String totalMsg = sb.toString();
int segmlen = MessageUtil.getMaxSegmentedMessageBytesLength(new DataCodingSchemeImpl(0));
String msga1 = totalMsg.substring(0, segmlen);
String msga2 = totalMsg.substring(segmlen);
sd1.msg = totalMsg;
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());
// SRI "MAP only V1 supported" response
DialogReject evt11 = new DialogReject(dlg, MAPRefuseReason.PotentialVersionIncompatibility, null, null);
this.sriSbb.onDialogReject(evt11, null);
dlg = serviceSri.getLastMAPDialogSms();
acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version1);
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);
// SRI "MAP only V1 supported" response
DialogReject evt12 = new DialogReject(dlg, MAPRefuseReason.PotentialVersionIncompatibility, null, null);
this.mtSbb.onDialogReject(evt12, null);
dlg = serviceMt.getLastMAPDialogSms();
acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version1);
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
evt = lstEvt.get(0);
assertEquals(evt.testEventType, MAPTestEventType.componentAdded);
ForwardShortMessageRequestImpl mtFsmReq = (ForwardShortMessageRequestImpl) 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(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 1
ForwardShortMessageResponseImpl evt2 = new ForwardShortMessageResponseImpl();
evt2.setMAPDialog(dlg);
DialogAccept daevt = new DialogAccept(dlg, null);
this.mtSbb.onDialogAccept(daevt, null);
this.mtSbb.onForwardShortMessageResponse(evt2, null);
DialogClose dcl = new DialogClose(dlg);
this.mtSbb.onDialogClose(dcl, null);
dlg = serviceMt.getLastMAPDialogSms();
acv = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(acv, MAPApplicationContextVersion.version1);
lstEvt = dlg.getEventList();
assertEquals(lstEvt.size(), 2);
evt = lstEvt.get(0);
assertEquals(evt.testEventType, MAPTestEventType.componentAdded);
mtFsmReq = (ForwardShortMessageRequestImpl) 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 ForwardShortMessageResponseImpl();
evt2.setMAPDialog(dlg);
daevt = new DialogAccept(dlg, null);
this.mtSbb.onDialogAccept(daevt, null);
this.mtSbb.onForwardShortMessageResponse(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.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class MtTest method SuccessDelivery4Test.
/**
* MAP V3, 1 message, long message with 2 segments, UCS2
* Empty TC-BEGIN message
*/
@Test(groups = { "Mt" })
public void SuccessDelivery4Test() 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();
for (int i1 = 0; i1 < 8; i1++) {
// msg len = 80
sb.append("012345678пїЅ");
}
String totalMsg = sb.toString();
int segmlen = MessageUtil.getMaxSegmentedMessageBytesLength(new DataCodingSchemeImpl(8)) / 2;
String msga1 = totalMsg.substring(0, segmlen);
String msga2 = totalMsg.substring(segmlen);
// Charset ucs2Charset = Charset.forName("UTF-16BE");
// ByteBuffer bb = ucs2Charset.encode(totalMsg);
// byte[] buf = new byte[bb.limit()];
// bb.get(buf);
sd1.msg = totalMsg;
sd1.dataCodingScheme = 8;
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(), 8);
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(), 8);
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.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl 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.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class TxSmppServerSbbTest method testSubmitSm_BadCodingSchema.
// @Test(groups = { "TxSmppServer" })
// public void testSubmitMulti_BadAddr() 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 requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
// long clientBindTimeout = SmppConstants.DEFAULT_BIND_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, -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_SUBSCRIBER);
// 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, 0);
// b1 = this.pers.checkSmsExists(dueSlot, ta2.getTargetId());
// assertEquals(b1, 1);
//
// SubmitMultiResp resp = (SubmitMultiResp)this.smppSess.getRespList().get(0);
// assertEquals(resp.getCommandStatus(), 0);
// assertEquals(resp.getOptionalParameterCount(), 0);
// assertEquals(resp.getUnsucessfulSmes().size(), 1);
// assertEquals(resp.getUnsucessfulSmes().get(0).getAddress().getAddress(), "5555");
// }
@Test(groups = { "TxSmppServer" })
public void testSubmitSm_BadCodingSchema() 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 requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
long clientBindTimeout = SmppConstants.DEFAULT_BIND_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);
SubmitSm event = new SubmitSm();
Date curDate = new Date();
this.fillSm(event, curDate, true);
event.setShortMessage(msgUtf8);
DataCodingSchemeImpl dcss = new DataCodingSchemeImpl(DataCodingGroup.GeneralGroup, null, null, null, CharacterSet.GSM7, true);
// DataCodingGroup dataCodingGroup, DataCodingSchemaMessageClass
// messageClass,
// DataCodingSchemaIndicationType dataCodingSchemaIndicationType,
// Boolean setIndicationActive,
// CharacterSet characterSet, boolean isCompressed
event.setDataCoding((byte) 12);
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);
TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Utf8);
this.sbb.onSubmitSm(event, aci);
b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
assertEquals(b2, 0);
assertEquals(this.smppSess.getReqList().size(), 0);
assertEquals(this.smppSess.getRespList().size(), 1);
PduResponse resp = this.smppSess.getRespList().get(0);
assertEquals(resp.getCommandStatus(), 260);
assertEquals(resp.getOptionalParameterCount(), 1);
Tlv tlvr = resp.getOptionalParameter(SmppConstants.TAG_ADD_STATUS_INFO);
String errMsg = tlvr.getValueAsString();
assertEquals(errMsg, "TxSmpp DataCoding scheme does not supported: 12 - Only GSM7, GSM8 and USC2 are supported");
}
Aggregations