Search in sources :

Example 26 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class ChargingSbb method rejectSmsByMproc.

private void rejectSmsByMproc(ChargingData chargingData, boolean isRejected) throws SmscProcessingException {
    Sms sms = chargingData.getSms();
    if (logger.isInfoEnabled()) {
        logger.info("ChargingSbb: incoming message is " + (isRejected ? "rejected" : "dropped") + " by mProc rules, message=[" + sms + "]");
    }
    CdrGenerator.generateCdr(sms, (isRejected ? CdrGenerator.CDR_MPROC_REJECTED : CdrGenerator.CDR_MPROC_DROPPED), "Message is rejected by MProc rules.", smscPropertiesManagement.getGenerateReceiptCdr(), MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateCdr()), false, true, smscPropertiesManagement.getCalculateMsgPartsLenCdr(), smscPropertiesManagement.getDelayParametersInCdr());
    try {
        // sending of a failure response for transactional mode / delaying for charging result
        MessageDeliveryResultResponseInterface.DeliveryFailureReason delReason = MessageDeliveryResultResponseInterface.DeliveryFailureReason.invalidDestinationAddress;
        if (sms.getMessageDeliveryResultResponse() != null) {
            if (isRejected) {
                sms.getMessageDeliveryResultResponse().responseDeliveryFailure(delReason, null);
                sms.setMessageDeliveryResultResponse(null);
            } else {
                sms.getMessageDeliveryResultResponse().responseDeliverySuccess();
                sms.setMessageDeliveryResultResponse(null);
            }
        }
        sms.getSmsSet().setStatus(ErrorCode.MPROC_ACCESS_NOT_GRANTED);
        boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
        if (storeAndForwMode) {
            sms.setStored(true);
        }
        // if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
        // persistence.archiveFailuredSms(sms);
        // } else {
        String sourceAddrAndPort = null;
        String messageType = null;
        EventType eventType = null;
        switch(sms.getOriginationType()) {
            case SMPP:
                EsmeManagement esmeManagement = EsmeManagement.getInstance();
                Esme esme = esmeManagement.getEsmeByClusterName(sms.getSmsSet().getDestClusterName());
                eventType = EventType.IN_SMPP_REJECT_MPROC;
                if (esme != null) {
                    sourceAddrAndPort = esme.getRemoteAddressAndPort();
                    // shouldn't have null value
                    messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
                }
                break;
            case HTTP:
                messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
                eventType = EventType.IN_HTTP_REJECT_MPROC;
                break;
            default:
                break;
        }
        if (eventType != null) {
            CdrDetailedGenerator.generateDetailedCdr(sms, eventType, sms.getSmsSet().getStatus(), messageType, 0, -1, sourceAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
        }
        if (MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateArchiveTable())) {
            persistence.c2_createRecordArchive(sms, null, null, !smscPropertiesManagement.getReceiptsDisabling(), smscPropertiesManagement.getIncomeReceiptsProcessing());
        }
        // }
        smscStatAggregator.updateMsgInRejectedAll();
        CdrGenerator.generateCdr(sms, (isRejected ? CdrGenerator.CDR_MPROC_REJECTED : CdrGenerator.CDR_MPROC_DROPPED), CdrGenerator.CDR_SUCCESS_NO_REASON, smscPropertiesManagement.getGenerateReceiptCdr(), MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateCdr()), false, true, smscPropertiesManagement.getCalculateMsgPartsLenCdr(), smscPropertiesManagement.getDelayParametersInCdr());
    } catch (PersistenceException e) {
        throw new SmscProcessingException("PersistenceException when storing into Archive rejected by MProc message : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) MessageDeliveryResultResponseInterface(org.mobicents.smsc.library.MessageDeliveryResultResponseInterface) EventType(org.mobicents.smsc.library.EventType) Esme(org.restcomm.smpp.Esme) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException)

Example 27 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class PersistenceRAInterfaceProxy method checkSmsExists.

public int checkSmsExists(long dueSlot, String targetId) throws PersistenceException {
    try {
        String s1 = "select \"ID\" from \"SLOT_MESSAGES_TABLE" + this.getTableName(dueSlot) + "\" where \"DUE_SLOT\"=? and \"TARGET_ID\"=?;";
        PreparedStatement ps = session.prepare(s1);
        BoundStatement boundStatement = new BoundStatement(ps);
        boundStatement.bind(dueSlot, targetId);
        ResultSet rs = session.execute(boundStatement);
        return rs.all().size();
    } catch (Exception e) {
        int ggg = 0;
        ggg = 0;
        return -1;
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) IOException(java.io.IOException)

Example 28 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException 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

PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)28 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)12 ResultSet (com.datastax.driver.core.ResultSet)12 XMLStreamException (javolution.xml.stream.XMLStreamException)11 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)10 Sms (org.mobicents.smsc.library.Sms)9 Date (java.util.Date)6 SmsSet (org.mobicents.smsc.library.SmsSet)5 Row (com.datastax.driver.core.Row)4 CreateException (javax.slee.CreateException)4 EventType (org.mobicents.smsc.library.EventType)4 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)4 TargetAddress (org.mobicents.smsc.library.TargetAddress)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DbSmsRoutingRule (org.mobicents.smsc.library.DbSmsRoutingRule)3 MessageDeliveryResultResponseInterface (org.mobicents.smsc.library.MessageDeliveryResultResponseInterface)3 Esme (org.restcomm.smpp.Esme)3 EsmeManagement (org.restcomm.smpp.EsmeManagement)3