Search in sources :

Example 6 with ValidityPeriod

use of org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod in project smscgateway by RestComm.

the class MoSbbTest method testMo3_Usc2.

@Test(groups = { "Mo" })
public void testMo3_Usc2() throws Exception {
    if (!this.cassandraDbInited)
        return;
    // this.clearDatabase();
    // SmppSessionsProxy smppServerSessions = new SmppSessionsProxy();
    // this.sbb.setSmppServerSessions(smppServerSessions);
    AddressString serviceCentreAddressDA = new AddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "1111");
    SM_RP_DA sm_RP_DA = new SM_RP_DAImpl(serviceCentreAddressDA);
    ISDNAddressString msisdn = new ISDNAddressStringImpl(AddressNature.international_number, NumberingPlan.ISDN, "4444");
    SM_RP_OAImpl sm_RP_OA = new SM_RP_OAImpl();
    sm_RP_OA.setMsisdn(msisdn);
    AddressField destinationAddress = new AddressFieldImpl(TypeOfNumber.InternationalNumber, NumberingPlanIdentification.ISDNTelephoneNumberingPlan, "5555");
    ProtocolIdentifier protocolIdentifier = new ProtocolIdentifierImpl(12);
    DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(8);
    UserData userData = new UserDataImpl(new String("������"), dataCodingScheme, null, null);
    // String decodedMessage, DataCodingScheme dataCodingScheme, UserDataHeader decodedUserDataHeader, Charset gsm8Charset
    SmsTpdu tpdu = new SmsSubmitTpduImpl(false, false, false, 150, destinationAddress, protocolIdentifier, null, userData);
    // boolean rejectDuplicates, boolean replyPathExists, boolean statusReportRequest, int messageReference,
    // AddressField destinationAddress, ProtocolIdentifier protocolIdentifier, ValidityPeriod validityPeriod, UserData userData
    // tpdu.encodeData();
    SmsSignalInfo sm_RP_UI = new SmsSignalInfoImpl(tpdu, null);
    ForwardShortMessageRequest event = new ForwardShortMessageRequestImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, false);
    // ActivityContextInterface aci = new SmppTransactionProxy(esme);
    // Date curDate = new Date();
    // this.fillSm(event, curDate, true);
    // event.setShortMessage(msg);
    long dueSlot = this.pers.c2_getDueSlotForTime(new Date());
    PreparedStatementCollection psc = this.pers.getStatementCollection(new Date());
    int b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    long b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
    assertEquals(b1, 0);
    assertEquals(b2, 0L);
    MAPProviderProxy proxy = new MAPProviderProxy();
    MAPDialogSmsProxy dialog = new MAPDialogSmsProxy(new MAPServiceSmsProxy(proxy), null, null, null);
    event.setMAPDialog(dialog);
    Date curDate = new Date();
    MAPApplicationContext act = MAPApplicationContext.getInstance(MAPApplicationContextName.shortMsgMORelayContext, MAPApplicationContextVersion.version2);
    dialog.setApplicationContext(act);
    this.sbb.onForwardShortMessageRequest(event, null);
    b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
    dueSlot = b2;
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
    assertEquals(b2, dueSlot);
    assertEquals(dialog.getResponseCount(), 1);
    assertEquals(dialog.getErrorList().size(), 0);
    SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
    assertEquals(smsSet.getDestAddr(), "5555");
    assertEquals(smsSet.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet.getInSystem(), 0);
    assertEquals(smsSet.getDueDelay(), 0);
    assertNull(smsSet.getStatus());
    assertFalse(smsSet.isAlertingSupported());
    Sms sms = smsSet.getSms(0);
    assertNotNull(sms);
    assertEquals(sms.getSourceAddr(), "4444");
    assertEquals(sms.getSourceAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(sms.getSourceAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(sms.getMessageId(), DBOperations.MESSAGE_ID_LAG + 1);
    assertEquals(sms.getMoMessageRef(), 150);
    assertEquals(sms.getDataCoding(), 8);
    assertNull(sms.getOrigEsmeName());
    assertNull(sms.getOrigSystemId());
    assertNull(sms.getServiceType());
    assertEquals(sms.getEsmClass() & 0xFF, 3);
    assertEquals(sms.getRegisteredDelivery(), 0);
    assertEquals(sms.getProtocolId(), 12);
    assertEquals(sms.getPriority(), 0);
    assertEquals(sms.getReplaceIfPresent(), 0);
    assertEquals(sms.getDefaultMsgId(), 0);
    assertEquals(sms.getTlvSet().getOptionalParameterCount(), 0);
    assertNull(sms.getScheduleDeliveryTime());
    assertDateEq(sms.getValidityPeriod(), MessageUtil.addHours(curDate, 24 * 3));
    assertEquals(sms.getDeliveryCount(), 0);
    // assertDateEq(smsSet.getDueDate(), new Date(curDate.getTime() + 1 * 60 * 1000));
    // Charset ucs2Charset = Charset.forName("UTF-16BE");
    // ByteBuffer bb = ByteBuffer.wrap(sms.getShortMessage());
    // CharBuffer bf = ucs2Charset.decode(bb);
    // String s = bf.toString();
    // assertEquals(s, "������");
    assertEquals(sms.getShortMessageText(), "������");
    assertNull(sms.getShortMessageBin());
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) MAPServiceSmsProxy(org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.restcomm.protocols.ss7.map.api.primitives.AddressString) UserData(org.restcomm.protocols.ss7.map.api.smstpdu.UserData) SmsTpdu(org.restcomm.protocols.ss7.map.api.smstpdu.SmsTpdu) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) SmsSignalInfoImpl(org.restcomm.protocols.ss7.map.service.sms.SmsSignalInfoImpl) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.restcomm.protocols.ss7.map.api.primitives.AddressString) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ProtocolIdentifierImpl(org.restcomm.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl) SmsSignalInfo(org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo) UserDataImpl(org.restcomm.protocols.ss7.map.smstpdu.UserDataImpl) MAPProviderProxy(org.mobicents.smsc.slee.resources.persistence.MAPProviderProxy) ProtocolIdentifier(org.restcomm.protocols.ss7.map.api.smstpdu.ProtocolIdentifier) ISDNAddressStringImpl(org.restcomm.protocols.ss7.map.primitives.ISDNAddressStringImpl) AddressStringImpl(org.restcomm.protocols.ss7.map.primitives.AddressStringImpl) AddressField(org.restcomm.protocols.ss7.map.api.smstpdu.AddressField) ForwardShortMessageRequestImpl(org.restcomm.protocols.ss7.map.service.sms.ForwardShortMessageRequestImpl) MoForwardShortMessageRequestImpl(org.restcomm.protocols.ss7.map.service.sms.MoForwardShortMessageRequestImpl) SM_RP_DAImpl(org.restcomm.protocols.ss7.map.service.sms.SM_RP_DAImpl) AddressFieldImpl(org.restcomm.protocols.ss7.map.smstpdu.AddressFieldImpl) ForwardShortMessageRequest(org.restcomm.protocols.ss7.map.api.service.sms.ForwardShortMessageRequest) MoForwardShortMessageRequest(org.restcomm.protocols.ss7.map.api.service.sms.MoForwardShortMessageRequest) SM_RP_OAImpl(org.restcomm.protocols.ss7.map.service.sms.SM_RP_OAImpl) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) MAPDialogSmsProxy(org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy) ISDNAddressStringImpl(org.restcomm.protocols.ss7.map.primitives.ISDNAddressStringImpl) Sms(org.mobicents.smsc.library.Sms) SM_RP_DA(org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA) MAPApplicationContext(org.restcomm.protocols.ss7.map.api.MAPApplicationContext) SmsSet(org.mobicents.smsc.library.SmsSet) SmsSubmitTpduImpl(org.restcomm.protocols.ss7.map.smstpdu.SmsSubmitTpduImpl) Test(org.testng.annotations.Test)

Example 7 with ValidityPeriod

use of org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod in project smscgateway by RestComm.

the class DeliveryCommonSbb method endDeliveryAfterValidityPeriod.

/**
 * Finishing delivering of a message which validity period is over at the start of delivery time.
 *
 * @param sms
 * @param processingType
 * @param dlvMessageId
 * @param dlvDestId
 */
protected void endDeliveryAfterValidityPeriod(Sms sms, ProcessingType processingType, String dlvMessageId, String dlvDestId) {
    // ending of delivery process in this SBB
    ErrorCode smStatus = ErrorCode.VALIDITY_PERIOD_EXPIRED;
    ErrorAction errorAction = ErrorAction.permanentFailure;
    String reason = "Validity period is expired";
    smsSet.setStatus(smStatus);
    StringBuilder sb = new StringBuilder();
    sb.append("onDeliveryError: errorAction=validityExpired");
    sb.append(", smStatus=");
    sb.append(smStatus);
    sb.append(", targetId=");
    sb.append(smsSet.getTargetId());
    sb.append(", smsSet=");
    sb.append(smsSet);
    sb.append(", reason=");
    sb.append(reason);
    if (this.logger.isInfoEnabled())
        this.logger.info(sb.toString());
    // mproc rules applying for delivery phase
    MProcResult mProcResult = MProcManagement.getInstance().applyMProcDelivery(itsMProcRa, sms, true, processingType);
    if (mProcResult.isMessageIsRerouted()) {
        // we do not reroute a message with expired validity period
        sb = new StringBuilder();
        sb.append("Can not reroute of a message with expired ValidityPeriod, sms=");
        sb.append(sms);
        this.logger.warning(sb.toString());
    }
    FastList<Sms> addedMessages = mProcResult.getMessageList();
    if (addedMessages != null) {
        for (FastList.Node<Sms> n = addedMessages.head(), end = addedMessages.tail(); (n = n.getNext()) != end; ) {
            Sms smst = n.getValue();
            TargetAddress ta = new TargetAddress(smst.getSmsSet().getDestAddrTon(), smst.getSmsSet().getDestAddrNpi(), smst.getSmsSet().getDestAddr(), smst.getSmsSet().getNetworkId());
            this.sendNewGeneratedMessage(smst, ta);
            if (this.logger.isInfoEnabled()) {
                sb = new StringBuilder();
                sb.append("Posting of a new message after PermFailure-ValidityPeriod: targetId=");
                sb.append(smst.getSmsSet().getTargetId());
                sb.append(", sms=");
                sb.append(smst);
                this.logger.info(sb.toString());
            }
        }
    }
    ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
    lstPermFailured.add(sms);
    // sending of a failure response for transactional mode
    this.sendTransactionalResponseFailure(lstPermFailured, null, errorAction, null);
    // Processing messages that were temp or permanent failed or rerouted
    this.postProcessPermFailures(lstPermFailured, dlvMessageId, dlvDestId);
    // generating CDRs for permanent failure messages
    this.generateCDRs(lstPermFailured, CdrGenerator.CDR_FAILED, reason);
    EsmeManagement esmeManagement = EsmeManagement.getInstance();
    if (esmeManagement != null) {
        Esme esme = null;
        if (smsSet.getDestClusterName() != null) {
            esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
        }
        String messageType = null;
        String remoteAddr = null;
        if (esme != null) {
            messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
            remoteAddr = esme.getRemoteAddressAndPort();
        }
        this.generateDetailedCDRs(lstPermFailured, EventType.VALIDITY_PERIOD_TIMEOUT, smStatus, messageType, remoteAddr, -1);
    }
    // sending of failure delivery receipts
    this.generateFailureReceipts(smsSet, lstPermFailured, null);
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) Esme(org.restcomm.smpp.Esme) FastList(javolution.util.FastList) ArrayList(java.util.ArrayList) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) ErrorAction(org.mobicents.smsc.library.ErrorAction) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) ErrorCode(org.mobicents.smsc.library.ErrorCode)

Example 8 with ValidityPeriod

use of org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod in project smscgateway by RestComm.

the class MoSbb method createSmsEvent.

private Sms createSmsEvent(SmsSubmitTpdu smsSubmitTpdu, TargetAddress ta, PersistenceRAInterface store, AddressString callingPartyAddress, int networkId, String originatorSccpAddress) throws SmscProcessingException {
    UserData userData = smsSubmitTpdu.getUserData();
    try {
        userData.decode();
    } catch (MAPException e) {
        throw new SmscProcessingException("MO MAPException when decoding user data", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    Sms sms = new Sms();
    sms.setDbId(UUID.randomUUID());
    sms.setOriginationType(OriginationType.SS7_MO);
    // checking parameters first
    if (callingPartyAddress == null || callingPartyAddress.getAddress() == null || callingPartyAddress.getAddress().isEmpty()) {
        throw new SmscProcessingException("MO SourceAddress digits are absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getAddressNature() == null) {
        throw new SmscProcessingException("MO SourceAddress AddressNature is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getNumberingPlan() == null) {
        throw new SmscProcessingException("MO SourceAddress NumberingPlan is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setSourceAddr(callingPartyAddress.getAddress());
    sms.setOriginatorSccpAddress(originatorSccpAddress);
    sms.setSourceAddrTon(callingPartyAddress.getAddressNature().getIndicator());
    sms.setSourceAddrNpi(callingPartyAddress.getNumberingPlan().getIndicator());
    sms.setOrigNetworkId(networkId);
    sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
    int messageingMode = (smscPropertiesManagement.getMoDefaultMessagingMode() & 0x03);
    sms.setEsmClass(messageingMode | (smsSubmitTpdu.getUserDataHeaderIndicator() ? SmppConstants.ESM_CLASS_UDHI_MASK : 0) | (smsSubmitTpdu.getReplyPathExists() ? SmppConstants.ESM_CLASS_REPLY_PATH_MASK : 0));
    sms.setProtocolId(smsSubmitTpdu.getProtocolIdentifier().getCode());
    sms.setPriority(0);
    // TODO: do we need somehow care with RegisteredDelivery ?
    sms.setReplaceIfPresent(smsSubmitTpdu.getRejectDuplicates() ? 2 : 0);
    sms.setStatusReportRequest(smsSubmitTpdu.getStatusReportRequest());
    DataCodingScheme dataCodingScheme = smsSubmitTpdu.getDataCodingScheme();
    int dcs = dataCodingScheme.getCode();
    String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
    if (err != null) {
        throw new SmscProcessingException("MO DataCoding scheme does not supported: " + dcs + " - " + err, SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setDataCoding(dcs);
    sms.setShortMessageText(userData.getDecodedMessage());
    UserDataHeader udh = userData.getDecodedUserDataHeader();
    if (udh != null) {
        sms.setShortMessageBin(udh.getEncodedData());
    }
    // ValidityPeriod processing
    ValidityPeriod vp = smsSubmitTpdu.getValidityPeriod();
    ValidityPeriodFormat vpf = smsSubmitTpdu.getValidityPeriodFormat();
    Date validityPeriod = null;
    if (vp != null && vpf != null && vpf != ValidityPeriodFormat.fieldNotPresent) {
        switch(vpf) {
            case fieldPresentAbsoluteFormat:
                AbsoluteTimeStamp ats = vp.getAbsoluteFormatValue();
                Date dt = new Date(ats.getYear(), ats.getMonth(), ats.getDay(), ats.getHour(), ats.getMinute(), ats.getSecond());
                int i1 = ats.getTimeZone() * 15 * 60;
                int i2 = -new Date().getTimezoneOffset() * 60;
                long i3 = (i2 - i1) * 1000;
                validityPeriod = new Date(dt.getTime() + i3);
                break;
            case fieldPresentRelativeFormat:
                validityPeriod = new Date(new Date().getTime() + (long) (vp.getRelativeFormatHours() * 3600 * 1000));
                break;
            case fieldPresentEnhancedFormat:
                this.logger.info("Recieved unsupported ValidityPeriodFormat: PresentEnhancedFormat - we skip it");
                break;
        }
    }
    MessageUtil.applyValidityPeriod(sms, validityPeriod, false, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
    SmsSet smsSet;
    smsSet = new SmsSet();
    smsSet.setDestAddr(ta.getAddr());
    smsSet.setDestAddrNpi(ta.getAddrNpi());
    smsSet.setDestAddrTon(ta.getAddrTon());
    smsSet.setNetworkId(networkId);
    smsSet.addSms(sms);
    long messageId = store.c2_getNextMessageId();
    SmscStatProvider.getInstance().setCurrentMessageId(messageId);
    sms.setMessageId(messageId);
    sms.setMoMessageRef(smsSubmitTpdu.getMessageReference());
    return sms;
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) AbsoluteTimeStamp(org.restcomm.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp) UserData(org.restcomm.protocols.ss7.map.api.smstpdu.UserData) MAPException(org.restcomm.protocols.ss7.map.api.MAPException) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.restcomm.protocols.ss7.map.api.primitives.AddressString) Timestamp(java.sql.Timestamp) Date(java.util.Date) ValidityPeriodFormat(org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriodFormat) MAPDialogSms(org.restcomm.protocols.ss7.map.api.service.sms.MAPDialogSms) ValidityPeriod(org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)

Example 9 with ValidityPeriod

use of org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod in project smscgateway by RestComm.

the class MoSbb method createSmsEvent.

private Sms createSmsEvent(SmsDeliverTpdu smsDeliverTpdu, TargetAddress ta, PersistenceRAInterface store, CorrelationIdValue civ, int networkId, String originatorSccpAddress) throws SmscProcessingException {
    UserData userData = smsDeliverTpdu.getUserData();
    try {
        userData.decode();
    } catch (MAPException e) {
        throw new SmscProcessingException("MT MAPException when decoding user data", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    Sms sms = new Sms();
    sms.setDbId(UUID.randomUUID());
    sms.setOriginationType(OriginationType.SS7_HR);
    AddressField callingPartyAddress = smsDeliverTpdu.getOriginatingAddress();
    // checking parameters first
    if (callingPartyAddress == null || callingPartyAddress.getAddressValue() == null || callingPartyAddress.getAddressValue().isEmpty()) {
        throw new SmscProcessingException("Home routing: TPDU OriginatingAddress digits are absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getTypeOfNumber() == null) {
        throw new SmscProcessingException("Home routing: TPDU OriginatingAddress TypeOfNumber is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getNumberingPlanIdentification() == null) {
        throw new SmscProcessingException("Home routing: TPDU OriginatingAddress NumberingPlanIdentification is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setSourceAddr(callingPartyAddress.getAddressValue());
    sms.setOriginatorSccpAddress(originatorSccpAddress);
    if (callingPartyAddress.getTypeOfNumber() == TypeOfNumber.Alphanumeric) {
        sms.setSourceAddrTon(TypeOfNumber.Alphanumeric.getCode());
        sms.setSourceAddrNpi(NumberingPlanIdentification.Unknown.getCode());
    } else {
        sms.setSourceAddrTon(callingPartyAddress.getTypeOfNumber().getCode());
        sms.setSourceAddrNpi(callingPartyAddress.getNumberingPlanIdentification().getCode());
    }
    sms.setOrigNetworkId(networkId);
    sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
    int messageingMode = (smscPropertiesManagement.getHrDefaultMessagingMode() & 0x03);
    sms.setEsmClass(messageingMode | (smsDeliverTpdu.getUserDataHeaderIndicator() ? SmppConstants.ESM_CLASS_UDHI_MASK : 0) | (smsDeliverTpdu.getReplyPathExists() ? SmppConstants.ESM_CLASS_REPLY_PATH_MASK : 0));
    sms.setProtocolId(smsDeliverTpdu.getProtocolIdentifier().getCode());
    sms.setPriority(0);
    // TODO: do we need somehow care with RegisteredDelivery ?
    sms.setReplaceIfPresent(0);
    // TODO: care with smsSubmitTpdu.getStatusReportRequest() parameter
    // sending back SMS_STATUS_REPORT tpdu ?
    DataCodingScheme dataCodingScheme = smsDeliverTpdu.getDataCodingScheme();
    int dcs = dataCodingScheme.getCode();
    String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
    if (err != null) {
        throw new SmscProcessingException("Home routing: DataCoding scheme does not supported: " + dcs + " - " + err, SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setDataCoding(dcs);
    sms.setShortMessageText(userData.getDecodedMessage());
    UserDataHeader udh = userData.getDecodedUserDataHeader();
    if (udh != null) {
        sms.setShortMessageBin(udh.getEncodedData());
    }
    // ValidityPeriod processing
    MessageUtil.applyValidityPeriod(sms, null, false, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
    SmsSet smsSet;
    smsSet = new SmsSet();
    smsSet.setDestAddr(ta.getAddr());
    smsSet.setDestAddrNpi(ta.getAddrNpi());
    smsSet.setDestAddrTon(ta.getAddrTon());
    smsSet.setNetworkId(networkId);
    smsSet.setCorrelationId(civ.getCorrelationID());
    smsSet.setImsi(civ.getImsi());
    smsSet.setLocationInfoWithLMSI(civ.getLocationInfoWithLMSI());
    smsSet.addSms(sms);
    sms.setSmsSet(smsSet);
    long messageId = store.c2_getNextMessageId();
    SmscStatProvider.getInstance().setCurrentMessageId(messageId);
    sms.setMessageId(messageId);
    return sms;
}
Also used : AddressField(org.restcomm.protocols.ss7.map.api.smstpdu.AddressField) DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) UserData(org.restcomm.protocols.ss7.map.api.smstpdu.UserData) MAPException(org.restcomm.protocols.ss7.map.api.MAPException) MAPDialogSms(org.restcomm.protocols.ss7.map.api.service.sms.MAPDialogSms) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.restcomm.protocols.ss7.map.api.primitives.AddressString) Timestamp(java.sql.Timestamp) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)

Example 10 with ValidityPeriod

use of org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod in project smscgateway by RestComm.

the class TxSipServerSbb method onMESSAGE.

// *********
// SIP Event Handlers
public void onMESSAGE(javax.sip.RequestEvent event, ActivityContextInterface aci) {
    if (this.logger.isFineEnabled()) {
        this.logger.fine("onMESSAGE " + event);
    }
    Sip sip = sipManagement.getSipByName(SipManagement.SIP_NAME);
    try {
        final Request request = event.getRequest();
        byte[] message = request.getRawContent();
        final ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
        final String toUser = ((SipUri) toHeader.getAddress().getURI()).getUser();
        final FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
        final String fromUser = ((SipUri) fromHeader.getAddress().getURI()).getUser();
        // Persist this message
        TargetAddress ta = this.createDestTargetAddress(toUser, sip.getNetworkId());
        byte[] udh = null;
        Header udhHeader = request.getHeader(SipXHeaders.XSmsUdh);
        if (udhHeader != null) {
            udh = this.hexStringToByteArray(((SIPHeader) udhHeader).getValue());
        }
        Header codingHeader = request.getHeader(SipXHeaders.XSmsCoding);
        DataCodingSchemeImpl codingSchme = dcsGsm7;
        if (codingHeader != null) {
            int dcs = Integer.parseInt(((SIPHeader) codingHeader).getValue());
            codingSchme = this.createDataCodingScheme(dcs);
        }
        Date validityPeriod = null;
        Header validityHeader = request.getHeader(SipXHeaders.XSmsValidty);
        if (validityHeader != null) {
            try {
                validityPeriod = MessageUtil.parseDate(((SIPHeader) validityHeader).getValue());
            } catch (ParseException e) {
                logger.severe("ParseException when parsing ValidityPeriod field: " + e.getMessage(), e);
                if (smscPropertiesManagement.isGenerateRejectionCdr()) {
                    generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e.getMessage(), true);
                }
                ServerTransaction serverTransaction = event.getServerTransaction();
                Response res;
                try {
                    res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
                    event.getServerTransaction().sendResponse(res);
                } catch (Exception e1) {
                    this.logger.severe("Exception while trying to send 500 response to sip", e1);
                }
                return;
            }
        }
        // Registered Delivery
        int regDeliveryInt = 0;
        Header regDeliveryHeader = request.getHeader(SipXHeaders.XRegDelivery);
        if (regDeliveryHeader != null) {
            regDeliveryInt = Integer.parseInt(((SIPHeader) regDeliveryHeader).getValue());
        }
        Sms sms = null;
        try {
            sms = this.createSmsEvent(fromUser, message, ta, persistence, udh, codingSchme, validityPeriod, regDeliveryInt, sip.getNetworkId());
            this.processSms(sms, persistence);
        } catch (SmscProcessingException e1) {
            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_SIP, e1.getMessage(), false, true);
                } else {
                    generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
                }
            }
            ServerTransaction serverTransaction = event.getServerTransaction();
            Response res;
            try {
                res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
                event.getServerTransaction().sendResponse(res);
            } catch (Exception e) {
                this.logger.severe("Exception while trying to send Ok response to sip", e);
            }
            return;
        } catch (Throwable e1) {
            this.logger.severe("Exception while processing a message from sip", e1);
            smscStatAggregator.updateMsgInFailedAll();
            if (smscPropertiesManagement.isGenerateRejectionCdr()) {
                generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
            }
            ServerTransaction serverTransaction = event.getServerTransaction();
            Response res;
            try {
                // TODO: we possibly need to response ERROR message to sip
                res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
                event.getServerTransaction().sendResponse(res);
            } catch (Exception e) {
                this.logger.severe("Exception while trying to send Ok response to sip", e);
            }
            return;
        }
        ServerTransaction serverTransaction = event.getServerTransaction();
        Response res;
        try {
            res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
            event.getServerTransaction().sendResponse(res);
        } catch (Exception e) {
            this.logger.severe("Exception while trying to send Ok response to sip", e);
        }
    } catch (Exception e) {
        this.logger.severe("Error while trying to process received the SMS " + event, e);
    }
}
Also used : FromHeader(javax.sip.header.FromHeader) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Request(javax.sip.message.Request) TargetAddress(org.mobicents.smsc.library.TargetAddress) SipUri(gov.nist.javax.sip.address.SipUri) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) Date(java.util.Date) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) ParseException(java.text.ParseException) Response(javax.sip.message.Response) ToHeader(javax.sip.header.ToHeader) FromHeader(javax.sip.header.FromHeader) SIPHeader(gov.nist.javax.sip.header.SIPHeader) Header(javax.sip.header.Header) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ToHeader(javax.sip.header.ToHeader) Sms(org.mobicents.smsc.library.Sms) Sip(org.mobicents.smsc.domain.Sip) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction)

Aggregations

Date (java.util.Date)8 DataCodingScheme (org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme)8 DataCodingSchemeImpl (org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)7 Sms (org.mobicents.smsc.library.Sms)6 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)6 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)5 UserData (org.restcomm.protocols.ss7.map.api.smstpdu.UserData)5 UserDataHeader (org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)5 Timestamp (java.sql.Timestamp)4 AddressField (org.restcomm.protocols.ss7.map.api.smstpdu.AddressField)4 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)3 SmsSet (org.mobicents.smsc.library.SmsSet)3 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)3 MAPProviderProxy (org.mobicents.smsc.slee.resources.persistence.MAPProviderProxy)3 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)3 MoForwardShortMessageRequest (org.restcomm.protocols.ss7.map.api.service.sms.MoForwardShortMessageRequest)3 SM_RP_DA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA)3 SmsSignalInfo (org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo)3