use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class DeliveryCommonSbb method postProcessSucceeded.
// *********
// ending / rescheduling of messages after successful / failed delivering and for next delivery attempts
/**
* Processing messages that were succeeded (sms.inSystem=sent in live database, adding of archive record).
*
* @param sms
* @param dlvMessageId
* @param dlvDestId
*/
protected void postProcessSucceeded(Sms sms, String dlvMessageId, String dlvDestId) {
try {
sms.setDeliveryDate(new Date());
persistence.c2_updateInSystem(sms, DBOperations.IN_SYSTEM_SENT, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast);
if (MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateArchiveTable())) {
persistence.c2_createRecordArchive(sms, dlvMessageId, dlvDestId, !smscPropertiesManagement.getReceiptsDisabling(), smscPropertiesManagement.getIncomeReceiptsProcessing());
}
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when DeliveryCommonSbb.postProcessSucceeded()" + e.getMessage(), e);
}
}
use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class TxSmppServerSbb method processSms.
private void processSms(Sms sms0, PersistenceRAInterface store, Esme esme, SubmitSm eventSubmit, DataSm eventData, SubmitMulti eventSubmitMulti, IncomingMessageType incomingMessageType, String messageType, int seqNumber) throws SmscProcessingException {
sms0.setTimestampA(System.currentTimeMillis());
if (logger.isInfoEnabled()) {
logger.info(String.format("Received %s to ESME: %s, sms=%s", incomingMessageType.toString(), esme.getName(), sms0.toString()));
}
this.checkSmscState(sms0, smscCongestionControl, SubmitCommonSbb.MaxActivityCountFactor.factor_12);
boolean withCharging = false;
switch(smscPropertiesManagement.getTxSmppChargingType()) {
case Selected:
withCharging = esme.isChargingEnabled();
break;
case All:
withCharging = true;
break;
}
if (withCharging && (eventSubmit == null && eventData == null)) {
// we do not support of charging of submit_multi
String msg = "SMSC GW does not support charging for sumbit_multi and deliver_sm, a message is rejected";
logger.warning(msg);
SmscProcessingException e = new SmscProcessingException(msg, SmppConstants.STATUS_PROHIBITED, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_INJECT_STORE_AND_FORWARD_FAST);
e.setSkipErrorLogging(true);
throw e;
}
// transactional mode / or charging request
boolean isTransactional = (eventSubmit != null || eventData != null) && MessageUtil.isTransactional(sms0);
if (isTransactional || withCharging) {
MessageDeliveryResultResponseSmpp messageDeliveryResultResponse = new MessageDeliveryResultResponseSmpp(!isTransactional, this.smppServerSessions, esme, eventSubmit, eventData, sms0.getMessageId());
sms0.setMessageDeliveryResultResponse(messageDeliveryResultResponse);
}
// delivery receipt transit - replacing of messageId in delivery receipt with local messageId
if (smscPropertiesManagement.getIncomeReceiptsProcessing() && MessageUtil.isDeliveryReceipt(sms0)) {
DeliveryReceiptData deliveryReceiptData = MessageUtil.parseDeliveryReceipt(sms0.getShortMessageText(), sms0.getTlvSet());
if (deliveryReceiptData != null) {
String clusterName = esme.getClusterName();
String dlvTlvMessageId = deliveryReceiptData.getTlvReceiptedMessageId();
String dlvMessageId = deliveryReceiptData.getMessageId();
Long messageId = null;
String drFormat = null;
if (dlvTlvMessageId != null) {
try {
messageId = persistence.c2_getMessageIdByRemoteMessageId(dlvTlvMessageId, clusterName);
drFormat = "dlvTlvMessageId";
} catch (PersistenceException e) {
logger.severe("Exception when running c2_getMessageIdByRemoteMessageId() - 1: " + e.getMessage(), e);
}
}
if (messageId == null) {
// trying to parse as a hex format
try {
messageId = persistence.c2_getMessageIdByRemoteMessageId(dlvMessageId, clusterName);
drFormat = "dlvMessageId";
} catch (PersistenceException e) {
logger.severe("Exception when running c2_getMessageIdByRemoteMessageId() - 2: " + e.getMessage(), e);
} catch (NumberFormatException e) {
}
}
if (messageId != null) {
// we found in local cache / database a reference to an origin
logger.info("Remote delivery receipt: clusterName=" + clusterName + ", dlvMessageId=" + dlvMessageId + ", dlvTlvMessageId=" + dlvTlvMessageId + ", receipt=" + sms0.getShortMessageText() + ", drFormat=" + drFormat);
if (dlvTlvMessageId != null) {
sms0.setReceiptOrigMessageId(dlvTlvMessageId);
sms0.getTlvSet().removeOptionalParameter(SmppConstants.TAG_RECEIPTED_MSG_ID);
} else {
sms0.setReceiptOrigMessageId(dlvMessageId);
}
sms0.setReceiptLocalMessageId(messageId);
String messageIdStr = MessageUtil.createMessageIdString(messageId);
String updatedReceiptText = MessageUtil.createDeliveryReceiptMessage(messageIdStr, deliveryReceiptData.getSubmitDate(), deliveryReceiptData.getDoneDate(), deliveryReceiptData.getError(), deliveryReceiptData.getText(), deliveryReceiptData.getStatus().equals(MessageUtil.DELIVERY_ACK_STATE_DELIVERED), null, deliveryReceiptData.getStatus().equals(MessageUtil.DELIVERY_ACK_STATE_ENROUTE));
sms0.setShortMessageText(updatedReceiptText);
} else {
// we have not found a local message - marking as unrecognized receipt
logger.warning("Remote delivery receipt - but no original message is found in local cache: clusterName=" + clusterName + ", dlvMessageId=" + dlvMessageId + ", dlvTlvMessageId=" + dlvTlvMessageId + ", receipt=" + sms0.getShortMessageText() + ", drFormat=" + drFormat);
sms0.setReceiptLocalMessageId(-1L);
}
}
}
this.forwardMessage(sms0, withCharging, smscStatAggregator, messageType, seqNumber);
}
use of org.mobicents.smsc.cassandra.PersistenceException 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;
}
}
}
use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class DeliveryCommonSbb method sendNewGeneratedMessage.
// *********
// sending of generated messages (delivery receipts and messages that were generated by mproc rules)
private void sendNewGeneratedMessage(Sms sms, TargetAddress ta) {
boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
TargetAddress lock = SmsSetCache.getInstance().addSmsSet(ta);
try {
synchronized (lock) {
if (!storeAndForwMode) {
try {
this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
} catch (Exception e) {
this.logger.severe("Exception when runnung injectSmsOnFly() for receipt in sendNewGeneratedMessage(): " + e.getMessage(), e);
}
} else {
if (smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast) {
try {
sms.setStoringAfterFailure(true);
this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
} catch (Exception e) {
this.logger.severe("Exception when runnung injectSmsOnFly() for receipt in sendNewGeneratedMessage(): " + e.getMessage(), e);
}
} else {
sms.setStored(true);
this.scheduler.setDestCluster(sms.getSmsSet());
try {
persistence.c2_scheduleMessage_ReschedDueSlot(sms, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast, true);
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when running c2_scheduleMessage_ReschedDueSlot() in sendNewGeneratedMessage()" + e.getMessage(), e);
}
}
}
}
} finally {
SmsSetCache.getInstance().removeSmsSet(lock);
}
}
use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class DeliveryCommonSbb method postProcessPermFailures.
/**
* Processing messages that were failed permanently (sms.inSystem=sent in live database, adding of archive record).
*
* @param lstPermFailured
* @param dlvMessageId
* @param dlvDestId
*/
protected void postProcessPermFailures(ArrayList<Sms> lstPermFailured, String dlvMessageId, String dlvDestId) {
try {
for (Sms sms : lstPermFailured) {
persistence.c2_updateInSystem(sms, DBOperations.IN_SYSTEM_SENT, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast);
sms.setDeliveryDate(new Date());
if (MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateArchiveTable())) {
persistence.c2_createRecordArchive(sms, dlvMessageId, dlvDestId, !smscPropertiesManagement.getReceiptsDisabling(), smscPropertiesManagement.getIncomeReceiptsProcessing());
}
}
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when DeliveryCommonSbb.postProcessPermFailures()" + e.getMessage(), e);
}
}
Aggregations