Search in sources :

Example 66 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class RxSmppServerSbbTest method prepareDatabase.

private SmsSet prepareDatabase(ArrayList<SmsDef> lst) throws PersistenceException {
    SmsSet smsSet = createEmptySmsSet(ta1);
    int i1 = 1;
    procDueSlot = -1;
    for (SmsDef smsDef : lst) {
        Sms sms = this.prepareSms(smsSet, i1, smsDef);
        if (sms.getStored()) {
            this.pers.c2_scheduleMessage_ReschedDueSlot(sms, false, true);
            procDueSlot = sms.getDueSlot();
        } else {
            smsSet.addSms(sms);
        }
        i1++;
    }
    if (procDueSlot != -1) {
        ArrayList<SmsSet> lst1 = this.pers.c2_getRecordList(procDueSlot);
        ArrayList<SmsSet> lst2 = this.pers.c2_sortRecordList(lst1);
        if (lst2.size() > 0) {
            SmsSet res = lst2.get(0);
            curDate = new Date();
            procTargetId = res.getTargetId();
            procId = new UUID[(int) res.getSmsCount()];
            for (i1 = 0; i1 < res.getSmsCount(); i1++) {
                procId[i1] = res.getSms(i1).getDbId();
            }
            return res;
        } else {
            return null;
        }
    } else {
        procTargetId = smsSet.getTargetId();
        procId = new UUID[(int) smsSet.getSmsCount()];
        for (i1 = 0; i1 < smsSet.getSmsCount(); i1++) {
            procId[i1] = smsSet.getSms(i1).getDbId();
        }
        SmsSetCache.getInstance().addProcessingSmsSet(smsSet.getTargetId(), smsSet, 1000);
        return smsSet;
    }
}
Also used : Sms(org.mobicents.smsc.library.Sms) SmsSet(org.mobicents.smsc.library.SmsSet) Date(java.util.Date)

Example 67 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class DeliveryCommonSbb method postProcessTempFailures.

/**
 * Processing messages that were failed temporary and will be rescheduled (sms.inSystem=sent in live database, message
 * rescheduling).
 *
 * @param smsSet
 * @param lstTempFailured
 * @param int newDueDelay
 * @param newDueDate
 * @param isCheckScheduleDeliveryTimeNeeded true if we need to schedule messages for time to the nearest
 *        ScheduleDeliveryTime (for SS7 network case)
 */
protected void postProcessTempFailures(SmsSet smsSet, ArrayList<Sms> lstTempFailured, int newDueDelay, Date newDueDate, boolean isCheckScheduleDeliveryTimeNeeded) {
    try {
        if (isCheckScheduleDeliveryTimeNeeded)
            newDueDate = MessageUtil.checkScheduleDeliveryTime(lstTempFailured, newDueDate);
        smsSet.setDueDate(newDueDate);
        smsSet.setDueDelay(newDueDelay);
        long dueSlot = persistence.c2_getDueSlotForTime(newDueDate);
        for (Sms sms : lstTempFailured) {
            persistence.c2_scheduleMessage_NewDueSlot(sms, dueSlot, null, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast);
        }
    } catch (PersistenceException e) {
        this.logger.severe("PersistenceException when DeliveryCommonSbb.postProcessTempFailures()" + e.getMessage(), e);
    }
}
Also used : Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException)

Example 68 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class DeliveryCommonSbb method applyMProcPreDelivery.

private boolean applyMProcPreDelivery(Sms sms, ProcessingType processingType) {
    MProcResult mProcResult = MProcManagement.getInstance().applyMProcPreDelivery(itsMProcRa, sms, processingType);
    if (mProcResult.isMessageIsRerouted()) {
        // firstly we check if rerouting attempts was not too many
        if (sms.getReroutingCount() >= MAX_POSSIBLE_REROUTING) {
            StringBuilder sb = new StringBuilder();
            sb.append("Rerouting message attempt in PreDelivery, but we have already rerouted ");
            sb.append(MAX_POSSIBLE_REROUTING);
            sb.append(" times before: targetId=");
            sb.append(sms.getSmsSet().getTargetId());
            sb.append(", newNetworkId=");
            sb.append(mProcResult.getNewNetworkId());
            sb.append(", sms=");
            sb.append(sms);
            this.logger.warning(sb.toString());
            return false;
        } else if (mProcResult.getNewNetworkId() == sms.getSmsSet().getNetworkId()) {
            // we do not reroute for the same networkId
            return true;
        } else {
            ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
            ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
            lstRerouted.add(sms);
            lstNewNetworkId.add(mProcResult.getNewNetworkId());
            if (this.logger.isInfoEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Rerouting message in PreDelivery: targetId=");
                sb.append(sms.getSmsSet().getTargetId());
                sb.append(", newNetworkId=");
                sb.append(mProcResult.getNewNetworkId());
                sb.append(", sms=");
                sb.append(sms);
                this.logger.info(sb.toString());
            }
            postProcessRerouted(lstRerouted, lstNewNetworkId);
            return false;
        }
    } else if (mProcResult.isMessageDropped()) {
        if (this.logger.isInfoEnabled()) {
            StringBuilder sb = new StringBuilder();
            sb.append("Dropping message after in PreDelivery: targetId=");
            sb.append(sms.getSmsSet().getTargetId());
            sb.append(", sms=");
            sb.append(sms);
            this.logger.info(sb.toString());
        }
        ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
        lstPermFailured.add(sms);
        ErrorCode smStatus = ErrorCode.MPROC_PRE_DELIVERY_DROP;
        ErrorAction errorAction = ErrorAction.permanentFailure;
        String reason = "Message drop in PreDelivery";
        sms.getSmsSet().setStatus(smStatus);
        // sending of a failure response for transactional mode
        this.sendTransactionalResponseFailure(lstPermFailured, null, errorAction, null);
        // Processing messages that were temp or permanent failed or rerouted
        this.postProcessPermFailures(lstPermFailured, null, null);
        // generating CDRs for permanent failure messages
        this.generateCDRs(lstPermFailured, CdrGenerator.CDR_MPROC_DROP_PRE_DELIVERY, reason);
        EsmeManagement esmeManagement = EsmeManagement.getInstance();
        Esme esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
        String messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
        this.generateDetailedCDRs(lstPermFailured, EventType.OUT_SMPP_ERROR, smStatus, messageType, esme.getRemoteAddressAndPort(), -1);
        // sending of failure delivery receipts
        this.generateFailureReceipts(sms.getSmsSet(), lstPermFailured, null);
        return false;
    }
    FastList<Sms> addedMessages = mProcResult.getMessageList();
    if (addedMessages != null) {
        for (FastList.Node<Sms> n = addedMessages.head(), end = addedMessages.tail(); (n = n.getNext()) != end; ) {
            Sms smst = n.getValue();
            TargetAddress ta = new TargetAddress(smst.getSmsSet().getDestAddrTon(), smst.getSmsSet().getDestAddrNpi(), smst.getSmsSet().getDestAddr(), smst.getSmsSet().getNetworkId());
            this.sendNewGeneratedMessage(smst, ta);
            if (this.logger.isInfoEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Posting of a new message after PreDelivery: targetId=");
                sb.append(smst.getSmsSet().getTargetId());
                sb.append(", sms=");
                sb.append(smst);
                this.logger.info(sb.toString());
            }
        }
    }
    return true;
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) Esme(org.restcomm.smpp.Esme) ArrayList(java.util.ArrayList) FastList(javolution.util.FastList) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) ErrorAction(org.mobicents.smsc.library.ErrorAction) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) ErrorCode(org.mobicents.smsc.library.ErrorCode)

Example 69 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class DeliveryCommonSbb method applyMprocRulesOnFailure.

/**
 * mproc rules applying for delivery phase for failure case
 *
 * @param lstPermFailured
 * @param lstTempFailured
 * @param lstPermFailuredNew
 * @param lstTempFailuredNew
 * @param lstRerouted
 * @param lstNewNetworkId
 * @param processingType
 */
protected void applyMprocRulesOnFailure(ArrayList<Sms> lstPermFailured, ArrayList<Sms> lstTempFailured, ArrayList<Sms> lstPermFailuredNew, ArrayList<Sms> lstTempFailuredNew, ArrayList<Sms> lstRerouted, ArrayList<Integer> lstNewNetworkId, ProcessingType processingType) {
    // TempFailureProcessor
    for (Sms sms : lstTempFailured) {
        MProcResult mProcResult = MProcManagement.getInstance().applyMProcDeliveryTempFailure(itsMProcRa, sms, processingType);
        if (mProcResult.isMessageIsRerouted()) {
            // firstly we check if rerouting attempts was not too many
            if (sms.getReroutingCount() >= MAX_POSSIBLE_REROUTING) {
                StringBuilder sb = new StringBuilder();
                sb.append("Rerouting message attempt after TempFailure, but we have already rerouted ");
                sb.append(MAX_POSSIBLE_REROUTING);
                sb.append(" times before: targetId=");
                sb.append(sms.getSmsSet().getTargetId());
                sb.append(", newNetworkId=");
                sb.append(mProcResult.getNewNetworkId());
                sb.append(", sms=");
                sb.append(sms);
                this.logger.warning(sb.toString());
                lstTempFailuredNew.add(sms);
            } else if (mProcResult.getNewNetworkId() == sms.getSmsSet().getNetworkId()) {
                // we do not reroute for the same networkId
                lstTempFailuredNew.add(sms);
            } else {
                lstRerouted.add(sms);
                lstNewNetworkId.add(mProcResult.getNewNetworkId());
                if (this.logger.isInfoEnabled()) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("Rerouting message after TempFailure: targetId=");
                    sb.append(sms.getSmsSet().getTargetId());
                    sb.append(", newNetworkId=");
                    sb.append(mProcResult.getNewNetworkId());
                    sb.append(", sms=");
                    sb.append(sms);
                    this.logger.info(sb.toString());
                }
            }
        } else if (mProcResult.isMessageDropped()) {
            lstPermFailuredNew.add(sms);
            if (this.logger.isInfoEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Dropping message after TempFailure: targetId=");
                sb.append(sms.getSmsSet().getTargetId());
                sb.append(", sms=");
                sb.append(sms);
                this.logger.info(sb.toString());
            }
        } else {
            lstTempFailuredNew.add(sms);
        }
        FastList<Sms> addedMessages = mProcResult.getMessageList();
        if (addedMessages != null) {
            for (FastList.Node<Sms> n = addedMessages.head(), end = addedMessages.tail(); (n = n.getNext()) != end; ) {
                Sms smst = n.getValue();
                TargetAddress ta = new TargetAddress(smst.getSmsSet().getDestAddrTon(), smst.getSmsSet().getDestAddrNpi(), smst.getSmsSet().getDestAddr(), smst.getSmsSet().getNetworkId());
                this.sendNewGeneratedMessage(smst, ta);
                if (this.logger.isInfoEnabled()) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("Posting of a new message after TempFailure: targetId=");
                    sb.append(smst.getSmsSet().getTargetId());
                    sb.append(", sms=");
                    sb.append(smst);
                    this.logger.info(sb.toString());
                }
            }
        }
    }
    // PostDeliveryProcessor - failure case
    for (Sms sms : lstPermFailured) {
        MProcResult mProcResult = MProcManagement.getInstance().applyMProcDelivery(itsMProcRa, sms, true, processingType);
        if (mProcResult.isMessageIsRerouted()) {
            if (sms.getReroutingCount() >= MAX_POSSIBLE_REROUTING) {
                StringBuilder sb = new StringBuilder();
                sb.append("Rerouting message attempt after PermFailure, but we have already rerouted ");
                sb.append(MAX_POSSIBLE_REROUTING);
                sb.append(" times before: targetId=");
                sb.append(sms.getSmsSet().getTargetId());
                sb.append(", newNetworkId=");
                sb.append(mProcResult.getNewNetworkId());
                sb.append(", sms=");
                sb.append(sms);
                this.logger.warning(sb.toString());
                lstPermFailuredNew.add(sms);
            } else if (mProcResult.getNewNetworkId() == sms.getSmsSet().getNetworkId()) {
                // we do not reroute for the same networkId
                lstPermFailuredNew.add(sms);
            } else {
                lstRerouted.add(sms);
                lstNewNetworkId.add(mProcResult.getNewNetworkId());
                if (this.logger.isInfoEnabled()) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("Rerouting message after PermFailure: targetId=");
                    sb.append(sms.getSmsSet().getTargetId());
                    sb.append(", newNetworkId=");
                    sb.append(mProcResult.getNewNetworkId());
                    sb.append(", sms=");
                    sb.append(sms);
                    this.logger.info(sb.toString());
                }
            }
        } else {
            lstPermFailuredNew.add(sms);
        }
        FastList<Sms> addedMessages = mProcResult.getMessageList();
        if (addedMessages != null) {
            for (FastList.Node<Sms> n = addedMessages.head(), end = addedMessages.tail(); (n = n.getNext()) != end; ) {
                Sms smst = n.getValue();
                TargetAddress ta = new TargetAddress(smst.getSmsSet().getDestAddrTon(), smst.getSmsSet().getDestAddrNpi(), smst.getSmsSet().getDestAddr(), smst.getSmsSet().getNetworkId());
                this.sendNewGeneratedMessage(smst, ta);
                if (this.logger.isInfoEnabled()) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("Posting of a new message after PermFailure: targetId=");
                    sb.append(smst.getSmsSet().getTargetId());
                    sb.append(", sms=");
                    sb.append(smst);
                    this.logger.info(sb.toString());
                }
            }
        }
    }
}
Also used : MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) FastList(javolution.util.FastList) TargetAddress(org.mobicents.smsc.library.TargetAddress)

Example 70 with Sms

use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.

the class DeliveryCommonSbb method generateIntermediateReceipts.

/**
 * Generating of intermediate receipts for temporary failed messages
 *
 * @param smsSet
 * @param lstTempFailured
 */
protected void generateIntermediateReceipts(SmsSet smsSet, ArrayList<Sms> lstTempFailured) {
    if (!smscPropertiesManagement.getReceiptsDisabling() && smscPropertiesManagement.getEnableIntermediateReceipts()) {
        for (Sms sms : lstTempFailured) {
            // SMPP delivery receipt
            int registeredDelivery = sms.getRegisteredDelivery();
            if (MessageUtil.isReceiptIntermediate(registeredDelivery)) {
                TargetAddress ta = new TargetAddress(sms.getSourceAddrTon(), sms.getSourceAddrNpi(), sms.getSourceAddr(), smsSet.getNetworkId());
                Sms receipt = MessageUtil.createReceiptSms(sms, false, ta, smscPropertiesManagement.getOrigNetworkIdForReceipts(), null, true);
                this.sendNewGeneratedMessage(receipt, ta);
                this.logger.info("Adding an intermediate failure receipt: source=" + receipt.getSourceAddr() + ", dest=" + receipt.getSmsSet().getDestAddr());
            }
        }
    }
}
Also used : Sms(org.mobicents.smsc.library.Sms) TargetAddress(org.mobicents.smsc.library.TargetAddress)

Aggregations

Sms (org.mobicents.smsc.library.Sms)139 SmsSet (org.mobicents.smsc.library.SmsSet)62 Test (org.testng.annotations.Test)43 Date (java.util.Date)42 ArrayList (java.util.ArrayList)35 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)33 TargetAddress (org.mobicents.smsc.library.TargetAddress)30 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)27 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)27 ISDNAddressStringImpl (org.restcomm.protocols.ss7.map.primitives.ISDNAddressStringImpl)26 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)24 SmscPropertiesManagement (org.mobicents.smsc.domain.SmscPropertiesManagement)23 UUID (java.util.UUID)22 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)21 SmsSetEvent (org.mobicents.smsc.slee.services.smpp.server.events.SmsSetEvent)21 SmsProxy (org.mobicents.smsc.slee.resources.persistence.SmsProxy)20 SM_RP_DA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA)19 SmsSignalInfo (org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo)19 MAPApplicationContextVersion (org.restcomm.protocols.ss7.map.api.MAPApplicationContextVersion)17 UserData (org.restcomm.protocols.ss7.map.api.smstpdu.UserData)17