Search in sources :

Example 1 with SmscProcessingException

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

the class ChargingSbb method rejectSmsByDiameter.

private void rejectSmsByDiameter(ChargingData chargingData, RoCreditControlAnswer evt) throws SmscProcessingException {
    Sms sms = chargingData.getSms();
    if (logger.isInfoEnabled()) {
        logger.info("ChargingSbb: accessRejected for: resultCode =" + (evt != null ? evt.getResultCode() : "timeout") + ", chargingType=" + chargingData.getChargingType() + ", message=[" + sms + "]");
    }
    try {
        // sending of a failure response for transactional mode / delaying for charging result
        MessageDeliveryResultResponseInterface.DeliveryFailureReason delReason = MessageDeliveryResultResponseInterface.DeliveryFailureReason.invalidDestinationAddress;
        if (sms.getMessageDeliveryResultResponse() != null) {
            sms.getMessageDeliveryResultResponse().responseDeliveryFailure(delReason, null);
            sms.setMessageDeliveryResultResponse(null);
        }
        sms.getSmsSet().setStatus(ErrorCode.OCS_ACCESS_NOT_GRANTED);
        boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
        if (storeAndForwMode) {
            sms.setStored(true);
        }
        // if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
        // persistence.archiveFailuredSms(sms);
        // } else {
        String sourceAddrAndPort = null;
        String messageType = null;
        EventType eventType = null;
        switch(sms.getOriginationType()) {
            case SMPP:
                EsmeManagement esmeManagement = EsmeManagement.getInstance();
                Esme esme = null;
                if (esmeManagement != null)
                    esme = esmeManagement.getEsmeByClusterName(sms.getOrigEsmeName());
                eventType = EventType.IN_SMPP_REJECT_DIAMETER;
                if (esme != null) {
                    sourceAddrAndPort = esme.getRemoteAddressAndPort();
                    // shouldn't have null value
                    messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
                }
                break;
            case HTTP:
                messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
                eventType = EventType.IN_HTTP_REJECT_DIAMETER;
                break;
            default:
                break;
        }
        if (eventType != null) {
            CdrDetailedGenerator.generateDetailedCdr(sms, eventType, sms.getSmsSet().getStatus(), messageType, 0, -1, sourceAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
        }
        if (MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateArchiveTable())) {
            persistence.c2_createRecordArchive(sms, null, null, !smscPropertiesManagement.getReceiptsDisabling(), smscPropertiesManagement.getIncomeReceiptsProcessing());
        }
        // }
        smscStatAggregator.updateMsgInRejectedAll();
        // TODO: if CCR gives some response verbal reject reason
        // we need replace CdrGenerator.CDR_SUCCESS_NO_REASON with this
        // reason
        CdrGenerator.generateCdr(sms, CdrGenerator.CDR_OCS_REJECTED, CdrGenerator.CDR_SUCCESS_NO_REASON, smscPropertiesManagement.getGenerateReceiptCdr(), MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateCdr()), false, true, smscPropertiesManagement.getCalculateMsgPartsLenCdr(), smscPropertiesManagement.getDelayParametersInCdr());
    } catch (PersistenceException e) {
        throw new SmscProcessingException("PersistenceException when storing into Archive rejected by OCS message : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) MessageDeliveryResultResponseInterface(org.mobicents.smsc.library.MessageDeliveryResultResponseInterface) EventType(org.mobicents.smsc.library.EventType) Esme(org.restcomm.smpp.Esme) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException)

Example 2 with SmscProcessingException

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

the class MtSbb method sendMtSms.

private void sendMtSms(MAPApplicationContext mapApplicationContext, MessageProcessingState messageProcessingState, MAPDialogSms mapDialogSms, int networkId) throws SmscProcessingException {
    SmsSet smsSet = getSmsSet();
    if (smsSet == null) {
        throw new SmscProcessingException("CMP smsSet is missed", -1, -1, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    Sms sms = this.getMessageInSendingPool(0);
    if (sms == null) {
        throw new SmscProcessingException("sms is missed in CMP", -1, -1, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    boolean moreMessagesToSend = false;
    try {
        if (this.getTotalUnsentMessageCount() > 1) {
            moreMessagesToSend = true;
        }
    } catch (Throwable e) {
    }
    try {
        boolean newDialog = false;
        if (mapDialogSms == null) {
            newDialog = true;
            String mtLocalSccpGt = sms.getMtLocalSccpGt();
            SccpAddress originSccpAddress;
            if (mtLocalSccpGt != null) {
                originSccpAddress = this.getServiceCenterSccpAddress(mtLocalSccpGt, networkId);
            } else {
                originSccpAddress = this.getServiceCenterSccpAddress(networkId);
            }
            mapDialogSms = this.mapProvider.getMAPServiceSms().createNewDialog(mapApplicationContext, originSccpAddress, null, this.getNetworkNode(), null);
            mapDialogSms.setNetworkId(networkId);
            ActivityContextInterface mtFOSmsDialogACI = this.mapAcif.getActivityContextInterface(mapDialogSms);
            mtFOSmsDialogACI.attach(this.sbbContext.getSbbLocalObject());
        }
        // setting TON / NPI to unknown for unsupported source TON / NPI
        int sourceAddrTon = sms.getSourceAddrTon();
        if (sourceAddrTon < 0 || sourceAddrTon > 6)
            sourceAddrTon = 0;
        int sourceAddrNpi = sms.getSourceAddrNpi();
        if (sourceAddrTon == SmppConstants.TON_ALPHANUMERIC) {
            sourceAddrNpi = SmppConstants.NPI_UNKNOWN;
        } else {
            if (sourceAddrNpi >= 0 && sourceAddrNpi <= 1 || sourceAddrNpi >= 3 && sourceAddrNpi <= 9 || sourceAddrNpi >= 10 && sourceAddrNpi <= 1 || sourceAddrNpi == 18) {
            } else {
                sourceAddrNpi = SmppConstants.NPI_UNKNOWN;
            }
        }
        SM_RP_DA sm_RP_DA = this.getSmRpDa();
        SM_RP_OA sm_RP_OA = this.getSmRpOa();
        SmsSignalInfo smsSignalInfo;
        if (messageProcessingState == MessageProcessingState.firstMessageSending) {
            int dcs = sms.getDataCoding();
            Tlv dest_addr_subunit = sms.getTlvSet().getOptionalParameter(SmppConstants.TAG_DEST_ADDR_SUBUNIT);
            if (dest_addr_subunit != null) {
                try {
                    int mclass = dest_addr_subunit.getValueAsByte();
                    if (mclass >= 1 && mclass <= 4) {
                        dcs |= (0x10 + (mclass - 1));
                    }
                } catch (TlvConvertException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            DataCodingScheme dataCodingScheme = this.mapSmsTpduParameterFactory.createDataCodingScheme(dcs);
            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);
            SmsSignalInfo[] segments;
            SmsDeliveryReportData smsDeliveryReportData = SmsDeliveryReportData.decodeFromString(sms.getShortMessageText());
            if (smsDeliveryReportData != null) {
                // this is SMS-STATUS-REPORT
                segments = new SmsSignalInfo[1];
                segments[0] = this.createSignalInfoStatusReport(sms, moreMessagesToSend, smsDeliveryReportData);
            } else if ((sms.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0) {
                // message already contains UDH - we can not slice it
                segments = new SmsSignalInfo[1];
                segments[0] = this.createSignalInfo(sms, sms.getShortMessageText(), sms.getShortMessageBin(), moreMessagesToSend, 0, 1, 1, dataCodingScheme, 0, 0, sourceAddrTon, sourceAddrNpi);
            } else if (sarMsgRefNum != null && sarTotalSegments != null && sarSegmentSeqnum != null) {
                // we have tlv's that define message count/number/reference
                int messageSegmentCount = sarTotalSegments.getValueAsUnsignedByte();
                int messageSegmentNumber = sarSegmentSeqnum.getValueAsUnsignedByte();
                int messageReferenceNumber = sarMsgRefNum.getValueAsUnsignedShort();
                segments = new SmsSignalInfo[1];
                segments[0] = this.createSignalInfo(sms, sms.getShortMessageText(), null, moreMessagesToSend, messageReferenceNumber, messageSegmentCount, messageSegmentNumber, dataCodingScheme, sms.getNationalLanguageLockingShift(), sms.getNationalLanguageSingleShift(), sourceAddrTon, sourceAddrNpi);
            } else {
                // possible a big message and segmentation
                String[] segmentsByte;
                segmentsByte = MessageUtil.sliceMessage(sms.getShortMessageText(), dataCodingScheme, sms.getNationalLanguageLockingShift(), sms.getNationalLanguageSingleShift());
                segments = new SmsSignalInfo[segmentsByte.length];
                // TODO messageReferenceNumber should be generated
                // int messageReferenceNumber = (int) (this.getCurrentMsgNumValue() + 1);
                int messageReferenceNumber = (int) (this.getCurrentMsgNumValue());
                for (int i1 = 0; i1 < segmentsByte.length; i1++) {
                    segments[i1] = this.createSignalInfo(sms, segmentsByte[i1], null, (i1 < segmentsByte.length - 1 ? true : moreMessagesToSend), messageReferenceNumber, segmentsByte.length, i1 + 1, dataCodingScheme, sms.getNationalLanguageLockingShift(), sms.getNationalLanguageSingleShift(), sourceAddrTon, sourceAddrNpi);
                }
            }
            this.setSegments(segments);
            smsSignalInfo = segments[0];
            this.setMessageSegmentNumber(0);
            if (segments.length > 1)
                moreMessagesToSend = true;
        } else {
            int messageSegmentNumber = this.getMessageSegmentNumber();
            SmsSignalInfo[] segments = this.getSegments();
            smsSignalInfo = segments[messageSegmentNumber];
            if (messageSegmentNumber < segments.length - 1)
                moreMessagesToSend = true;
        }
        long invokeId = 0;
        switch(mapDialogSms.getApplicationContext().getApplicationContextVersion()) {
            case version3:
                invokeId = mapDialogSms.addMtForwardShortMessageRequest(sm_RP_DA, sm_RP_OA, smsSignalInfo, moreMessagesToSend, null);
                if (this.logger.isInfoEnabled()) {
                    this.logger.info("\nSending: MtForwardShortMessageRequest: sm_RP_DA=" + sm_RP_DA + ", sm_RP_OA=" + sm_RP_OA + ", si=" + smsSignalInfo + ", moreMessagesToSend=" + moreMessagesToSend);
                }
                break;
            case version2:
            case version1:
                invokeId = mapDialogSms.addForwardShortMessageRequest(sm_RP_DA, sm_RP_OA, smsSignalInfo, moreMessagesToSend);
                if (this.logger.isInfoEnabled()) {
                    this.logger.info("\nSending: ForwardShortMessageRequest: sm_RP_DA=" + sm_RP_DA + ", sm_RP_OA=" + sm_RP_OA + ", si=" + smsSignalInfo + ", moreMessagesToSend=" + moreMessagesToSend);
                }
                break;
            default:
                break;
        }
        int messageUserDataLengthOnSend = mapDialogSms.getMessageUserDataLengthOnSend();
        int maxUserDataLength = mapDialogSms.getMaxUserDataLength();
        if (mapDialogSms.getApplicationContext().getApplicationContextVersion() != MAPApplicationContextVersion.version1 && newDialog && messageUserDataLengthOnSend >= maxUserDataLength - SmscPropertiesManagement.getInstance().getMaxMessageLengthReducer()) {
            mapDialogSms.cancelInvocation(invokeId);
            this.setTcEmptySent(1);
        } else {
            this.setTcEmptySent(0);
        }
        mapDialogSms.send();
        sms.putMsgPartDeliveryTime(getMessageSegmentNumber(), System.currentTimeMillis());
    } catch (MAPException e) {
        if (mapDialogSms != null)
            mapDialogSms.release();
        throw new SmscProcessingException("MAPException when sending MtForwardSM. \nSms=" + sms, -1, -1, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
    } catch (TlvConvertException e) {
        if (mapDialogSms != null)
            mapDialogSms.release();
        throw new SmscProcessingException("TlvConvertException when sending MtForwardSM", -1, -1, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
    }
}
Also used : SccpAddress(org.mobicents.protocols.ss7.sccp.parameter.SccpAddress) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) ActivityContextInterface(javax.slee.ActivityContextInterface) MAPException(org.mobicents.protocols.ss7.map.api.MAPException) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) SM_RP_OA(org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) SmsDeliveryReportData(org.mobicents.smsc.library.SmsDeliveryReportData) SmsSignalInfo(org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo) MAPDialogSms(org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms) Sms(org.mobicents.smsc.library.Sms) MAPErrorMessageSubscriberBusyForMtSms(org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageSubscriberBusyForMtSms) SmsSet(org.mobicents.smsc.library.SmsSet) SM_RP_DA(org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 3 with SmscProcessingException

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

the class MtSbb method setupMtForwardShortMessageRequest.

// *********
// Main service methods
public void setupMtForwardShortMessageRequest(ISDNAddressString networkNode, String imsiData, LMSI lmsi, int networkId) {
    if (this.logger.isFineEnabled()) {
        this.logger.fine("\nmperforming setupMtForwardShortMessageRequest ISDNAddressString= " + networkNode);
    }
    SmsSet smsSet = getSmsSet();
    if (smsSet == null) {
        markDeliveringIsEnded(true);
        logger.severe("MtSbb.setupMtForwardShortMessageRequest(): CMP smsSet is missed");
        return;
    }
    Sms sms0 = smsSet.getSms(0);
    Integer mtRemoteSccpTt = sms0.getMtRemoteSccpTt();
    SccpAddress networkNodeSccpAddress = this.getMSCSccpAddress(networkNode, mtRemoteSccpTt);
    IMSI imsi = this.mapParameterFactory.createIMSI(imsiData);
    SM_RP_DA sm_RP_DA = this.mapParameterFactory.createSM_RP_DA(imsi);
    AddressString scAddress = this.getServiceCenterAddressString(networkId);
    SM_RP_OA sm_RP_OA = this.mapParameterFactory.createSM_RP_OA_ServiceCentreAddressOA(scAddress);
    if (sms0 != null) {
        // we only set it for first sms in the list
        sms0.setMtServiceCenterAddress(scAddress.getAddress());
    }
    this.setNnn(networkNode);
    this.setNetworkNode(networkNodeSccpAddress);
    this.setSmRpDa(sm_RP_DA);
    this.setSmRpOa(sm_RP_OA);
    // Set cache with MAP version
    MAPApplicationContextVersion mapApplicationContextVersion = mapVersionCache.getMAPApplicationContextVersion(networkNode.getAddress());
    if (mapApplicationContextVersion == null) {
        mapApplicationContextVersion = MAPApplicationContextVersion.getInstance(smscPropertiesManagement.getMaxMapVersion());
    } else {
        this.setNegotiatedMapVersionUsing(true);
    }
    this.setMAPVersionTested(mapApplicationContextVersion);
    // dropaftersri mproc rules
    try {
        if (this.getTotalUnsentMessageCount() > 0) {
            ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
            ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
            ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
            TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
            try {
                synchronized (lock) {
                    this.applyMprocRulesOnImsiResponse(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNode, imsiData);
                    this.onImsiDrop(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNode, imsiData);
                }
            } finally {
                persistence.releaseSynchroObject(lock);
            }
        }
    } catch (Throwable e) {
    }
    if (this.getTotalUnsentMessageCount() == 0) {
        setupReportSMDeliveryStatusRequestSuccess(smsSet, true);
        smsSet.setStatus(ErrorCode.SUCCESS);
        this.markDeliveringIsEnded(true);
    } else {
        try {
            this.sendMtSms(this.getMtFoSMSMAPApplicationContext(mapApplicationContextVersion), MessageProcessingState.firstMessageSending, null, smsSet.getNetworkId());
        } catch (SmscProcessingException e) {
            String reason = "SmscPocessingException when invoking sendMtSms() from setupMtForwardShortMessageRequest()-firstMessageSending: " + e.toString();
            this.logger.severe(reason, e);
            ErrorCode smStatus = ErrorCode.SC_SYSTEM_ERROR;
            try {
                smStatus = ErrorCode.fromInt(e.getSmppErrorCode());
            } catch (IllegalArgumentException e1) {
            }
            this.onDeliveryError(smsSet, ErrorAction.permanentFailure, smStatus, reason, true, null, false, ProcessingType.SS7_MT);
        } catch (Throwable e) {
            String reason = "Exception when invoking sendMtSms() from setupMtForwardShortMessageRequest()-firstMessageSending: " + e.toString();
            this.logger.severe(reason, e);
            ErrorCode smStatus = ErrorCode.SC_SYSTEM_ERROR;
            this.onDeliveryError(smsSet, ErrorAction.permanentFailure, smStatus, reason, true, null, false, ProcessingType.SS7_MT);
        }
    }
}
Also used : SccpAddress(org.mobicents.protocols.ss7.sccp.parameter.SccpAddress) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) ArrayList(java.util.ArrayList) SM_RP_OA(org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_OA) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) MAPApplicationContextVersion(org.mobicents.protocols.ss7.map.api.MAPApplicationContextVersion) MAPDialogSms(org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms) Sms(org.mobicents.smsc.library.Sms) MAPErrorMessageSubscriberBusyForMtSms(org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageSubscriberBusyForMtSms) IMSI(org.mobicents.protocols.ss7.map.api.primitives.IMSI) MAPErrorCode(org.mobicents.protocols.ss7.map.api.errors.MAPErrorCode) ErrorCode(org.mobicents.smsc.library.ErrorCode) SmsSet(org.mobicents.smsc.library.SmsSet) SM_RP_DA(org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA)

Example 4 with SmscProcessingException

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

the class MtSbb method handleSmsResponse.

private void handleSmsResponse(MAPDialogSms mapDialogSms, boolean continueDialog) {
    SmsSet smsSet = getSmsSet();
    if (smsSet == null) {
        logger.severe("MtSbb.handleSmsResponse(): CMP smsSet is missed");
        markDeliveringIsEnded(true);
        return;
    }
    smscStatAggregator.updateMsgOutSentAll();
    smscStatAggregator.updateMsgOutSentSs7();
    Sms sms = this.getMessageInSendingPool(0);
    // checking if there are yet message segments
    int messageSegmentNumber = this.getMessageSegmentNumber();
    SmsSignalInfo[] segments = this.getSegments();
    if (segments != null && messageSegmentNumber < segments.length - 1) {
        this.generateCDR(sms, CdrGenerator.CDR_PARTIAL, CdrGenerator.CDR_SUCCESS_NO_REASON, true, false, messageSegmentNumber);
        // we have more message parts to be sent yet
        messageSegmentNumber++;
        this.setMessageSegmentNumber(messageSegmentNumber);
        try {
            smscStatAggregator.updateMsgOutTryAll();
            smscStatAggregator.updateMsgOutTrySs7();
            this.sendMtSms(mapDialogSms.getApplicationContext(), MessageProcessingState.nextSegmentSending, continueDialog ? mapDialogSms : null, smsSet.getNetworkId());
            return;
        } catch (SmscProcessingException e) {
            this.logger.severe("SmscPocessingException when invoking sendMtSms() from handleSmsResponse()-nextSegmentSending: " + e.toString(), e);
            this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SYSTEM_FAILURE, "Error sendMtSms in handleSmsResponse(): ", true, null, false, ProcessingType.SS7_MT);
            return;
        }
    }
    // current message is sent
    // firstly sending of a positive response for transactional mode
    this.sendTransactionalResponseSuccess(sms);
    // mproc rules applying for delivery phase
    this.applyMprocRulesOnSuccess(sms, ProcessingType.SS7_MT);
    // 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 : CdrGenerator.CDR_SUCCESS, CdrGenerator.CDR_SUCCESS_NO_REASON, segments != null, true, messageSegmentNumber);
    // 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
            sms = obtainNextMessage(ProcessingType.SS7_MT);
            if (sms != null) {
                // dropaftersri pmproc rules
                ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
                ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
                ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
                SM_RP_DA da = this.getSmRpDa();
                ISDNAddressString networkNodeNumber = this.getNnn();
                this.applyMprocRulesOnImsiResponse(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNodeNumber, da.getIMSI().getData());
                this.onImsiDrop(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNodeNumber, da.getIMSI().getData());
            }
            sms = this.getMessageInSendingPool(0);
            if (sms != null) {
                try {
                    // sms.setDeliveryCount(sms.getDeliveryCount() + 1);
                    smscStatAggregator.updateMsgOutTryAll();
                    smscStatAggregator.updateMsgOutTrySs7();
                    this.sendMtSms(mapDialogSms.getApplicationContext(), MessageProcessingState.firstMessageSending, continueDialog ? mapDialogSms : null, smsSet.getNetworkId());
                    return;
                } catch (SmscProcessingException e) {
                    this.logger.severe("SmscPocessingException when invoking sendMtSms() from handleSmsResponse(): " + e.toString(), e);
                }
            }
            // more messages in a database
            if (continueDialog) {
                try {
                    mapDialogSms.close(false);
                } catch (MAPException e) {
                    this.logger.severe("MAPException when closing MAP dialog from handleSmsResponse(): " + e.toString(), e);
                }
            }
            // no more messages to send - remove smsSet
            setupReportSMDeliveryStatusRequestSuccess(smsSet, mapDialogSms.getApplicationContext().getApplicationContextVersion() != MAPApplicationContextVersion.version1);
            smsSet.setStatus(ErrorCode.SUCCESS);
            this.markDeliveringIsEnded(true);
        // this.freeSmsSetSucceded(smsSet, pers);
        }
    } finally {
        persistence.releaseSynchroObject(lock);
    }
}
Also used : MAPException(org.mobicents.protocols.ss7.map.api.MAPException) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) ArrayList(java.util.ArrayList) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) SmsSignalInfo(org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo) MAPDialogSms(org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms) Sms(org.mobicents.smsc.library.Sms) MAPErrorMessageSubscriberBusyForMtSms(org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageSubscriberBusyForMtSms) SmsSet(org.mobicents.smsc.library.SmsSet) SM_RP_DA(org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA)

Example 5 with SmscProcessingException

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

SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)18 Sms (org.mobicents.smsc.library.Sms)13 SmsSet (org.mobicents.smsc.library.SmsSet)9 TargetAddress (org.mobicents.smsc.library.TargetAddress)8 Esme (org.restcomm.smpp.Esme)6 EsmeManagement (org.restcomm.smpp.EsmeManagement)6 ArrayList (java.util.ArrayList)4 ISDNAddressString (org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString)4 Date (java.util.Date)3 MAPErrorMessageSubscriberBusyForMtSms (org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessageSubscriberBusyForMtSms)3 AddressString (org.mobicents.protocols.ss7.map.api.primitives.AddressString)3 MAPDialogSms (org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms)3 SM_RP_DA (org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA)3 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)3 EventType (org.mobicents.smsc.library.EventType)3 Tlv (com.cloudhopper.smpp.tlv.Tlv)2 FromHeader (javax.sip.header.FromHeader)2 Header (javax.sip.header.Header)2 ToHeader (javax.sip.header.ToHeader)2 Request (javax.sip.message.Request)2