Search in sources :

Example 1 with TlvConvertException

use of com.cloudhopper.smpp.tlv.TlvConvertException 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 2 with TlvConvertException

use of com.cloudhopper.smpp.tlv.TlvConvertException in project smscgateway by RestComm.

the class TxSmppServerSbb method onSubmitSmLocal.

private void onSubmitSmLocal(final TxSmppServerSbbUsage anSbbUsage, final com.cloudhopper.smpp.pdu.SubmitSm event, final ActivityContextInterface aci) {
    // TODO remove it ...........................
    // long l2 = Date.parse(event.getServiceType());
    // Date dt0 = new Date(l2);
    Date dt0 = new Date();
    Date dt1 = new Date();
    // TODO remove it ...........................
    SmppTransaction smppServerTransaction = (SmppTransaction) aci.getActivity();
    Esme esme = smppServerTransaction.getEsme();
    String esmeName = esme.getName();
    long timestampB = 0;
    if (this.logger.isFineEnabled()) {
        this.logger.fine("\nReceived SUBMIT_SM = " + event + " from Esme name=" + esmeName);
    }
    CheckMessageLimitResult cres = esme.onMessageReceived(1);
    if (cres.getResult() != CheckMessageLimitResult.Result.ok) {
        if (cres.getResult() == CheckMessageLimitResult.Result.firstFault) {
            this.updateOverrateCounters(cres);
            this.logger.info(cres.getMessage());
        }
        if (smscPropertiesManagement.isGenerateRejectionCdr()) {
            generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, cres.getMessage(), true);
        }
        SubmitSmResp response = event.createResponse();
        response.setCommandStatus(SmppConstants.STATUS_THROTTLED);
        String s = cres.getMessage();
        if (s.length() > 255)
            s = s.substring(0, 255);
        Tlv tlv;
        try {
            tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
            response.addOptionalParameter(tlv);
        } catch (TlvConvertException e) {
            anSbbUsage.incrementCounterErrorSubmitSm(ONE);
            this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
        }
        // Lets send the Response with error here
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            timestampB = System.currentTimeMillis();
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorSubmitSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitSmResponse. Message: " + e.getMessage() + ".\nResponse: " + response + ".", e);
        }
        try {
            TargetAddress ta = createDestTargetAddress(event.getDestAddress(), esme.getNetworkId());
            Sms sms = this.createSmsEvent(event, esme, ta, persistence);
            sms.setTimestampB(timestampB);
            generateFailureDetailedCdr(sms, EventType.IN_SMPP_REJECT_CONG, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, SmppConstants.STATUS_THROTTLED, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        } catch (SmscProcessingException e1) {
        }
        return;
    }
    Sms sms = null;
    try {
        TargetAddress ta = createDestTargetAddress(event.getDestAddress(), esme.getNetworkId());
        sms = this.createSmsEvent(event, esme, ta, persistence);
        this.processSms(sms, persistence, esme, event, null, null, IncomingMessageType.submit_sm, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, event.getSequenceNumber());
    } catch (SmscProcessingException e1) {
        anSbbUsage.incrementCounterErrorSubmitSm(ONE);
        SbbStatsUtils.handleProcessingException(e1, anSbbUsage);
        if (!e1.isSkipErrorLogging()) {
            if (e1.isIsWarning()) {
                this.logger.warning(e1.getMessage());
            } else {
                this.logger.severe(e1.getMessage(), e1);
            }
            smscStatAggregator.updateMsgInFailedAll();
        }
        if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
            if (sms != null) {
                generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), false, true);
            } else {
                generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
            }
        }
        SubmitSmResp response = event.createResponse();
        response.setCommandStatus(e1.getSmppErrorCode());
        String s = e1.getMessage();
        if (s != null) {
            if (s.length() > 255)
                s = s.substring(0, 255);
            Tlv tlv;
            try {
                tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
                response.addOptionalParameter(tlv);
            } catch (TlvConvertException e) {
                this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
            }
        }
        // Lets send the Response with error here
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            timestampB = System.currentTimeMillis();
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorSubmitSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitSmResponse. Message: " + e.getMessage() + ".\nResponse: " + response + ".", e);
        }
        EventType eventType = null;
        if (e1.getInternalErrorCode() == SmscProcessingException.INTERNAL_ERROR_STATE_OVERLOADED) {
            eventType = EventType.IN_SMPP_REJECT_CONG;
        } else {
            eventType = EventType.IN_SMPP_REJECT_FORBIDDEN;
        }
        if (sms != null) {
            sms.setTimestampB(timestampB);
            generateRejectDetailedCdr(e1.getInternalErrorCode(), sms, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, e1.getSmppErrorCode(), esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        } else {
            generateRejectDetailedCdr(e1.getInternalErrorCode(), event, esme, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, e1.getSmppErrorCode(), parseShortMessageText(event), timestampB);
        }
        return;
    } catch (Throwable e1) {
        anSbbUsage.incrementCounterErrorSubmitSm(ONE);
        String s = "Exception when processing SubmitSm message: " + e1.getMessage();
        this.logger.severe(s, e1);
        smscStatAggregator.updateMsgInFailedAll();
        if (smscPropertiesManagement.isGenerateRejectionCdr()) {
            generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
        }
        SubmitSmResp response = event.createResponse();
        response.setCommandStatus(SmppConstants.STATUS_SYSERR);
        if (s.length() > 255)
            s = s.substring(0, 255);
        Tlv tlv;
        try {
            tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
            response.addOptionalParameter(tlv);
        } catch (TlvConvertException e) {
            this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
        }
        // Lets send the Response with error here
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            if (sms != null) {
                sms.setTimestampB(System.currentTimeMillis());
                generateFailureDetailedCdr(sms, EventType.IN_SMPP_ERROR, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, SmppConstants.STATUS_SYSERR, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
            }
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorSubmitSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitSmResponse. Message: " + e.getMessage() + ".\nResponse: " + response + ".", e);
        }
        return;
    }
    SubmitSmResp response = event.createResponse();
    response.setMessageId(sms.getMessageIdText());
    // Lets send the Response with success here
    try {
        if (sms.getMessageDeliveryResultResponse() == null) {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            sms.setTimestampB(System.currentTimeMillis());
            generateDetailedCDR(sms, EventType.IN_SMPP_RECEIVED, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, SmppConstants.STATUS_OK, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        }
    } catch (Throwable e) {
        anSbbUsage.incrementCounterErrorSubmitSmResponding(ONE);
        this.logger.severe("Error while trying to send SubmitSmResponse. Message: " + e.getMessage() + ".\nResponse: " + response + ".", e);
    }
    // TODO remove it ...........................
    Date dt3 = new Date();
    SmscStatProvider.getInstance().setParam1((int) (dt3.getTime() - dt0.getTime()));
    SmscStatProvider.getInstance().setParam2((int) (dt3.getTime() - dt1.getTime()));
// TODO remove it ...........................
}
Also used : TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) SmppTransaction(org.restcomm.slee.resource.smpp.SmppTransaction) Esme(org.restcomm.smpp.Esme) CheckMessageLimitResult(org.restcomm.smpp.CheckMessageLimitResult) Date(java.util.Date) ParseException(java.text.ParseException) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) CharacterCodingException(java.nio.charset.CharacterCodingException) SmppInvalidArgumentException(com.cloudhopper.smpp.type.SmppInvalidArgumentException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) SubmitSmResp(com.cloudhopper.smpp.pdu.SubmitSmResp) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 3 with TlvConvertException

use of com.cloudhopper.smpp.tlv.TlvConvertException in project smscgateway by RestComm.

the class TxSmppServerSbb method createSmsEvent.

// *********
// General Sms creating and processing methods
protected Sms createSmsEvent(BaseSm event, Esme origEsme, TargetAddress ta, PersistenceRAInterface store) throws SmscProcessingException {
    Sms sms = new Sms();
    sms.setDbId(UUID.randomUUID());
    sms.setOriginationType(OriginationType.SMPP);
    // checking parameters first
    if (event.getSourceAddress() == null || event.getSourceAddress().getAddress() == null || event.getSourceAddress().getAddress().isEmpty()) {
        throw new SmscProcessingException("SourceAddress digits are absent", SmppConstants.STATUS_INVSRCADR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_SRC_ADDR_INVALID);
    }
    sms.setSourceAddr(event.getSourceAddress().getAddress());
    sms.setSourceAddrTon(event.getSourceAddress().getTon());
    sms.setSourceAddrNpi(event.getSourceAddress().getNpi());
    sms.setOrigNetworkId(origEsme.getNetworkId());
    int dcs = event.getDataCoding();
    String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
    if (err != null) {
        throw new SmscProcessingException("TxSmpp DataCoding scheme does not supported: " + dcs + " - " + err, SmppExtraConstants.ESME_RINVDCS, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_DATA_CODING_INVALID);
    }
    // storing additional parameters
    ArrayList<Tlv> optionalParameters = event.getOptionalParameters();
    if (optionalParameters != null && optionalParameters.size() > 0) {
        for (Tlv tlv : optionalParameters) {
            if (tlv.getTag() != SmppConstants.TAG_MESSAGE_PAYLOAD) {
                sms.getTlvSet().addOptionalParameter(tlv);
            }
        }
    }
    DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
    sms.setDataCoding(dcs);
    sms.setOrigSystemId(origEsme.getSystemId());
    sms.setOrigEsmeName(origEsme.getName());
    sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
    sms.setServiceType(event.getServiceType());
    sms.setEsmClass(event.getEsmClass());
    sms.setProtocolId(event.getProtocolId());
    sms.setPriority(event.getPriority());
    sms.setRegisteredDelivery(event.getRegisteredDelivery());
    sms.setReplaceIfPresent(event.getReplaceIfPresent());
    sms.setDefaultMsgId(event.getDefaultMsgId());
    boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
    Tlv sarMsgRefNum = event.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
    Tlv sarTotalSegments = event.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
    Tlv sarSegmentSeqnum = event.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
    boolean segmentTlvFlag = (sarMsgRefNum != null && sarTotalSegments != null && sarSegmentSeqnum != null);
    // short message data
    byte[] data = event.getShortMessage();
    if (event.getShortMessageLength() == 0) {
        // Probably the message_payload Optional Parameter is being used
        Tlv messagePaylod = event.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
        if (messagePaylod != null) {
            data = messagePaylod.getValue();
        }
    }
    if (data == null) {
        data = new byte[0];
    }
    byte[] udhData;
    byte[] textPart;
    String msg;
    udhData = null;
    textPart = data;
    if (udhPresent && data.length > 2) {
        // UDH exists
        int udhLen = (textPart[0] & 0xFF) + 1;
        if (udhLen <= textPart.length) {
            textPart = new byte[textPart.length - udhLen];
            udhData = new byte[udhLen];
            System.arraycopy(data, udhLen, textPart, 0, textPart.length);
            System.arraycopy(data, 0, udhData, 0, udhLen);
        }
    }
    msg = parseShortMessageText(event);
    sms.setShortMessageText(msg);
    sms.setShortMessageBin(udhData);
    // checking of min / max length
    if (origEsme.getMinMessageLength() >= 0 && msg.length() < origEsme.getMinMessageLength()) {
        SmscProcessingException e = new SmscProcessingException("Message length is less than a min length limit for ESME=" + origEsme.getName() + ", len=" + msg.length(), SmppConstants.STATUS_INVMSGLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_SHORT);
        e.setSkipErrorLogging(true);
        throw e;
    }
    if (origEsme.getMaxMessageLength() >= 0 && msg.length() > origEsme.getMaxMessageLength()) {
        SmscProcessingException e = new SmscProcessingException("Message length is more than a max length limit for ESME=" + origEsme.getName() + ", len=" + msg.length(), SmppConstants.STATUS_INVMSGLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
        e.setSkipErrorLogging(true);
        throw e;
    }
    // checking max message length
    if (udhPresent || segmentTlvFlag) {
        // here splitting by SMSC is not supported
        UserDataHeader udh = null;
        int lenSolid = MessageUtil.getMaxSolidMessageBytesLength();
        if (udhPresent) {
            udh = new UserDataHeaderImpl(udhData);
        } else {
            udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
            if (udh != null && udh.getNationalLanguageLockingShift() != null) {
                lenSolid -= 3;
                sms.setNationalLanguageLockingShift(udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode());
            }
            if (udh != null && udh.getNationalLanguageSingleShift() != null) {
                lenSolid -= 3;
                sms.setNationalLanguageSingleShift(udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode());
            }
        }
        int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
        if (udhData != null)
            lenSolid -= udhData.length;
        if (messageLen > lenSolid) {
            throw new SmscProcessingException("Message length in bytes is too big for solid message: " + messageLen + ">" + lenSolid, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
        }
    } else {
        // here splitting by SMSC is supported
        int lenSegmented = MessageUtil.getMaxSegmentedMessageBytesLength();
        UserDataHeader udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
        if (msg.length() * 2 > (lenSegmented - 6) * 255) {
            // firstly draft length check
            int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
            if (udh != null) {
                if (udh.getNationalLanguageLockingShift() != null) {
                    lenSegmented -= 3;
                    sms.setNationalLanguageLockingShift(udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode());
                }
                if (udh.getNationalLanguageSingleShift() != null) {
                    lenSegmented -= 3;
                    sms.setNationalLanguageSingleShift(udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode());
                }
            }
            if (messageLen > lenSegmented * 255) {
                throw new SmscProcessingException("Message length in bytes is too big for segmented message: " + messageLen + ">" + lenSegmented, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
            }
        } else {
            if (udh != null) {
                if (udh.getNationalLanguageLockingShift() != null) {
                    sms.setNationalLanguageLockingShift(udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode());
                }
                if (udh.getNationalLanguageSingleShift() != null) {
                    sms.setNationalLanguageSingleShift(udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode());
                }
            }
        }
    }
    // ValidityPeriod processing
    Tlv tlvQosTimeToLive = event.getOptionalParameter(SmppConstants.TAG_QOS_TIME_TO_LIVE);
    Date validityPeriod;
    if (tlvQosTimeToLive != null) {
        long valTime;
        try {
            valTime = (new Date()).getTime() + tlvQosTimeToLive.getValueAsInt();
        } catch (TlvConvertException e) {
            throw new SmscProcessingException("TlvConvertException when getting TAG_QOS_TIME_TO_LIVE tlv field: " + e.getMessage(), SmppConstants.STATUS_INVOPTPARAMVAL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
        }
        validityPeriod = new Date(valTime);
    } else {
        try {
            validityPeriod = MessageUtil.parseSmppDate(event.getValidityPeriod());
        } catch (ParseException e) {
            throw new SmscProcessingException("ParseException when parsing ValidityPeriod field: " + e.getMessage(), SmppConstants.STATUS_INVEXPIRY, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
        }
    }
    MessageUtil.applyValidityPeriod(sms, validityPeriod, true, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
    // ScheduleDeliveryTime processing
    Date scheduleDeliveryTime;
    try {
        scheduleDeliveryTime = MessageUtil.parseSmppDate(event.getScheduleDeliveryTime());
    } catch (ParseException e) {
        throw new SmscProcessingException("ParseException when parsing ScheduleDeliveryTime field: " + e.getMessage(), SmppConstants.STATUS_INVSCHED, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_SCHEDULER_DELIVERY_TIME_PARSING);
    }
    MessageUtil.applyScheduleDeliveryTime(sms, scheduleDeliveryTime);
    SmsSet smsSet;
    smsSet = new SmsSet();
    smsSet.setDestAddr(ta.getAddr());
    smsSet.setDestAddrNpi(ta.getAddrNpi());
    smsSet.setDestAddrTon(ta.getAddrTon());
    smsSet.setNetworkId(origEsme.getNetworkId());
    smsSet.addSms(sms);
    sms.setSmsSet(smsSet);
    long messageId = store.c2_getNextMessageId();
    SmscStatProvider.getInstance().setCurrentMessageId(messageId);
    sms.setMessageId(messageId);
    return sms;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) UserDataHeaderImpl(org.mobicents.protocols.ss7.map.smstpdu.UserDataHeaderImpl) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) Timestamp(java.sql.Timestamp) Date(java.util.Date) ParseException(java.text.ParseException) UserDataHeader(org.mobicents.protocols.ss7.map.api.smstpdu.UserDataHeader) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 4 with TlvConvertException

use of com.cloudhopper.smpp.tlv.TlvConvertException in project smscgateway by RestComm.

the class TxSmppServerSbb method onSubmitMultiLocal.

private void onSubmitMultiLocal(final TxSmppServerSbbUsage anSbbUsage, final com.cloudhopper.smpp.pdu.SubmitMulti event, final ActivityContextInterface aci) {
    SmppTransaction smppServerTransaction = (SmppTransaction) aci.getActivity();
    Esme esme = smppServerTransaction.getEsme();
    String esmeName = esme.getName();
    if (this.logger.isFineEnabled()) {
        this.logger.fine("\nReceived SUBMIT_MULTI = " + event + " from Esme name=" + esmeName);
    }
    List<Address> addrList = event.getDestAddresses();
    int msgCnt = 0;
    if (addrList != null)
        msgCnt = addrList.size();
    CheckMessageLimitResult cres = esme.onMessageReceived(msgCnt);
    if (cres.getResult() != CheckMessageLimitResult.Result.ok) {
        if (cres.getResult() == CheckMessageLimitResult.Result.firstFault) {
            this.updateOverrateCounters(cres);
            this.logger.info(cres.getMessage());
        }
        if (smscPropertiesManagement.isGenerateRejectionCdr()) {
            generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, cres.getMessage(), true);
        }
        SubmitMultiResp response = event.createResponse();
        response.setCommandStatus(SmppConstants.STATUS_THROTTLED);
        String s = cres.getMessage();
        if (s.length() > 255)
            s = s.substring(0, 255);
        Tlv tlv;
        try {
            tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
            response.addOptionalParameter(tlv);
        } catch (TlvConvertException e) {
            anSbbUsage.incrementCounterErrorSubmitMultiSm(ONE);
            this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
        }
        // Lets send the Response with error here
        long timestampB = 0L;
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            timestampB = System.currentTimeMillis();
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
        }
        try {
            TargetAddress ta = createDestTargetAddress(event.getDestAddress(), esme.getNetworkId());
            Sms sms = this.createSmsEvent(event, esme, ta, persistence);
            sms.setTimestampB(timestampB);
            generateFailureDetailedCdr(sms, EventType.IN_SMPP_REJECT_CONG, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, SmppConstants.STATUS_THROTTLED, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        } catch (SmscProcessingException e1) {
        }
        return;
    }
    SubmitMultiParseResult parseResult;
    Sms singleSms = null;
    try {
        parseResult = this.createSmsEventMulti(event, esme, persistence, esme.getNetworkId());
        for (Sms sms : parseResult.getParsedMessages()) {
            singleSms = sms;
            this.processSms(sms, persistence, esme, null, null, event, IncomingMessageType.submit_multi, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, event.getSequenceNumber());
        }
    } catch (SmscProcessingException e1) {
        anSbbUsage.incrementCounterErrorSubmitMultiSm(ONE);
        SbbStatsUtils.handleProcessingException(e1, anSbbUsage);
        if (!e1.isSkipErrorLogging()) {
            if (e1.isIsWarning()) {
                this.logger.warning(e1.getMessage());
            } else {
                this.logger.severe(e1.getMessage(), e1);
            }
            smscStatAggregator.updateMsgInFailedAll();
        }
        if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
            if (singleSms != null) {
                generateCDR(singleSms, CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), false, true);
            } else {
                generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
            }
        }
        SubmitMultiResp response = event.createResponse();
        response.setCommandStatus(e1.getSmppErrorCode());
        String s = e1.getMessage();
        if (s != null) {
            if (s.length() > 255)
                s = s.substring(0, 255);
            Tlv tlv;
            try {
                tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
                response.addOptionalParameter(tlv);
            } catch (TlvConvertException e) {
                this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
            }
        }
        // Lets send the Response with error here
        long timestampB = 0L;
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            timestampB = System.currentTimeMillis();
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
        }
        EventType eventType = null;
        if (e1.getInternalErrorCode() == SmscProcessingException.INTERNAL_ERROR_STATE_OVERLOADED) {
            eventType = EventType.IN_SMPP_REJECT_CONG;
        } else {
            eventType = EventType.IN_SMPP_REJECT_FORBIDDEN;
        }
        if (singleSms != null) {
            singleSms.setTimestampB(timestampB);
            generateRejectDetailedCdr(e1.getInternalErrorCode(), singleSms, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, e1.getSmppErrorCode(), esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        } else {
            generateRejectDetailedCdr(e1.getInternalErrorCode(), event, esme, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, e1.getSmppErrorCode(), parseShortMessageText(event), timestampB);
        }
        return;
    } catch (Throwable e1) {
        anSbbUsage.incrementCounterErrorSubmitMultiSm(ONE);
        String s = "Exception when processing SubmitMulti message: " + e1.getMessage();
        this.logger.severe(s, e1);
        smscStatAggregator.updateMsgInFailedAll();
        if (smscPropertiesManagement.isGenerateRejectionCdr()) {
            generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
        }
        SubmitMultiResp response = event.createResponse();
        response.setCommandStatus(SmppConstants.STATUS_SYSERR);
        if (s.length() > 255)
            s = s.substring(0, 255);
        Tlv tlv;
        try {
            tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
            response.addOptionalParameter(tlv);
        } catch (TlvConvertException e) {
            this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
        }
        // Lets send the Response with error here
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            if (singleSms != null) {
                singleSms.setTimestampB(System.currentTimeMillis());
                generateFailureDetailedCdr(singleSms, EventType.IN_SMPP_ERROR, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, SmppConstants.STATUS_SYSERR, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
            }
            anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
        } catch (Exception e) {
            this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
        }
        return;
    }
    SubmitMultiResp response = event.createResponse();
    Sms sms = null;
    if (parseResult.getParsedMessages().size() > 0)
        sms = parseResult.getParsedMessages().get(0);
    if (sms != null)
        response.setMessageId(sms.getMessageIdText());
    for (UnsucessfulSME usme : parseResult.getBadAddresses()) {
        try {
            response.addUnsucessfulSME(usme);
        } catch (SmppInvalidArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // Lets send the Response with success here
    try {
        if (sms == null || sms.getMessageDeliveryResultResponse() == null) {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            sms.setTimestampB(System.currentTimeMillis());
            generateDetailedCDR(sms, EventType.IN_SMPP_RECEIVED, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, SmppConstants.STATUS_OK, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        }
    } catch (Throwable e) {
        anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
        this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
    }
}
Also used : TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) SmppTransaction(org.restcomm.slee.resource.smpp.SmppTransaction) Address(com.cloudhopper.smpp.type.Address) UnsucessfulSME(com.cloudhopper.smpp.type.UnsucessfulSME) Esme(org.restcomm.smpp.Esme) CheckMessageLimitResult(org.restcomm.smpp.CheckMessageLimitResult) ParseException(java.text.ParseException) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) CharacterCodingException(java.nio.charset.CharacterCodingException) SmppInvalidArgumentException(com.cloudhopper.smpp.type.SmppInvalidArgumentException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) SubmitMultiResp(com.cloudhopper.smpp.pdu.SubmitMultiResp) SmppInvalidArgumentException(com.cloudhopper.smpp.type.SmppInvalidArgumentException) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 5 with TlvConvertException

use of com.cloudhopper.smpp.tlv.TlvConvertException in project smscgateway by RestComm.

the class TxSmppServerSbb method onDeliverSmLocal.

private void onDeliverSmLocal(final TxSmppServerSbbUsage anSbbUsage, final com.cloudhopper.smpp.pdu.DeliverSm event, final ActivityContextInterface aci) {
    SmppTransaction smppServerTransaction = (SmppTransaction) aci.getActivity();
    Esme esme = smppServerTransaction.getEsme();
    String esmeName = esme.getName();
    if (this.logger.isFineEnabled()) {
        this.logger.fine("\nReceived DELIVER_SM = " + event + " from Esme name=" + esmeName);
    }
    CheckMessageLimitResult cres = esme.onMessageReceived(1);
    if (cres.getResult() != CheckMessageLimitResult.Result.ok) {
        if (cres.getResult() == CheckMessageLimitResult.Result.firstFault) {
            this.updateOverrateCounters(cres);
            this.logger.info(cres.getMessage());
        }
        if (smscPropertiesManagement.isGenerateRejectionCdr()) {
            generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, cres.getMessage(), true);
        }
        DeliverSmResp response = event.createResponse();
        response.setCommandStatus(SmppConstants.STATUS_THROTTLED);
        String s = cres.getMessage();
        if (s.length() > 255)
            s = s.substring(0, 255);
        Tlv tlv;
        try {
            tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
            response.addOptionalParameter(tlv);
        } catch (TlvConvertException e) {
            anSbbUsage.incrementCounterErrorDeliverSm(ONE);
            this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
        }
        // Lets send the Response with error here
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorDeliverSmResponding(ONE);
            this.logger.severe("Error while trying to send DeliverSmResponse=" + response, e);
        }
        try {
            TargetAddress ta = createDestTargetAddress(event.getDestAddress(), esme.getNetworkId());
            Sms sms = this.createSmsEvent(event, esme, ta, persistence);
            sms.setTimestampB(System.currentTimeMillis());
            generateFailureDetailedCdr(sms, EventType.IN_SMPP_REJECT_CONG, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM, SmppConstants.STATUS_THROTTLED, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        } catch (SmscProcessingException e1) {
        }
        return;
    }
    Sms sms = null;
    try {
        TargetAddress ta = createDestTargetAddress(event.getDestAddress(), esme.getNetworkId());
        sms = this.createSmsEvent(event, esme, ta, persistence);
        this.processSms(sms, persistence, esme, null, null, null, IncomingMessageType.deliver_sm, CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM, event.getSequenceNumber());
    } catch (SmscProcessingException e1) {
        anSbbUsage.incrementCounterErrorDeliverSm(ONE);
        SbbStatsUtils.handleProcessingException(e1, anSbbUsage);
        if (!e1.isSkipErrorLogging()) {
            if (e1.isIsWarning()) {
                this.logger.warning(e1.getMessage());
            } else {
                this.logger.severe(e1.getMessage(), e1);
            }
            smscStatAggregator.updateMsgInFailedAll();
        }
        if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
            if (sms != null) {
                generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), false, true);
            } else {
                generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
            }
        }
        DeliverSmResp response = event.createResponse();
        response.setCommandStatus(e1.getSmppErrorCode());
        String s = e1.getMessage();
        if (s != null) {
            if (s.length() > 255)
                s = s.substring(0, 255);
            Tlv tlv;
            try {
                tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
                response.addOptionalParameter(tlv);
            } catch (TlvConvertException e) {
                this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
            }
        }
        // Lets send the Response with error here
        long timestampB = 0L;
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            timestampB = System.currentTimeMillis();
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorDeliverSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitSmResponse=" + response, e);
        }
        EventType eventType = null;
        if (e1.getInternalErrorCode() == SmscProcessingException.INTERNAL_ERROR_STATE_OVERLOADED) {
            eventType = EventType.IN_SMPP_REJECT_CONG;
        } else {
            eventType = EventType.IN_SMPP_REJECT_FORBIDDEN;
        }
        if (sms != null) {
            sms.setTimestampB(timestampB);
            generateRejectDetailedCdr(e1.getInternalErrorCode(), sms, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM, e1.getSmppErrorCode(), esme.getRemoteAddressAndPort(), event.getSequenceNumber());
        } else {
            generateRejectDetailedCdr(e1.getInternalErrorCode(), event, esme, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM, e1.getSmppErrorCode(), parseShortMessageText(event), timestampB);
        }
        return;
    } catch (Throwable e1) {
        anSbbUsage.incrementCounterErrorDeliverSm(ONE);
        String s = "Exception when processing SubmitSm message: " + e1.getMessage();
        this.logger.severe(s, e1);
        smscStatAggregator.updateMsgInFailedAll();
        if (smscPropertiesManagement.isGenerateRejectionCdr()) {
            generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
        }
        DeliverSmResp response = event.createResponse();
        response.setCommandStatus(SmppConstants.STATUS_SYSERR);
        if (s.length() > 255)
            s = s.substring(0, 255);
        Tlv tlv;
        try {
            tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
            response.addOptionalParameter(tlv);
        } catch (TlvConvertException e) {
            this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
        }
        // Lets send the Response with error here
        try {
            this.smppServerSessions.sendResponsePdu(esme, event, response);
            if (sms != null) {
                sms.setTimestampB(System.currentTimeMillis());
                generateFailureDetailedCdr(sms, EventType.IN_SMPP_ERROR, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM, SmppConstants.STATUS_SYSERR, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
            }
        } catch (Exception e) {
            anSbbUsage.incrementCounterErrorDeliverSmResponding(ONE);
            this.logger.severe("Error while trying to send SubmitSmResponse=" + response, e);
        }
        return;
    }
    DeliverSmResp response = event.createResponse();
    // Lets send the Response with success here
    try {
        this.smppServerSessions.sendResponsePdu(esme, event, response);
        sms.setTimestampB(System.currentTimeMillis());
        generateDetailedCDR(sms, EventType.IN_SMPP_RECEIVED, CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM, SmppConstants.STATUS_OK, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
    } catch (Throwable e) {
        anSbbUsage.incrementCounterErrorDeliverSmResponding(ONE);
        this.logger.severe("Error while trying to send SubmitSmResponse=" + response, e);
    }
}
Also used : TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) SmppTransaction(org.restcomm.slee.resource.smpp.SmppTransaction) Esme(org.restcomm.smpp.Esme) CheckMessageLimitResult(org.restcomm.smpp.CheckMessageLimitResult) ParseException(java.text.ParseException) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) CharacterCodingException(java.nio.charset.CharacterCodingException) SmppInvalidArgumentException(com.cloudhopper.smpp.type.SmppInvalidArgumentException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) DeliverSmResp(com.cloudhopper.smpp.pdu.DeliverSmResp) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

Tlv (com.cloudhopper.smpp.tlv.Tlv)9 TlvConvertException (com.cloudhopper.smpp.tlv.TlvConvertException)9 ParseException (java.text.ParseException)7 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)4 SmppInvalidArgumentException (com.cloudhopper.smpp.type.SmppInvalidArgumentException)4 CharacterCodingException (java.nio.charset.CharacterCodingException)4 Date (java.util.Date)4 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)4 SmppTransaction (org.restcomm.slee.resource.smpp.SmppTransaction)4 CheckMessageLimitResult (org.restcomm.smpp.CheckMessageLimitResult)4 Esme (org.restcomm.smpp.Esme)4 UserDataHeaderImpl (org.mobicents.protocols.ss7.map.smstpdu.UserDataHeaderImpl)3 Address (com.cloudhopper.smpp.type.Address)2 UnsucessfulSME (com.cloudhopper.smpp.type.UnsucessfulSME)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)2 UserDataHeader (org.mobicents.protocols.ss7.map.api.smstpdu.UserDataHeader)2 DataCodingSchemeImpl (org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)2 DataSmResp (com.cloudhopper.smpp.pdu.DataSmResp)1