Search in sources :

Example 11 with TargetAddress

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

the class RxSipServerSbb method onSUCCESS.

public void onSUCCESS(javax.sip.ResponseEvent event, ActivityContextInterface aci) {
    if (this.logger.isFineEnabled()) {
        this.logger.fine("onSUCCESS " + event);
    }
    SmsSet smsSet = getSmsSet();
    if (smsSet == null) {
        logger.severe("RxSipServerSbb.onSUCCESS(): CMP smsSet is missed");
        markDeliveringIsEnded(true);
        return;
    }
    try {
        smscStatAggregator.updateMsgOutSentAll();
        smscStatAggregator.updateMsgOutSentSip();
        // current message is sent pushing current message into an archive
        Sms sms = this.getMessageInSendingPool(0);
        if (sms == null) {
            logger.severe("RxSipServerSbb.onSUCCESS(): CMP sms is missed. smsSet=" + smsSet);
            markDeliveringIsEnded(true);
            return;
        }
        // firstly sending of a positive response for transactional mode
        sendTransactionalResponseSuccess(sms);
        // mproc rules applying for delivery phase
        this.applyMprocRulesOnSuccess(sms, ProcessingType.SIP);
        // Processing succeeded
        sms.getSmsSet().setStatus(ErrorCode.SUCCESS);
        this.postProcessSucceeded(sms, null, null);
        // success CDR generating
        boolean isPartial = MessageUtil.isSmsNotLastSegment(sms);
        this.generateCDR(sms, isPartial ? CdrGenerator.CDR_PARTIAL_SIP : CdrGenerator.CDR_SUCCESS_SIP, CdrGenerator.CDR_SUCCESS_NO_REASON, false, true, -1);
        // adding a success receipt if it is needed
        this.generateSuccessReceipt(smsSet, sms);
        TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
        try {
            synchronized (lock) {
                // marking the message in cache as delivered
                this.commitSendingPoolMsgCount();
                // now we are trying to sent other messages
                if (this.getTotalUnsentMessageCount() > 0) {
                    try {
                        this.sendMessage(smsSet);
                        return;
                    } catch (SmscProcessingException e) {
                        String s = "SmscProcessingException when sending sendMessage()=" + e.getMessage() + ", Message=" + sms;
                        logger.severe(s, e);
                        markDeliveringIsEnded(true);
                    }
                }
                // no more messages to send - remove smsSet
                smsSet.setStatus(ErrorCode.SUCCESS);
                this.markDeliveringIsEnded(true);
            }
        } finally {
            persistence.releaseSynchroObject(lock);
        }
    } catch (Throwable e1) {
        String s = "Exception in RxSipServerSbb.onSUCCESS() when fetching records and issuing events: " + e1.getMessage();
        logger.severe(s, e1);
        this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SC_SYSTEM_ERROR, s);
    }
}
Also used : SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Sms(org.mobicents.smsc.library.Sms) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 12 with TargetAddress

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

the class RxSipServerSbb method onDeliveryError.

/**
 * Processing a case when an error in message sending process. This stops of message sending, reschedule or drop messages
 * and clear resources.
 *
 * @param smsSet
 * @param errorAction
 * @param smStatus
 * @param reason
 */
private void onDeliveryError(SmsSet smsSet, ErrorAction errorAction, ErrorCode smStatus, String reason) {
    try {
        smscStatAggregator.updateMsgOutFailedAll();
        // generating of a temporary failure CDR (one record for all unsent messages)
        if (smscPropertiesManagement.getGenerateTempFailureCdr())
            this.generateTemporaryFailureCDR(CdrGenerator.CDR_TEMP_FAILED_SIP, reason);
        ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
        ArrayList<Sms> lstTempFailured = new ArrayList<Sms>();
        ArrayList<Sms> lstPermFailured2 = new ArrayList<Sms>();
        ArrayList<Sms> lstTempFailured2 = new ArrayList<Sms>();
        ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
        ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
        TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
        synchronized (lock) {
            try {
                // ending of delivery process in this SBB
                smsSet.setStatus(smStatus);
                this.markDeliveringIsEnded(true);
                // calculating of newDueDelay and NewDueTime
                int newDueDelay = calculateNewDueDelay(smsSet, false);
                Date newDueTime = calculateNewDueTime(smsSet, newDueDelay);
                // creating of failure lists
                this.createFailureLists(lstPermFailured, lstTempFailured, errorAction, newDueTime);
                // mproc rules applying for delivery phase
                this.applyMprocRulesOnFailure(lstPermFailured, lstTempFailured, lstPermFailured2, lstTempFailured2, lstRerouted, lstNewNetworkId, ProcessingType.SIP);
                // sending of a failure response for transactional mode
                this.sendTransactionalResponseFailure(lstPermFailured2, lstTempFailured2, errorAction, null);
                // Processing messages that were temp or permanent failed or rerouted
                this.postProcessPermFailures(lstPermFailured2, null, null);
                this.postProcessTempFailures(smsSet, lstTempFailured2, newDueDelay, newDueTime, false);
                this.postProcessRerouted(lstRerouted, lstNewNetworkId);
                // generating CDRs for permanent failure messages
                this.generateCDRs(lstPermFailured2, CdrGenerator.CDR_FAILED_SIP, reason);
                // sending of intermediate delivery receipts
                this.generateIntermediateReceipts(smsSet, lstTempFailured2);
                // sending of failure delivery receipts
                this.generateFailureReceipts(smsSet, lstPermFailured2, null);
            } finally {
                persistence.releaseSynchroObject(lock);
            }
        }
    } catch (Throwable e) {
        logger.severe("Exception in RxSipServerSbb.onDeliveryError(): " + e.getMessage(), e);
        markDeliveringIsEnded(true);
    }
}
Also used : Sms(org.mobicents.smsc.library.Sms) ArrayList(java.util.ArrayList) TargetAddress(org.mobicents.smsc.library.TargetAddress) ListeningPoint(javax.sip.ListeningPoint) Date(java.util.Date)

Example 13 with TargetAddress

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

the class RxSmppServerSbb method onDeliveryError.

/**
 * Processing a case when an error in message sending process. This stops of message sending, reschedule or drop messages
 * and clear resources.
 *
 * @param smsSet
 * @param errorAction
 * @param smStatus
 * @param reason
 */
private void onDeliveryError(SmsSet smsSet, ErrorAction errorAction, ErrorCode smStatus, String reason, EventType eventType, int seqNumber) {
    getDefaultSbbUsageParameterSet().incrementCounterErrorDelivery(ONE);
    try {
        smscStatAggregator.updateMsgOutFailedAll();
        EsmeManagement esmeManagement = EsmeManagement.getInstance();
        Esme esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
        String messageType = null;
        String remoteAddr = null;
        if (esme != null) {
            messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
            remoteAddr = esme.getRemoteAddressAndPort();
        }
        // generating of a temporary failure CDR (one record for all unsent messages)
        if (smscPropertiesManagement.getGenerateTempFailureCdr()) {
            this.generateTemporaryFailureCDR(CdrGenerator.CDR_TEMP_FAILED_ESME, reason);
            this.generateTemporaryFailureDetailedCDR(eventType, messageType, smStatus, remoteAddr, seqNumber);
        }
        ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
        ArrayList<Sms> lstTempFailured = new ArrayList<Sms>();
        ArrayList<Sms> lstPermFailured2 = new ArrayList<Sms>();
        ArrayList<Sms> lstTempFailured2 = new ArrayList<Sms>();
        ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
        ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
        TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
        synchronized (lock) {
            try {
                setPendingChunks(null);
                setSentChunks(null);
                // ending of delivery process in this SBB
                smsSet.setStatus(smStatus);
                this.markDeliveringIsEnded(true);
                // calculating of newDueDelay and NewDueTime
                int newDueDelay = calculateNewDueDelay(smsSet, false);
                Date newDueTime = calculateNewDueTime(smsSet, newDueDelay);
                // creating of failure lists
                this.createFailureLists(lstPermFailured, lstTempFailured, errorAction, newDueTime);
                // mproc rules applying for delivery phase
                this.applyMprocRulesOnFailure(lstPermFailured, lstTempFailured, lstPermFailured2, lstTempFailured2, lstRerouted, lstNewNetworkId, ProcessingType.SMPP);
                // sending of a failure response for transactional mode
                this.sendTransactionalResponseFailure(lstPermFailured2, lstTempFailured2, errorAction, null);
                // Processing messages that were temp or permanent failed or rerouted
                this.postProcessPermFailures(lstPermFailured2, null, null);
                this.postProcessTempFailures(smsSet, lstTempFailured2, newDueDelay, newDueTime, false);
                this.postProcessRerouted(lstRerouted, lstNewNetworkId);
                // generating CDRs for permanent failure messages
                this.generateCDRs(lstPermFailured2, CdrGenerator.CDR_FAILED_ESME, reason);
                if (!smscPropertiesManagement.getGenerateTempFailureCdr()) {
                    generateDetailedCDRs(lstPermFailured2, EventType.OUT_SMPP_ERROR, smStatus, messageType, remoteAddr, seqNumber);
                }
                // sending of intermediate delivery receipts
                this.generateIntermediateReceipts(smsSet, lstTempFailured2);
                // sending of failure delivery receipts
                this.generateFailureReceipts(smsSet, lstPermFailured2, null);
            } finally {
                persistence.releaseSynchroObject(lock);
            }
        }
    } catch (Throwable e) {
        getDefaultSbbUsageParameterSet().incrementCounterErrorDeliveryException(ONE);
        logger.severe("Exception in RxSmppServerSbb.onDeliveryError(): " + e.getMessage(), e);
        markDeliveringIsEnded(true);
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) Esme(org.restcomm.smpp.Esme) Sms(org.mobicents.smsc.library.Sms) ArrayList(java.util.ArrayList) TargetAddress(org.mobicents.smsc.library.TargetAddress) Date(java.util.Date)

Example 14 with TargetAddress

use of org.mobicents.smsc.library.TargetAddress 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 15 with TargetAddress

use of org.mobicents.smsc.library.TargetAddress 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)

Aggregations

TargetAddress (org.mobicents.smsc.library.TargetAddress)34 Sms (org.mobicents.smsc.library.Sms)28 Date (java.util.Date)13 SmsSet (org.mobicents.smsc.library.SmsSet)13 ArrayList (java.util.ArrayList)10 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)8 Esme (org.restcomm.smpp.Esme)8 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)7 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)7 FastList (javolution.util.FastList)6 MProcResult (org.mobicents.smsc.mproc.impl.MProcResult)6 EsmeManagement (org.restcomm.smpp.EsmeManagement)6 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)5 Test (org.testng.annotations.Test)5 CreateException (javax.slee.CreateException)4 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)4 ErrorAction (org.mobicents.smsc.library.ErrorAction)3 ErrorCode (org.mobicents.smsc.library.ErrorCode)3 SmppSessionsProxy (org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy)3 MAPDialogSms (org.restcomm.protocols.ss7.map.api.service.sms.MAPDialogSms)3