Search in sources :

Example 21 with TargetAddress

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

the class CassandraTest method readDueSlotMessage.

public SmsSet readDueSlotMessage(long dueSlot, int opt, int resSize) throws Exception {
    // reading dueSlot
    TargetAddress lock = this.sbb.obtainSynchroObject(ta2);
    try {
        synchronized (lock) {
            sbb.c2_registerDueSlotWriting(dueSlot);
            ArrayList<SmsSet> lst0, lst;
            try {
                lst0 = sbb.c2_getRecordList(dueSlot);
                lst = sbb.c2_sortRecordList(lst0);
            } finally {
                sbb.c2_unregisterDueSlotWriting(dueSlot);
            }
            assertEquals(lst.size(), resSize);
            SmsSet smsSet;
            if (resSize == 0) {
                // messages are not in res because smsSet is already in processing
                smsSet = SmsSetCache.getInstance().getProcessingSmsSet(ta1.getTargetId());
            } else {
                smsSet = lst.get(0);
            }
            if (opt == 1) {
                assertEquals(smsSet.getSmsCount(), 3);
                Sms sms1 = smsSet.getSms(0);
                Sms sms2 = smsSet.getSms(1);
                Sms sms3 = smsSet.getSms(2);
                assertEquals(sms1.getDueSlot(), dueSlot);
                assertEquals(sms2.getDueSlot(), dueSlot);
                assertEquals(sms3.getDueSlot(), dueSlot);
                this.checkTestSms(1, sms1, id1, false);
                this.checkTestSms(2, sms2, id2, false);
                this.checkTestSms(3, sms3, id3, false);
                assertEquals(smsSet.getCorrelationId(), "CI=100001000022222");
            } else {
                assertEquals(smsSet.getSmsCount(), 4);
                Sms sms1 = smsSet.getSms(0);
                Sms sms2 = smsSet.getSms(1);
                Sms sms3 = smsSet.getSms(2);
                assertEquals(sms1.getDueSlot(), dueSlot - 1);
                assertEquals(sms2.getDueSlot(), dueSlot - 1);
                assertEquals(sms3.getDueSlot(), dueSlot - 1);
                this.checkTestSms(1, sms1, id1, false);
                this.checkTestSms(2, sms2, id2, false);
                this.checkTestSms(3, sms3, id3, false);
                Sms sms5 = smsSet.getSms(3);
                assertEquals(sms5.getDueSlot(), dueSlot);
                this.checkTestSms(5, sms5, id5, false);
            }
            return smsSet;
        }
    } finally {
        this.sbb.obtainSynchroObject(lock);
    }
}
Also used : Sms(org.mobicents.smsc.library.Sms) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 22 with TargetAddress

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

the class SubmitCommonSbb method forwardMessage.

protected void forwardMessage(Sms sms0, boolean withCharging, SmscStatAggregator smscStatAggregator, String messageType, int seqNumber) throws SmscProcessingException {
    ChargingMedium chargingMedium = null;
    EventType eventTypeFailure = null;
    int statusCode = 0;
    switch(sms0.getOriginationType()) {
        case SMPP:
            chargingMedium = ChargingMedium.TxSmppOrig;
            eventTypeFailure = EventType.IN_SMPP_REJECT_MPROC;
            break;
        case SS7_MO:
        case SS7_HR:
            chargingMedium = ChargingMedium.MoOrig;
            break;
        case SIP:
            chargingMedium = ChargingMedium.TxSipOrig;
            break;
        case HTTP:
            chargingMedium = ChargingMedium.HttpOrig;
            eventTypeFailure = EventType.IN_HTTP_REJECT_MPROC;
            break;
    }
    if (withCharging) {
        ChargingSbbLocalObject chargingSbb = getChargingSbbObject();
        chargingSbb.setupChargingRequestInterface(chargingMedium, sms0);
    } else {
        // applying of MProc
        MProcResult mProcResult = MProcManagement.getInstance().applyMProcArrival(itsMProcRa, sms0, persistence);
        FastList<Sms> smss = mProcResult.getMessageList();
        if (smss != null) {
            for (FastList.Node<Sms> n = smss.head(), end = smss.tail(); (n = n.getNext()) != end; ) {
                Sms sms = n.getValue();
                TargetAddress ta = new TargetAddress(sms.getSmsSet());
                TargetAddress lock = persistence.obtainSynchroObject(ta);
                try {
                    sms.setTimestampC(System.currentTimeMillis());
                    synchronized (lock) {
                        boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
                        if (!storeAndForwMode) {
                            try {
                                this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
                            } catch (Exception e) {
                                throw new SmscProcessingException("Exception when running injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_INJECT_STORE_AND_FORWARD_NOT_SET);
                            }
                        } else {
                            // store and forward
                            if (smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast && sms.getScheduleDeliveryTime() == null) {
                                try {
                                    sms.setStoringAfterFailure(true);
                                    this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
                                } catch (Exception e) {
                                    throw new SmscProcessingException("Exception when running injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_INJECT_STORE_AND_FORWARD_FAST);
                                }
                            } else {
                                try {
                                    sms.setStored(true);
                                    this.scheduler.setDestCluster(sms.getSmsSet());
                                    persistence.c2_scheduleMessage_ReschedDueSlot(sms, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast, false);
                                } catch (PersistenceException e) {
                                    throw new SmscProcessingException("PersistenceException when storing LIVE_SMS : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_INJECT_STORE_AND_FORWARD_NORMAL);
                                }
                            }
                        }
                    }
                } finally {
                    persistence.releaseSynchroObject(lock);
                }
            }
        }
        if (mProcResult.isMessageRejected()) {
            sms0.setMessageDeliveryResultResponse(null);
            if (eventTypeFailure != null) {
                String sourceAddrAndPort = null;
                if (eventTypeFailure == EventType.IN_SMPP_REJECT_MPROC) {
                    EsmeManagement esmeManagement = EsmeManagement.getInstance();
                    if (esmeManagement != null) {
                        // for testing there is no EsmeManagement
                        Esme esme = esmeManagement.getEsmeByClusterName(sms0.getOrigEsmeName());
                        // null check is for testing
                        if (esme != null) {
                            sourceAddrAndPort = esme.getRemoteAddressAndPort();
                        }
                    }
                    statusCode = mProcResult.getSmppErrorCode();
                } else if (eventTypeFailure == EventType.IN_HTTP_REJECT_MPROC) {
                    statusCode = mProcResult.getHttpErrorCode();
                }
                generateMprocFailureDetailedCdr(sms0, eventTypeFailure, ErrorCode.REJECT_INCOMING_MPROC, messageType, statusCode, mProcResult.getRuleIdDropReject(), sourceAddrAndPort, seqNumber);
            }
            rejectSmsByMProc(sms0, "Message is rejected by MProc rules.", mProcResult);
        }
        if (mProcResult.isMessageDropped()) {
            sms0.setMessageDeliveryResultResponse(null);
            smscStatAggregator.updateMsgInFailedAll();
            if (eventTypeFailure != null) {
                String sourceAddrAndPort = null;
                if (eventTypeFailure == EventType.IN_SMPP_REJECT_MPROC) {
                    eventTypeFailure = EventType.IN_SMPP_DROP_MPROC;
                    EsmeManagement esmeManagement = EsmeManagement.getInstance();
                    if (esmeManagement != null) {
                        // for testing there is no EsmeManagement
                        Esme esme = esmeManagement.getEsmeByClusterName(sms0.getOrigEsmeName());
                        // null check is for testing
                        if (esme != null) {
                            sourceAddrAndPort = esme.getRemoteAddressAndPort();
                        }
                    }
                    statusCode = mProcResult.getSmppErrorCode();
                } else if (eventTypeFailure == EventType.IN_HTTP_REJECT_MPROC) {
                    eventTypeFailure = EventType.IN_HTTP_DROP_MPROC;
                    statusCode = mProcResult.getHttpErrorCode();
                }
                generateMprocFailureDetailedCdr(sms0, eventTypeFailure, ErrorCode.REJECT_INCOMING_MPROC, messageType, statusCode, mProcResult.getRuleIdDropReject(), sourceAddrAndPort, seqNumber);
            }
            rejectSmsByMProc(sms0, "Message is dropped by MProc rules.", mProcResult);
        }
        smscStatAggregator.updateMsgInReceivedAll();
        switch(sms0.getOriginationType()) {
            case SMPP:
                smscStatAggregator.updateMsgInReceivedSmpp();
                break;
            case SS7_MO:
                smscStatAggregator.updateMsgInReceivedSs7();
                smscStatAggregator.updateMsgInReceivedSs7Mo();
                break;
            case SS7_HR:
                smscStatAggregator.updateMsgInReceivedSs7();
                smscStatAggregator.updateMsgInReceivedSs7Hr();
                break;
            case SIP:
                smscStatAggregator.updateMsgInReceivedSip();
                break;
        }
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) EventType(org.mobicents.smsc.library.EventType) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Esme(org.restcomm.smpp.Esme) FastList(javolution.util.FastList) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) CreateException(javax.slee.CreateException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) ChargingSbbLocalObject(org.mobicents.smsc.slee.services.charging.ChargingSbbLocalObject) ChargingMedium(org.mobicents.smsc.slee.services.charging.ChargingMedium) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException)

Example 23 with TargetAddress

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

the class RxSmppServerSbb method handleResponse.

/**
 * Processing of a positive delivery response to smpp destination.
 *
 * @param event
 * @throws Exception
 */
private void handleResponse(BaseSmResp event) throws Exception {
    long ts = System.currentTimeMillis();
    if (isDeliveringEnded()) {
        if (logger.isFineEnabled()) {
            this.logger.fine("SMPP Response received when DeliveringEnded state: status=" + event.getCommandStatus());
        }
    }
    if (isDeliveringEnded()) {
        logger.info("RxSmppServerSbb.handleResponse(): received submit/deliver_sm_response but delivery process is already ended, dropping of a response");
        return;
    }
    SmsSet smsSet = getSmsSet();
    if (smsSet == null) {
        logger.severe("RxSmppServerSbb.handleResponse(): CMP smsSet is missed");
        markDeliveringIsEnded(true);
        return;
    }
    int status = event.getCommandStatus();
    if (status == 0) {
        smscStatAggregator.updateMsgOutSentAll();
        smscStatAggregator.updateMsgOutSentSmpp();
        boolean destAddressLimitationEnabled = false;
        EsmeManagement esmeManagement = EsmeManagement.getInstance();
        Esme esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
        if (esme != null) {
            destAddressLimitationEnabled = esme.getDestAddrSendLimit() != 0;
        }
        int realID = -1;
        Boolean sentListChanged = false;
        SentItemsList list = null;
        if (destAddressLimitationEnabled) {
            list = retreiveSentChunks();
            for (int i = 0; i < list.getSentList().size(); i++) {
                if (list.getSentList().get(i).getRemoteSequenceNumber() == event.getSequenceNumber()) {
                    realID = list.getSentList().get(i).getLocalSequenceNumber();
                    list.getSentList().remove(i);
                    sentListChanged = true;
                    break;
                }
            }
        } else {
            realID = event.getSequenceNumber();
        }
        ConfirmMessageInSendingPool confirmMessageInSendingPool = null;
        if (realID != -1)
            confirmMessageInSendingPool = confirmMessageInSendingPool(realID);
        if (realID == -1 || !confirmMessageInSendingPool.sequenceNumberFound) {
            this.logger.severe("RxSmppServerSbb.handleResponse(): no sms in MessageInSendingPool: UnconfirmedCnt=" + this.getUnconfirmedMessageCountInSendingPool() + ", sequenceNumber=" + event.getSequenceNumber() + ", realID=" + realID + ", confirmMessageInSendingPool=" + confirmMessageInSendingPool);
            this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SC_SYSTEM_ERROR, "Received undefined SequenceNumber: " + event.getSequenceNumber() + ", SmsSet=" + smsSet, EventType.OUT_SMPP_ERROR, realID);
            if (sentListChanged)
                setSentChunks(list);
            return;
        }
        Sms sms = confirmMessageInSendingPool.sms;
        if (sms != null) {
            sms.setTimestampC(System.currentTimeMillis());
        }
        if (destAddressLimitationEnabled) {
            ChunkDataList dataList = retreivePendingChunks();
            if (dataList != null && !dataList.getPendingList().isEmpty()) {
                // so checking if has window
                if (list.getSentList().size() < esme.getDestAddrSendLimit()) {
                    ChunkData current = dataList.getPendingList().remove(0);
                    setPendingChunks(dataList);
                    if (current != null) {
                        SentItem newItem = sendNextChunk(current, smsSet, esme);
                        SentItemsList sentChunks = retreiveSentChunks();
                        sentChunks.getSentList().add(newItem);
                        sentListChanged = true;
                    }
                }
            }
        }
        if (sentListChanged)
            setSentChunks(list);
        if (!confirmMessageInSendingPool.confirmed) {
            this.generateCDR(sms, CdrGenerator.CDR_PARTIAL_ESME, CdrGenerator.CDR_SUCCESS_NO_REASON, true, false, event.getSequenceNumber());
            String messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
            this.generateDetailedCDR(sms, EventType.OUT_SMPP_SENT, sms.getSmsSet().getStatus(), messageType, status, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
            return;
        }
        // firstly we store remote messageId if sms has a request to delivery receipt
        String clusterName = smsSet.getDestClusterName();
        String dlvMessageId = event.getMessageId();
        sms.setDlvMessageId(dlvMessageId);
        // if (MessageUtil.isDeliveryReceiptRequest(sms)) {
        // SmsSetCache.getInstance().putDeliveredRemoteMsgIdValue(dlvMessageId, clusterName, sms.getMessageId(), 30);
        // }
        // current message is sent
        // firstly sending of a positive response for transactional mode
        sendTransactionalResponseSuccess(sms);
        // mproc rules applying for delivery phase
        this.applyMprocRulesOnSuccess(sms, ProcessingType.SMPP);
        // Processing succeeded
        sms.getSmsSet().setStatus(ErrorCode.SUCCESS);
        this.postProcessSucceeded(sms, dlvMessageId, clusterName);
        // success CDR generating
        boolean isPartial = MessageUtil.isSmsNotLastSegment(sms);
        this.generateCDR(sms, isPartial ? CdrGenerator.CDR_PARTIAL_ESME : CdrGenerator.CDR_SUCCESS_ESME, CdrGenerator.CDR_SUCCESS_NO_REASON, confirmMessageInSendingPool.splittedMessage, true, event.getSequenceNumber());
        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();
        }
        if (messageType == null) {
            if (event.getCommandId() == SmppConstants.CMD_ID_DELIVER_SM_RESP) {
                messageType = CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
            } else {
                messageType = CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM;
            }
        }
        this.generateDetailedCDR(sms, EventType.OUT_SMPP_SENT, sms.getSmsSet().getStatus(), messageType, status, remoteAddr, event.getSequenceNumber());
        // adding a success receipt if it is needed
        this.generateSuccessReceipt(smsSet, sms);
        if (this.getUnconfirmedMessageCountInSendingPool() == 0) {
            // all sent messages are confirmed - we are sending new message set
            TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
            try {
                synchronized (lock) {
                    // marking the message in cache as delivered
                    this.commitSendingPoolMsgCount();
                    ts = warnIfLong(logger, ts, "handleResponse/status=0/in-lock/commitSendingPoolMsgCount");
                    // now we are trying to sent other messages
                    if (this.getTotalUnsentMessageCount() > 0) {
                        try {
                            this.sendDeliverSm(smsSet);
                            ts = warnIfLong(logger, ts, "handleResponse/status=0/in-lock/sendDeliverSm");
                            return;
                        } catch (SmscProcessingException e) {
                            SbbStatsUtils.handleProcessingException(e, getDefaultSbbUsageParameterSet());
                            String s = "SmscProcessingException when sending next sendDeliverSm()=" + e.getMessage() + ", Message=" + sms;
                            logger.severe(s, e);
                            this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SC_SYSTEM_ERROR, s, EventType.OUT_SMPP_ERROR, event.getSequenceNumber());
                        }
                    }
                    // no more messages to send - remove smsSet
                    smsSet.setStatus(ErrorCode.SUCCESS);
                    this.markDeliveringIsEnded(true);
                }
            } finally {
                persistence.releaseSynchroObject(lock);
            }
        }
    } else {
        ErrorAction errorAction = ErrorAction.permanentFailure;
        smsSet.setSmppCommandStatus(status);
        if (status == SmppConstants.STATUS_THROTTLED || status == SmppConstants.STATUS_X_T_APPN || status == SmppConstants.STATUS_SYSERR || status == SmppConstants.STATUS_INVBNDSTS || status == SmppConstants.STATUS_MSGQFUL)
            errorAction = ErrorAction.temporaryFailure;
        logger.warning("RxSmppServerSbb.handleResponse(): error code response received: status=" + status + ", errorAction=" + errorAction + ", smsSet=" + smsSet);
        this.onDeliveryError(smsSet, errorAction, ErrorCode.SC_SYSTEM_ERROR, event.getName() + " has a bad status: " + status, EventType.OUT_SMPP_REJECTED, event.getSequenceNumber());
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) ChunkData(org.mobicents.smsc.slee.services.deliverysbb.ChunkData) Esme(org.restcomm.smpp.Esme) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) TargetAddress(org.mobicents.smsc.library.TargetAddress) ChunkDataList(org.mobicents.smsc.slee.services.deliverysbb.ChunkDataList) ConfirmMessageInSendingPool(org.mobicents.smsc.slee.services.deliverysbb.ConfirmMessageInSendingPool) SentItemsList(org.mobicents.smsc.slee.services.deliverysbb.SentItemsList) ErrorAction(org.mobicents.smsc.library.ErrorAction) Sms(org.mobicents.smsc.library.Sms) SentItem(org.mobicents.smsc.slee.services.deliverysbb.SentItem) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 24 with TargetAddress

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

the class MoSbbTest method testMo4_MProc.

@Test(groups = { "Mo" })
public void testMo4_MProc() throws Exception {
    if (!this.cassandraDbInited)
        return;
    MProcManagement mProcManagement = MProcManagement.getInstance();
    SmscManagement smscManagement = SmscManagement.getInstance("Test");
    SmppManagement smppManagement = SmppManagement.getInstance("Test");
    smscManagement.setSmppManagement(smppManagement);
    mProcManagement.setSmscManagement(smscManagement);
    smscManagement.registerRuleFactory(new MProcRuleFactoryDefault());
    smscManagement.start();
    try {
        mProcManagement.destroyMProcRule(1);
    } catch (Exception e) {
    }
    try {
        mProcManagement.destroyMProcRule(2);
    } catch (Exception e) {
    }
    mProcManagement.createMProcRule(1, MProcRuleFactoryDefault.RULE_CLASS_NAME, "desttonmask 1 destnpimask 1 originatingmask SS7_MO networkidmask 0 adddestdigprefix 47 makecopy true");
    mProcManagement.createMProcRule(2, MProcRuleFactoryDefault.RULE_CLASS_NAME, "networkidmask 0 newnetworkid 5 newdestton 2 makecopy true");
    // TODO: ***** make proper mproc rules testing
    // MProcManagement.getInstance().createMProcRule(1, 1, 1, "-1", "SS7_MO", 0, -1, -1, -1, "47", true);
    // MProcManagement.getInstance().createMProcRule(2, -1, -1, "-1", null, 0, 5, 2, -1, "-1", true);
    // destTonMask, destNpiMask, destDigMask, originatingMask, networkIdMask, newNetworkId, newDestTon, newDestNpi, addDestDigPrefix, makeCopy
    // TODO: ***** make proper mproc rules testing
    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("UCS2 USC2 USC2"), dataCodingScheme, null, null);
    SmsTpdu tpdu = new SmsSubmitTpduImpl(false, false, false, 150, destinationAddress, protocolIdentifier, null, userData);
    SmsSignalInfo sm_RP_UI = new SmsSignalInfoImpl(tpdu, null);
    ForwardShortMessageRequest event = new ForwardShortMessageRequestImpl(sm_RP_DA, sm_RP_OA, sm_RP_UI, false);
    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);
    TargetAddress tax1 = new TargetAddress(1, 1, "475555", 0);
    TargetAddress tax2 = new TargetAddress(2, 1, "475555", 5);
    // int addrTon, int addrNpi, String addr, int networkId
    b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
    dueSlot = b2;
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
    assertEquals(b2, dueSlot);
    b2 = this.pers.c2_getDueSlotForTargetId(psc, tax1.getTargetId());
    long dueSlot2 = b2;
    b1 = this.pers.checkSmsExists(dueSlot, tax1.getTargetId());
    assertEquals(b1, 1);
    assertEquals(b2, dueSlot2);
    long dueSlot3 = b2;
    b1 = this.pers.checkSmsExists(dueSlot, tax1.getTargetId());
    assertEquals(b1, 1);
    assertEquals(b2, dueSlot3);
    assertEquals(dialog.getResponseCount(), 1);
    assertEquals(dialog.getErrorList().size(), 0);
    SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
    SmsSet smsSet2 = this.pers.c2_getRecordListForTargeId(dueSlot2, tax1.getTargetId());
    SmsSet smsSet3 = this.pers.c2_getRecordListForTargeId(dueSlot3, tax2.getTargetId());
    assertEquals(smsSet.getDestAddr(), "5555");
    assertEquals(smsSet.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet.getNetworkId(), 0);
    assertEquals(smsSet2.getDestAddr(), "475555");
    assertEquals(smsSet2.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet2.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet2.getNetworkId(), 0);
    assertEquals(smsSet3.getDestAddr(), "475555");
    assertEquals(smsSet3.getDestAddrTon(), SmppConstants.TON_NATIONAL);
    assertEquals(smsSet3.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet3.getNetworkId(), 5);
    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);
    assertEquals(sms.getShortMessageText(), "UCS2 USC2 USC2");
    assertNull(sms.getShortMessageBin());
    sms = smsSet2.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);
    assertEquals(sms.getShortMessageText(), "UCS2 USC2 USC2");
    assertNull(sms.getShortMessageBin());
    sms = smsSet3.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);
    assertEquals(sms.getShortMessageText(), "UCS2 USC2 USC2");
    assertNull(sms.getShortMessageBin());
    try {
        MProcManagement.getInstance().destroyMProcRule(1);
        MProcManagement.getInstance().destroyMProcRule(2);
    // MProcManagement.getInstance().destroyMProcRule(3);
    } catch (Exception e) {
    }
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) MProcManagement(org.mobicents.smsc.domain.MProcManagement) 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) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) 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) MProcRuleFactoryDefault(org.mobicents.smsc.mproc.impl.MProcRuleFactoryDefault) ProtocolIdentifierImpl(org.restcomm.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl) SmsSignalInfo(org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo) SmscManagement(org.mobicents.smsc.domain.SmscManagement) 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) SmppManagement(org.restcomm.smpp.SmppManagement) 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 25 with TargetAddress

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

the class DeliveryCommonSbb method obtainNextMessagesSendingPool.

/**
 * Arrange a new message sending pool with the poolMessageCount message count in it. If pending message count is less then
 * poolMessageCount then all pending message will be arranged to a message sending pool. Previous arranging pool will be
 * removed by this operation and pending messages in it will be marked as already processed. If you need to arrange only one
 * message in message sending pool you can use obtainNextMessage() method. Messages wit expired ValidityPeriod are not added
 * to a sendingPoolMsg but are processed as perm failed.
 *
 * @param poolMessageCount Max message count that must be included into a a new message sending pool
 * @param processingType
 * @return a count of messages in a new message pool
 */
protected int obtainNextMessagesSendingPool(int poolMessageCount, ProcessingType processingType) {
    commitSendingPoolMsgCount();
    if (smsSet != null) {
        int addedMessageCnt = 0;
        TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
        // ***** lock ******
        try {
            synchronized (lock) {
                int gotMessageCnt = 0;
                int sendingPoolMsgCount = this.getTotalUnsentMessageCount();
                for (int i1 = 0; i1 < sendingPoolMsgCount; i1++) {
                    if (addedMessageCnt >= poolMessageCount) {
                        break;
                    }
                    gotMessageCnt++;
                    Sms sms = smsSet.getSms(currentMsgNum + i1);
                    if (sms == null) {
                        this.logger.severe("RxSmpp obtainNextMessagesSendingPool() error: sms is not found num=" + i1 + " from " + sendingPoolMsgCount + ", smsSet=" + smsSet, new Throwable());
                        break;
                    }
                    if (sms.getValidityPeriod() != null && sms.getValidityPeriod().getTime() <= System.currentTimeMillis()) {
                        this.endDeliveryAfterValidityPeriod(sms, processingType, null, null);
                    } else {
                        boolean res1 = applyMProcPreDelivery(sms, processingType);
                        if (res1) {
                            addedMessageCnt++;
                            sms.setDeliveryCount(sms.getDeliveryCount() + 1);
                            smsSet.markSmsAsDelivered(currentMsgNum + i1);
                            smsSet.addMessageToSendingPool(sms);
                        }
                    }
                }
                sequenceNumbers = new int[addedMessageCnt];
                sequenceNumbersExtra = new int[addedMessageCnt][];
                if (gotMessageCnt > 0) {
                    currentMsgNum += gotMessageCnt;
                    this.setCurrentMsgNum(currentMsgNum);
                }
                this.rescheduleDeliveryTimer(sendingPoolMsgCount);
            }
        } finally {
            persistence.releaseSynchroObject(lock);
        }
        return addedMessageCnt;
    } else
        return 0;
}
Also used : Sms(org.mobicents.smsc.library.Sms) TargetAddress(org.mobicents.smsc.library.TargetAddress)

Aggregations

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