Search in sources :

Example 1 with SubmitSm

use of com.cloudhopper.smpp.pdu.SubmitSm in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testUSim.

@Test(groups = { "TxSmppServer" })
public void testUSim() 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.setDataCoding((byte) 246);
    event.setEsmClass((byte) 0x43);
    event.setShortMessage(msgUSim);
    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.Unicode);
    this.sbb.onSubmitSm(event, aci);
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
// SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
// this.checkSmsSet(smsSet, curDate, true);
// Sms sms = smsSet.getSms(0);
// assertEquals(sms.getShortMessageText(), sMsg); // msgUcs2
// assertEquals(sms.getShortMessageBin(), udhCode);
// 
// assertEquals(this.smppSess.getReqList().size(), 0);
// assertEquals(this.smppSess.getRespList().size(), 1);
// 
// PduResponse resp = this.smppSess.getRespList().get(0);
// assertEquals(resp.getCommandStatus(), 0);
// assertEquals(resp.getOptionalParameterCount(), 0);
}
Also used : ActivityContextInterface(javax.slee.ActivityContextInterface) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) Esme(org.restcomm.smpp.Esme) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) Test(org.testng.annotations.Test)

Example 2 with SubmitSm

use of com.cloudhopper.smpp.pdu.SubmitSm in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testSubmitSm_Gsm7Enc.

@Test(groups = { "TxSmppServer" })
public void testSubmitSm_Gsm7Enc() 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(msgGsm7);
    event.setDataCoding((byte) 0);
    event.setEsmClass((byte) 3);
    // byte[] bbb = new byte[25500];
    // bbb[0] = 6;
    // bbb[1] = 36;
    // bbb[2] = 1;
    // bbb[3] = 13;
    // bbb[4] = 37;
    // bbb[5] = 1;
    // bbb[6] = 13;
    // for (int i = 7; i < 25500; i++) {
    // bbb[i] = 0x41;
    // }
    // event.setShortMessage(null);
    // Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, bbb);
    // event.addOptionalParameter(tlv);
    // TxSmppServerSbb.smscPropertiesManagement.setNationalLanguageLockingShift(13);
    // TxSmppServerSbb.smscPropertiesManagement.setNationalLanguageSingleShift(13);
    // event.setEsmClass((byte) 67);
    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.setSmppEncodingForGsm7(SmppEncoding.Gsm7);
    this.sbb.onSubmitSm(event, aci);
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
    SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
    // this.checkSmsSet(smsSet, curDate, true);
    Sms sms = smsSet.getSms(0);
    // msgGsm7
    assertEquals(sms.getShortMessageText(), sMsg_4);
    assertNull(sms.getShortMessageBin());
    assertEquals(this.smppSess.getReqList().size(), 0);
    assertEquals(this.smppSess.getRespList().size(), 1);
    PduResponse resp = this.smppSess.getRespList().get(0);
    assertEquals(resp.getCommandStatus(), 0);
    assertEquals(resp.getOptionalParameterCount(), 0);
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) ActivityContextInterface(javax.slee.ActivityContextInterface) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) Esme(org.restcomm.smpp.Esme) Sms(org.mobicents.smsc.library.Sms) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) SmsSet(org.mobicents.smsc.library.SmsSet) Test(org.testng.annotations.Test)

Example 3 with SubmitSm

use of com.cloudhopper.smpp.pdu.SubmitSm in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testUcs2Udh.

@Test(groups = { "TxSmppServer" })
public void testUcs2Udh() 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.setDataCoding((byte) 8);
    event.setEsmClass((byte) 0x40);
    event.setShortMessage(msgUcs2Udh);
    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.Unicode);
    this.sbb.onSubmitSm(event, aci);
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
// SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
// this.checkSmsSet(smsSet, curDate, true);
// Sms sms = smsSet.getSms(0);
// assertEquals(sms.getShortMessageText(), sMsg); // msgUcs2
// assertEquals(sms.getShortMessageBin(), udhCode);
// 
// assertEquals(this.smppSess.getReqList().size(), 0);
// assertEquals(this.smppSess.getRespList().size(), 1);
// 
// PduResponse resp = this.smppSess.getRespList().get(0);
// assertEquals(resp.getCommandStatus(), 0);
// assertEquals(resp.getOptionalParameterCount(), 0);
}
Also used : ActivityContextInterface(javax.slee.ActivityContextInterface) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) Esme(org.restcomm.smpp.Esme) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) Test(org.testng.annotations.Test)

Example 4 with SubmitSm

use of com.cloudhopper.smpp.pdu.SubmitSm in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testSubmitSm_MProc.

@Test(groups = { "TxSmppServer" })
public void testSubmitSm_MProc() throws Exception {
    if (!this.cassandraDbInited)
        return;
    MProcManagement mProcManagement = MProcManagement.getInstance();
    SmscManagement smscManagement = SmscManagement.getInstance("Test");
    SmppManagement smppManagement = SmppManagement.getInstance("Test");
    smscManagement.setSmppManagement(smppManagement);
    mProcManagement.setSmscManagement(smscManagement);
    smscManagement.registerRuleFactory(new MProcRuleFactoryDefault());
    // this.pers.stop();
    DBOperations.getInstance().stop();
    smscManagement.start();
    try {
        mProcManagement.destroyMProcRule(1);
    } catch (Exception e) {
    }
    try {
        mProcManagement.destroyMProcRule(2);
    } catch (Exception e) {
    }
    mProcManagement.createMProcRule(1, MProcRuleFactoryDefault.RULE_CLASS_NAME, "desttonmask 1 destnpimask 1 originatingmask SMPP networkidmask 0 newnetworkid 5 adddestdigprefix 47 makecopy true");
    mProcManagement.createMProcRule(2, MProcRuleFactoryDefault.RULE_CLASS_NAME, "networkidmask 5 newdestnpi 2 makecopy true");
    // TODO: ***** make proper mproc rules testing
    // MProcManagement.getInstance().createMProcRule(1, 1, 1, "-1", "SMPP", 0, 5, -1, -1, "47", true);
    // MProcManagement.getInstance().createMProcRule(2, -1, -1, "-1", null, 5, -1, -1, 2, "-1", true);
    // destTonMask, destNpiMask, destDigMask, originatingMask, networkIdMask, newNetworkId, newDestTon, newDestNpi,
    // addDestDigPrefix, makeCopy
    // TODO: ***** make proper mproc rules testing
    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(msgUcs2);
    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.Unicode);
    this.sbb.onSubmitSm(event, aci);
    TargetAddress tax1 = new TargetAddress(1, 1, "475555", 5);
    TargetAddress tax2 = new TargetAddress(1, 2, "475555", 5);
    // int addrTon, int addrNpi, String addr, int networkId
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
    b1 = this.pers.checkSmsExists(dueSlot, tax1.getTargetId());
    assertEquals(b1, 1);
    b1 = this.pers.checkSmsExists(dueSlot, tax2.getTargetId());
    assertEquals(b1, 1);
    SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
    SmsSet smsSet2 = this.pers.c2_getRecordListForTargeId(dueSlot, tax1.getTargetId());
    SmsSet smsSet3 = this.pers.c2_getRecordListForTargeId(dueSlot, tax2.getTargetId());
    assertEquals(smsSet.getDestAddr(), "5555");
    assertEquals(smsSet.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet.getNetworkId(), 0);
    assertEquals(smsSet2.getDestAddr(), "475555");
    assertEquals(smsSet2.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet2.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet2.getNetworkId(), 5);
    assertEquals(smsSet3.getDestAddr(), "475555");
    assertEquals(smsSet3.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet3.getDestAddrNpi(), SmppConstants.NPI_ISDN);
    assertEquals(smsSet3.getNetworkId(), 5);
    // this.checkSmsSet(smsSet, curDate, true);
    // Sms sms = smsSet.getSms(0);
    // assertEquals(sms.getShortMessageText(), sMsg); // msgUcs2
    // assertEquals(sms.getShortMessageBin(), udhCode);
    // 
    // assertEquals(this.smppSess.getReqList().size(), 0);
    // assertEquals(this.smppSess.getRespList().size(), 1);
    PduResponse resp = this.smppSess.getRespList().get(0);
    assertEquals(resp.getCommandStatus(), 0);
    assertEquals(resp.getOptionalParameterCount(), 0);
    try {
        mProcManagement.destroyMProcRule(1);
        mProcManagement.destroyMProcRule(2);
    } catch (Exception e) {
    }
}
Also used : MProcManagement(org.mobicents.smsc.domain.MProcManagement) PduResponse(com.cloudhopper.smpp.pdu.PduResponse) ActivityContextInterface(javax.slee.ActivityContextInterface) Esme(org.restcomm.smpp.Esme) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) TransactionRolledbackLocalException(javax.slee.TransactionRolledbackLocalException) TransactionRequiredLocalException(javax.slee.TransactionRequiredLocalException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) SLEEException(javax.slee.SLEEException) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) MProcRuleFactoryDefault(org.mobicents.smsc.mproc.impl.MProcRuleFactoryDefault) SmscManagement(org.mobicents.smsc.domain.SmscManagement) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SmppManagement(org.restcomm.smpp.SmppManagement) SmsSet(org.mobicents.smsc.library.SmsSet) Test(org.testng.annotations.Test)

Example 5 with SubmitSm

use of com.cloudhopper.smpp.pdu.SubmitSm 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 = "\nRxSmppServerSbb.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("\nSent 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("\nSent 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() + "\nsmsSet: " + smsSet, 0, 0, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_SEND_DELIVER_SM_000008);
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) ChunkData(org.mobicents.smsc.slee.services.deliverysbb.ChunkData) TargetAddress(org.mobicents.smsc.library.TargetAddress) Address(com.cloudhopper.smpp.type.Address) Esme(org.restcomm.smpp.Esme) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) ArrayList(java.util.ArrayList) ChunkDataList(org.mobicents.smsc.slee.services.deliverysbb.ChunkDataList) SentItemsList(org.mobicents.smsc.slee.services.deliverysbb.SentItemsList) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) Tlv(com.cloudhopper.smpp.tlv.Tlv) Date(java.util.Date) Sms(org.mobicents.smsc.library.Sms) SentItem(org.mobicents.smsc.slee.services.deliverysbb.SentItem) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm)

Aggregations

SubmitSm (com.cloudhopper.smpp.pdu.SubmitSm)13 Date (java.util.Date)7 Esme (org.restcomm.smpp.Esme)7 ActivityContextInterface (javax.slee.ActivityContextInterface)6 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)6 SmppSessionsProxy (org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy)6 Test (org.testng.annotations.Test)6 PduResponse (com.cloudhopper.smpp.pdu.PduResponse)5 Tlv (com.cloudhopper.smpp.tlv.Tlv)5 Address (com.cloudhopper.smpp.type.Address)5 SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)4 DeliverSm (com.cloudhopper.smpp.pdu.DeliverSm)3 Sms (org.mobicents.smsc.library.Sms)3 SmsSet (org.mobicents.smsc.library.SmsSet)3 DataSm (com.cloudhopper.smpp.pdu.DataSm)2 SubmitSmResp (com.cloudhopper.smpp.pdu.SubmitSmResp)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)2 TargetAddress (org.mobicents.smsc.library.TargetAddress)2 BaseSm (com.cloudhopper.smpp.pdu.BaseSm)1