use of org.mobicents.smsc.library.Sms 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);
}
}
use of org.mobicents.smsc.library.Sms 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);
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class DeliveryCommonSbb method obtainNextMessage.
/**
* Arrange a new message sending pool with only one message in it. If no pending message then no 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 more than one message in message sending pool you can use
* obtainNextMessagesSendingPool() method. Messages with expired ValidityPeriod are not added to a sendingPoolMsg but are
* processed as perm failed.
*
* @param processingType
* @return a message for sending or null if no more message to send
*/
protected Sms obtainNextMessage(ProcessingType processingType) {
commitSendingPoolMsgCount();
if (smsSet != null) {
Sms sms = null;
// ***** lock ******
TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
try {
synchronized (lock) {
int addedMessageCnt = 0;
int gotMessageCnt = 0;
int sendingPoolMsgCount = this.getTotalUnsentMessageCount();
for (int i1 = 0; i1 < sendingPoolMsgCount; i1++) {
if (addedMessageCnt >= 1) {
break;
}
gotMessageCnt++;
sms = smsSet.getSms(currentMsgNum + i1);
if (sms == null) {
this.logger.severe("RxSmpp obtainNextMessage() error: sms is not found num=" + i1 + " from " + sendingPoolMsgCount + ", smsSet=" + smsSet);
break;
}
if (sms.getValidityPeriod() != null && sms.getValidityPeriod().getTime() <= System.currentTimeMillis()) {
this.endDeliveryAfterValidityPeriod(sms, processingType, null, null);
sms = null;
} else {
boolean res1 = applyMProcPreDelivery(sms, processingType);
if (!res1) {
sms = null;
} else {
addedMessageCnt++;
sms.setDeliveryCount(sms.getDeliveryCount() + 1);
smsSet.markSmsAsDelivered(currentMsgNum + i1);
smsSet.addMessageToSendingPool(sms);
}
}
}
if (gotMessageCnt > 0) {
currentMsgNum += gotMessageCnt;
this.setCurrentMsgNum(currentMsgNum);
}
sequenceNumbers = null;
sequenceNumbersExtra = null;
this.rescheduleDeliveryTimer(sendingPoolMsgCount);
}
} finally {
persistence.releaseSynchroObject(lock);
}
return sms;
} else
return null;
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class MtCommonSbb method onDeliveryError.
/**
* Processing a case when an error in message sending process. This stops of message sending, reschedule or drop messages
* and clear resources.
*
* @param smsSet
* @param errorAction
* @param smStatus
* @param reason
* @param removeSmsSet
* @param errMessage
* @param isImsiVlrReject
* @param processingType
*/
protected void onDeliveryError(SmsSet smsSet, ErrorAction errorAction, ErrorCode smStatus, String reason, boolean removeSmsSet, MAPErrorMessage errMessage, boolean isImsiVlrReject, ProcessingType processingType) {
try {
smscStatAggregator.updateMsgOutFailedAll();
// generating of a temporary failure CDR
if (smscPropertiesManagement.getGenerateTempFailureCdr())
this.generateTemporaryFailureCDR(CdrGenerator.CDR_TEMP_FAILED, reason);
StringBuilder sb = new StringBuilder();
sb.append("onDeliveryError: errorAction=");
sb.append(errorAction);
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());
ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
ArrayList<Sms> lstTempFailured = new ArrayList<Sms>();
ArrayList<Sms> lstPermFailured2 = new ArrayList<Sms>();
ArrayList<Sms> lstTempFailured2 = new ArrayList<Sms>();
ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
// generate text for Delivery receipts
// false
String dlrText = null;
if (errMessage != null) {
MAPErrorMessageSMDeliveryFailure smDeliveryFailure = errMessage.getEmSMDeliveryFailure();
if (smDeliveryFailure != null) {
SmsDeliverReportTpdu tpdu = null;
try {
tpdu = errMessage.getEmSMDeliveryFailure().getSmsDeliverReportTpdu();
} catch (MAPException e) {
// we ignore Exception here
}
if (tpdu != null) {
UserData userData = tpdu.getUserData();
if (userData != null) {
byte[] data = userData.getEncodedData();
if (data != null) {
String text = DatatypeConverter.printHexBinary(data);
String smDlrWithTpdu = SmscPropertiesManagement.getInstance().getSmDeliveryFailureDlrWithTpdu();
if (smDlrWithTpdu.equals("short")) {
if (text.length() > 20)
dlrText = text.substring(0, 20);
else
dlrText = text;
} else if (smDlrWithTpdu.equals("full")) {
dlrText = text;
}
}
}
}
}
}
TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
synchronized (lock) {
try {
Date curDate = new Date();
smsSet.setStatus(smStatus);
// calculating of newDueDelay and NewDueTime
int newDueDelay = calculateNewDueDelay(smsSet, (errorAction == ErrorAction.subscriberBusy));
Date newDueTime = calculateNewDueTime(smsSet, newDueDelay);
// creating of failure lists
this.createFailureLists(lstPermFailured, lstTempFailured, errorAction, newDueTime);
// mproc rules applying for delivery phase
this.applyMprocRulesOnFailure(lstPermFailured, lstTempFailured, lstPermFailured2, lstTempFailured2, lstRerouted, lstNewNetworkId, processingType);
// sending of a failure response for transactional mode
this.sendTransactionalResponseFailure(lstPermFailured2, lstTempFailured2, errorAction, errMessage);
// Processing messages that were temp or permanent failed or rerouted
this.postProcessPermFailures(lstPermFailured2, null, null);
this.postProcessTempFailures(smsSet, lstTempFailured2, newDueDelay, newDueTime, true);
this.postProcessRerouted(lstRerouted, lstNewNetworkId);
// generating CDRs for permanent failure messages
this.generateCDRs(lstPermFailured2, (isImsiVlrReject ? CdrGenerator.CDR_FAILED_IMSI : CdrGenerator.CDR_FAILED), reason);
// sending of intermediate delivery receipts
this.generateIntermediateReceipts(smsSet, lstTempFailured2);
// sending of failure delivery receipts
this.generateFailureReceipts(smsSet, lstPermFailured2, dlrText);
// sending of ReportSMDeliveryStatusRequest if needed
SMDeliveryOutcome smDeliveryOutcome = null;
switch(errorAction) {
case memoryCapacityExceededFlag:
smDeliveryOutcome = SMDeliveryOutcome.memoryCapacityExceeded;
break;
case mobileNotReachableFlag:
smDeliveryOutcome = SMDeliveryOutcome.absentSubscriber;
break;
case notReachableForGprs:
smDeliveryOutcome = SMDeliveryOutcome.absentSubscriber;
break;
}
if (smDeliveryOutcome != null && lstTempFailured2.size() > 0) {
Sms sms0 = smsSet.getSms(0);
String mtLocalSccpGt = null;
Integer mtRemoteSccpTt = null;
if (sms0 != null) {
mtLocalSccpGt = sms0.getMtLocalSccpGt();
mtRemoteSccpTt = sms0.getMtRemoteSccpTt();
}
this.setupReportSMDeliveryStatusRequest(smsSet.getDestAddr(), smsSet.getDestAddrTon(), smsSet.getDestAddrNpi(), smDeliveryOutcome, smsSet.getTargetId(), smsSet.getNetworkId(), mtLocalSccpGt, mtRemoteSccpTt);
}
this.markDeliveringIsEnded(removeSmsSet);
} finally {
persistence.releaseSynchroObject(lock);
}
}
} catch (Throwable e) {
logger.severe("Exception in MtCommonSbb.onDeliveryError(): " + e.getMessage(), e);
markDeliveringIsEnded(true);
}
}
use of org.mobicents.smsc.library.Sms in project smscgateway by RestComm.
the class MtTest method MapVersionNegotiationTest.
/**
* MAP V3 -> MAP V3 -> MAP V1 (Reject - Alternative ANC)
*/
@Test(groups = { "Mt" })
public void MapVersionNegotiationTest() throws Exception {
if (!this.cassandraDbInited)
return;
MAPServiceSmsProxy serviceSri = (MAPServiceSmsProxy) this.sriSbb.mapProvider.getMAPServiceSms();
MAPServiceSmsProxy serviceMt = (MAPServiceSmsProxy) this.mtSbb.mapProvider.getMAPServiceSms();
MAPServiceSmsProxy serviceRsds = (MAPServiceSmsProxy) this.rsdsSbb.mapProvider.getMAPServiceSms();
SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
MProcManagement.getInstance("Test");
ArrayList<SmsDef> lst = new ArrayList<SmsDef>();
SmsDef sd1 = new SmsDef();
lst.add(sd1);
SmsSet smsSet = prepareDatabase(lst);
Sms sms1 = smsSet.getSms(0);
UUID smsId = sms1.getDbId();
SmsProxy smsx1 = this.pers.obtainArchiveSms(procDueSlot, smsSet.getDestAddr(), smsId);
assertNull(smsx1);
SmsSet smsSetX = SmsSetCache.getInstance().getProcessingSmsSet(procTargetId);
assertNotNull(smsSetX);
Sms smsX = this.pers.obtainLiveSms(procDueSlot, procTargetId, procId[0]);
assertEquals(smsX.getSmsSet().getInSystem(), 0);
assertEquals(SmsSetCache.getInstance().getProcessingSmsSetSize(), 1);
// initial onSms message
SmsSetEvent event = new SmsSetEvent();
event.setSmsSet(smsSet);
this.sriSbb.onSms(event, null, null);
MAPDialogSmsProxy dlg = serviceSri.getLastMAPDialogSms();
assertFalse(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version1));
assertFalse(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version2));
assertFalse(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version3));
assertFalse(this.mtSbb.isNegotiatedMapVersionUsing());
// SRI response
IMSI imsi = new IMSIImpl(imsiDig);
ISDNAddressString networkNodeNumber = new ISDNAddressStringImpl(AddressNature.international_number, org.restcomm.protocols.ss7.map.api.primitives.NumberingPlan.ISDN, nnnDig);
LocationInfoWithLMSI locationInfoWithLMSI = new LocationInfoWithLMSIImpl(networkNodeNumber, null, null, false, null);
SendRoutingInfoForSMResponse evt1 = new SendRoutingInfoForSMResponseImpl(imsi, locationInfoWithLMSI, null, null, null);
evt1.setMAPDialog(dlg);
this.sriSbb.onSendRoutingInfoForSMResponse(evt1, null);
this.sriSbb.onDialogDelimiter(null, null);
assertFalse(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version1));
assertFalse(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version2));
assertTrue(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version3));
assertFalse(this.mtSbb.isNegotiatedMapVersionUsing());
dlg = serviceMt.getLastMAPDialogSms();
MAPApplicationContextVersion vers = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(vers, MAPApplicationContextVersion.version3);
ApplicationContextNameImpl acn = new ApplicationContextNameImpl();
acn.setOid(new long[] { 0, 4, 0, 0, 1, 0, 25, 2 });
DialogReject evt5 = new DialogReject(dlg, MAPRefuseReason.ApplicationContextNotSupported, acn, null);
this.mtSbb.onDialogReject(evt5, null);
assertFalse(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version1));
assertTrue(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version2));
assertTrue(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version3));
assertFalse(this.mtSbb.isNegotiatedMapVersionUsing());
dlg = serviceMt.getLastMAPDialogSms();
vers = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(vers, MAPApplicationContextVersion.version2);
acn = new ApplicationContextNameImpl();
acn.setOid(new long[] { 0, 4, 0, 0, 1, 0, 25, 2 });
evt5 = new DialogReject(dlg, MAPRefuseReason.ApplicationContextNotSupported, acn, null);
this.mtSbb.onDialogReject(evt5, null);
assertTrue(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version1));
assertTrue(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version2));
assertTrue(this.mtSbb.isMAPVersionTested(MAPApplicationContextVersion.version3));
assertFalse(this.mtSbb.isNegotiatedMapVersionUsing());
dlg = serviceMt.getLastMAPDialogSms();
vers = dlg.getApplicationContext().getApplicationContextVersion();
assertEquals(vers, MAPApplicationContextVersion.version1);
}
Aggregations