use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class AlertSbb method setupAlert.
private void setupAlert(ISDNAddressString msisdn, AddressString serviceCentreAddress, int networkId) {
PersistenceRAInterface pers = this.getStore();
SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
// checking if SMSC is paused
if (smscPropertiesManagement.isDeliveryPause())
return;
// checking if database is available
if (!pers.isDatabaseAvailable())
return;
int addrTon = msisdn.getAddressNature().getIndicator();
int addrNpi = msisdn.getNumberingPlan().getIndicator();
String addr = msisdn.getAddress();
TargetAddress lock = pers.obtainSynchroObject(new TargetAddress(addrTon, addrNpi, addr, networkId));
try {
synchronized (lock) {
try {
long dueSlot = 0;
SmsSet smsSet0 = new SmsSet();
smsSet0.setDestAddr(addr);
smsSet0.setDestAddrNpi(addrNpi);
smsSet0.setDestAddrTon(addrTon);
smsSet0.setNetworkId(networkId);
SmsSet smsSet1 = SmsSetCache.getInstance().getProcessingSmsSet(smsSet0.getTargetId());
if (smsSet1 != null) {
// message is already in process
if (logger.isInfoEnabled()) {
logger.info(String.format("Received AlertServiceCentre for MSISDN=%s but the delivering for this dest is already in progress", addr));
}
return;
}
dueSlot = pers.c2_getDueSlotForTargetId(smsSet0.getTargetId());
if (dueSlot != 0 && dueSlot > pers.c2_getCurrentDueSlot() && pers.c2_checkDueSlotWritingPossibility(dueSlot) == dueSlot) {
pers.c2_registerDueSlotWriting(dueSlot);
try {
if (dueSlot != 0 && dueSlot > pers.c2_getCurrentDueSlot()) {
SmsSet smsSet = pers.c2_getRecordListForTargeId(dueSlot, smsSet0.getTargetId());
if (smsSet != null) {
if (logger.isInfoEnabled()) {
logger.info(String.format("Received AlertServiceCentre for MSISDN=%s, SmsSet was loaded with %d messages", addr, smsSet.getSmsCount()));
}
for (int i1 = 0; i1 < smsSet.getSmsCount(); i1++) {
Sms sms = smsSet.getSms(i1);
sms.setInvokedByAlert(true);
}
ArrayList<SmsSet> lstS = new ArrayList<SmsSet>();
lstS.add(smsSet);
ArrayList<SmsSet> lst = pers.c2_sortRecordList(lstS);
if (lst.size() > 0) {
smsSet = lst.get(0);
smsSet.setProcessingStarted();
this.scheduler.injectSmsDatabase(smsSet);
}
} else {
if (logger.isInfoEnabled()) {
logger.info(String.format("Received AlertServiceCentre for MSISDN=%s, dueSlot was scheduled but no SmsSet was loaded", addr));
}
}
} else {
if (logger.isInfoEnabled()) {
logger.info(String.format("Received AlertServiceCentre for MSISDN=%s but no dueSlot was scheduled or the scheduled dueSlot will come soon - 2", addr));
}
}
} finally {
pers.c2_unregisterDueSlotWriting(dueSlot);
}
} else {
if (logger.isInfoEnabled()) {
logger.info(String.format("Received AlertServiceCentre for MSISDN=%s but no dueSlot was scheduled or the scheduled dueSlot will come soon - 1", addr));
}
}
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when setupAlert()" + e.getMessage(), e);
} catch (Exception e) {
this.logger.severe("Exception when setupAlert()" + e.getMessage(), e);
}
}
} finally {
pers.releaseSynchroObject(lock);
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class CassandraTest method testOldFormatMessage.
@Test(groups = { "cassandra" })
public void testOldFormatMessage(TargetAddress ta, DataCodingScheme dcs, String msg, UserDataHeader udh, int size) throws Exception {
Date dt = new Date();
PreparedStatementCollection psc = sbb.getStatementCollection(dt);
TargetAddress lock = this.sbb.obtainSynchroObject(ta);
long dueSlot;
Sms sms;
try {
synchronized (lock) {
SmsSet smsSet = new SmsSet();
smsSet.setDestAddr(ta.getAddr());
smsSet.setDestAddrNpi(ta.getAddrNpi());
smsSet.setDestAddrTon(ta.getAddrTon());
smsSet.setCorrelationId("CI=0000");
smsSet.setNetworkId(9);
sms = new Sms();
sms.setSmsSet(smsSet);
sms.setDbId(UUID.randomUUID());
sms.setSourceAddr("11112");
sms.setSourceAddrTon(1);
sms.setSourceAddrNpi(1);
sms.setMessageId(8888888);
sms.setOrigNetworkId(49);
sms.setDataCoding(dcs.getCode());
sms.setShortMessageText(msg);
if (udh != null) {
sms.setEsmClass(SmppConstants.ESM_CLASS_UDHI_MASK);
sms.setShortMessageBin(udh.getEncodedData());
}
dueSlot = this.sbb.c2_getDueSlotForTargetId(psc, ta.getTargetId());
if (dueSlot == 0 || dueSlot <= sbb.c2_getCurrentDueSlot()) {
dueSlot = sbb.c2_getDueSlotForNewSms();
sbb.c2_updateDueSlotForTargetId(ta.getTargetId(), dueSlot);
}
sms.setDueSlot(dueSlot);
sbb.c2_registerDueSlotWriting(dueSlot);
try {
sbb.c2_createRecordCurrent(sms);
} finally {
sbb.c2_unregisterDueSlotWriting(dueSlot);
}
}
} finally {
this.sbb.obtainSynchroObject(lock);
}
lock = this.sbb.obtainSynchroObject(ta);
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(), size);
SmsSet smsSet;
if (size == 0) {
// messages are not in res because smsSet is already in processing
smsSet = SmsSetCache.getInstance().getProcessingSmsSet(ta.getTargetId());
} else {
smsSet = lst.get(0);
}
assertEquals(smsSet.getNetworkId(), 9);
assertEquals(sms.getOrigNetworkId(), 49);
for (Sms sms1 : smsSet.getRawListLastSegment()) {
if (sms1.getDbId().equals(sms.getDbId())) {
assertEquals(sms1.getDataCoding(), dcs.getCode());
if (msg != null)
assertEquals(sms1.getShortMessageText(), msg);
else
assertNull(sms1.getShortMessageText());
if (udh != null)
assertEquals(sms1.getShortMessageBin(), udh.getEncodedData());
else
assertNull(sms1.getShortMessageBin());
assertEquals(smsSet.getCorrelationId(), "CI=0000");
}
}
}
} finally {
this.sbb.obtainSynchroObject(lock);
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class CassandraTest method addingNewMessages2.
public void addingNewMessages2(long dueSlot) throws Exception {
Date dt = new Date();
PreparedStatementCollection psc = sbb.getStatementCollection(dt);
// adding an extra messages for "1111"
TargetAddress lock = this.sbb.obtainSynchroObject(ta1);
try {
synchronized (lock) {
Sms sms_a5 = this.createTestSms(5, ta1.getAddr(), id5);
sms_a5.setDueSlot(dueSlot);
sbb.c2_registerDueSlotWriting(dueSlot);
try {
sbb.c2_createRecordCurrent(sms_a5);
} finally {
sbb.c2_unregisterDueSlotWriting(dueSlot);
}
}
} finally {
this.sbb.obtainSynchroObject(lock);
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class MtSbb method setupMtForwardShortMessageRequest.
// *********
// Main service methods
public void setupMtForwardShortMessageRequest(ISDNAddressString networkNode, String imsiData, LMSI lmsi, int networkId) {
if (this.logger.isFineEnabled()) {
this.logger.fine("mperforming setupMtForwardShortMessageRequest ISDNAddressString= " + networkNode);
}
SmsSet smsSet = getSmsSet();
if (smsSet == null) {
markDeliveringIsEnded(true);
logger.severe("MtSbb.setupMtForwardShortMessageRequest(): CMP smsSet is missed");
return;
}
Sms sms0 = smsSet.getSms(0);
Integer mtRemoteSccpTt = sms0.getMtRemoteSccpTt();
SccpAddress networkNodeSccpAddress = this.getMSCSccpAddress(networkNode, mtRemoteSccpTt);
IMSI imsi = this.mapParameterFactory.createIMSI(imsiData);
SM_RP_DA sm_RP_DA = this.mapParameterFactory.createSM_RP_DA(imsi);
AddressString scAddress = this.getServiceCenterAddressString(networkId);
SM_RP_OA sm_RP_OA = this.mapParameterFactory.createSM_RP_OA_ServiceCentreAddressOA(scAddress);
if (sms0 != null) {
// we only set it for first sms in the list
sms0.setMtServiceCenterAddress(scAddress.getAddress());
}
this.setNnn(networkNode);
this.setNetworkNode(networkNodeSccpAddress);
this.setSmRpDa(sm_RP_DA);
this.setSmRpOa(sm_RP_OA);
// Set cache with MAP version
MAPApplicationContextVersion mapApplicationContextVersion = mapVersionCache.getMAPApplicationContextVersion(networkNode.getAddress());
if (mapApplicationContextVersion == null) {
mapApplicationContextVersion = MAPApplicationContextVersion.getInstance(smscPropertiesManagement.getMaxMapVersion());
} else {
this.setNegotiatedMapVersionUsing(true);
}
this.setMAPVersionTested(mapApplicationContextVersion);
// dropaftersri mproc rules
try {
if (this.getTotalUnsentMessageCount() > 0) {
ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
try {
synchronized (lock) {
this.applyMprocRulesOnImsiResponse(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNode, imsiData);
this.onImsiDrop(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNode, imsiData);
}
} finally {
persistence.releaseSynchroObject(lock);
}
}
} catch (Throwable e) {
}
if (this.getTotalUnsentMessageCount() == 0) {
setupReportSMDeliveryStatusRequestSuccess(smsSet, true);
smsSet.setStatus(ErrorCode.SUCCESS);
this.markDeliveringIsEnded(true);
} else {
try {
this.sendMtSms(this.getMtFoSMSMAPApplicationContext(mapApplicationContextVersion), MessageProcessingState.firstMessageSending, null, smsSet.getNetworkId());
} catch (SmscProcessingException e) {
String reason = "SmscPocessingException when invoking sendMtSms() from setupMtForwardShortMessageRequest()-firstMessageSending: " + e.toString();
this.logger.severe(reason, e);
ErrorCode smStatus = ErrorCode.SC_SYSTEM_ERROR;
try {
smStatus = ErrorCode.fromInt(e.getSmppErrorCode());
} catch (IllegalArgumentException e1) {
}
this.onDeliveryError(smsSet, ErrorAction.permanentFailure, smStatus, reason, true, null, false, ProcessingType.SS7_MT);
} catch (Throwable e) {
String reason = "Exception when invoking sendMtSms() from setupMtForwardShortMessageRequest()-firstMessageSending: " + e.toString();
this.logger.severe(reason, e);
ErrorCode smStatus = ErrorCode.SC_SYSTEM_ERROR;
this.onDeliveryError(smsSet, ErrorAction.permanentFailure, smStatus, reason, true, null, false, ProcessingType.SS7_MT);
}
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class MtSbb method handleSmsResponse.
private void handleSmsResponse(MAPDialogSms mapDialogSms, boolean continueDialog) {
SmsSet smsSet = getSmsSet();
if (smsSet == null) {
logger.severe("MtSbb.handleSmsResponse(): CMP smsSet is missed");
markDeliveringIsEnded(true);
return;
}
smscStatAggregator.updateMsgOutSentAll();
smscStatAggregator.updateMsgOutSentSs7();
Sms sms = this.getMessageInSendingPool(0);
// checking if there are yet message segments
int messageSegmentNumber = this.getMessageSegmentNumber();
SmsSignalInfo[] segments = this.getSegments();
if (segments != null && messageSegmentNumber < segments.length - 1) {
this.generateCDR(sms, CdrGenerator.CDR_PARTIAL, CdrGenerator.CDR_SUCCESS_NO_REASON, true, false, messageSegmentNumber);
// we have more message parts to be sent yet
messageSegmentNumber++;
this.setMessageSegmentNumber(messageSegmentNumber);
try {
smscStatAggregator.updateMsgOutTryAll();
smscStatAggregator.updateMsgOutTrySs7();
this.sendMtSms(mapDialogSms.getApplicationContext(), MessageProcessingState.nextSegmentSending, continueDialog ? mapDialogSms : null, smsSet.getNetworkId());
return;
} catch (SmscProcessingException e) {
this.logger.severe("SmscPocessingException when invoking sendMtSms() from handleSmsResponse()-nextSegmentSending: " + e.toString(), e);
this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SYSTEM_FAILURE, "Error sendMtSms in handleSmsResponse(): ", true, null, false, ProcessingType.SS7_MT);
return;
}
}
// current message is sent
// firstly sending of a positive response for transactional mode
this.sendTransactionalResponseSuccess(sms);
// mproc rules applying for delivery phase
this.applyMprocRulesOnSuccess(sms, ProcessingType.SS7_MT);
// Processing succeeded
sms.getSmsSet().setStatus(ErrorCode.SUCCESS);
this.postProcessSucceeded(sms, null, null);
// success CDR generating
boolean isPartial = MessageUtil.isSmsNotLastSegment(sms);
this.generateCDR(sms, isPartial ? CdrGenerator.CDR_PARTIAL : CdrGenerator.CDR_SUCCESS, CdrGenerator.CDR_SUCCESS_NO_REASON, segments != null, true, messageSegmentNumber);
// adding a success receipt if it is needed
this.generateSuccessReceipt(smsSet, sms);
TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
try {
synchronized (lock) {
// marking the message in cache as delivered
this.commitSendingPoolMsgCount();
// now we are trying to sent other messages
sms = obtainNextMessage(ProcessingType.SS7_MT);
if (sms != null) {
// dropaftersri pmproc rules
ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
ArrayList<Sms> lstRerouted = new ArrayList<Sms>();
ArrayList<Integer> lstNewNetworkId = new ArrayList<Integer>();
SM_RP_DA da = this.getSmRpDa();
ISDNAddressString networkNodeNumber = this.getNnn();
this.applyMprocRulesOnImsiResponse(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNodeNumber, da.getIMSI().getData());
this.onImsiDrop(smsSet, lstPermFailured, lstRerouted, lstNewNetworkId, networkNodeNumber, da.getIMSI().getData());
}
sms = this.getMessageInSendingPool(0);
if (sms != null) {
try {
// sms.setDeliveryCount(sms.getDeliveryCount() + 1);
smscStatAggregator.updateMsgOutTryAll();
smscStatAggregator.updateMsgOutTrySs7();
this.sendMtSms(mapDialogSms.getApplicationContext(), MessageProcessingState.firstMessageSending, continueDialog ? mapDialogSms : null, smsSet.getNetworkId());
return;
} catch (SmscProcessingException e) {
this.logger.severe("SmscPocessingException when invoking sendMtSms() from handleSmsResponse(): " + e.toString(), e);
}
}
// more messages in a database
if (continueDialog) {
try {
mapDialogSms.close(false);
} catch (MAPException e) {
this.logger.severe("MAPException when closing MAP dialog from handleSmsResponse(): " + e.toString(), e);
}
}
// no more messages to send - remove smsSet
setupReportSMDeliveryStatusRequestSuccess(smsSet, mapDialogSms.getApplicationContext().getApplicationContextVersion() != MAPApplicationContextVersion.version1);
smsSet.setStatus(ErrorCode.SUCCESS);
this.markDeliveringIsEnded(true);
// this.freeSmsSetSucceded(smsSet, pers);
}
} finally {
persistence.releaseSynchroObject(lock);
}
}
Aggregations