Search in sources :

Example 1 with MessageDeliveryResultResponseInterface

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

the class ChargingSbb method acceptSms.

private void acceptSms(ChargingData chargingData) throws SmscProcessingException {
    Sms sms0 = chargingData.getSms();
    if (logger.isInfoEnabled()) {
        logger.info("ChargingSbb: accessGranted for: chargingType=" + chargingData.getChargingType() + ", message=[" + sms0 + "]");
    }
    try {
        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);
                sms.setTimestampC(System.currentTimeMillis());
                try {
                    synchronized (lock) {
                        boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
                        if (!storeAndForwMode) {
                            try {
                                this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
                            } catch (Exception e) {
                                throw new SmscProcessingException("Exception when runnung injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
                            }
                        } else {
                            if (smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast) {
                                try {
                                    sms.setStoringAfterFailure(true);
                                    this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
                                } catch (Exception e) {
                                    throw new SmscProcessingException("Exception when runnung injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
                                }
                            } else {
                                sms.setStored(true);
                                // if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
                                // persistence.createLiveSms(sms);
                                // persistence.setNewMessageScheduled(sms.getSmsSet(),
                                // MessageUtil.computeDueDate(MessageUtil.computeFirstDueDelay(smscPropertiesManagement.getFirstDueDelay())));
                                // } else {
                                this.scheduler.setDestCluster(sms.getSmsSet());
                                persistence.c2_scheduleMessage_ReschedDueSlot(sms, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast, false);
                            // }
                            }
                        }
                    }
                } finally {
                    persistence.releaseSynchroObject(lock);
                }
            }
        }
        if (mProcResult.isMessageRejected()) {
            rejectSmsByMproc(chargingData, true);
            return;
        }
        if (mProcResult.isMessageDropped()) {
            rejectSmsByMproc(chargingData, false);
            return;
        }
        // sending success response for charging result
        if (sms0.getMessageDeliveryResultResponse() != null && sms0.getMessageDeliveryResultResponse().isOnlyChargingRequest()) {
            sms0.getMessageDeliveryResultResponse().responseDeliverySuccess();
            sms0.setTimestampB(System.currentTimeMillis());
            EventType eventTypeSuccess = null;
            String messageType = null;
            String sourceAddr = null;
            int seqNum = -1;
            switch(sms0.getOriginationType()) {
                case SMPP:
                    eventTypeSuccess = EventType.IN_SMPP_RECEIVED;
                    MessageDeliveryResultResponseInterface resp = sms0.getMessageDeliveryResultResponse();
                    messageType = resp.getMessageType();
                    seqNum = resp.getSeqNumber();
                    break;
                case HTTP:
                    eventTypeSuccess = EventType.IN_HTTP_RECEIVED;
                    messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
                    break;
                default:
                    break;
            }
            if (eventTypeSuccess != null) {
                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) {
                        sourceAddr = esme.getRemoteAddressAndPort();
                    }
                }
                CdrDetailedGenerator.generateDetailedCdr(sms0, eventTypeSuccess, sms0.getSmsSet().getStatus(), messageType, SmppConstants.STATUS_OK, -1, sourceAddr, null, seqNum, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
            }
            sms0.setMessageDeliveryResultResponse(null);
        }
        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;
            default:
                break;
        }
    } catch (PersistenceException e) {
        if (sms0 != null) {
            generateCDR(sms0, CdrGenerator.CDR_SUBMIT_FAILED_CHARGING, e.getMessage(), false, true);
        }
        throw new SmscProcessingException("PersistenceException when storing LIVE_SMS : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
    }
}
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) MessageDeliveryResultResponseInterface(org.mobicents.smsc.library.MessageDeliveryResultResponseInterface) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException)

Aggregations

CreateException (javax.slee.CreateException)1 FastList (javolution.util.FastList)1 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)1 EventType (org.mobicents.smsc.library.EventType)1 MessageDeliveryResultResponseInterface (org.mobicents.smsc.library.MessageDeliveryResultResponseInterface)1 Sms (org.mobicents.smsc.library.Sms)1 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)1 TargetAddress (org.mobicents.smsc.library.TargetAddress)1 MProcResult (org.mobicents.smsc.mproc.impl.MProcResult)1 Esme (org.restcomm.smpp.Esme)1 EsmeManagement (org.restcomm.smpp.EsmeManagement)1