use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcManagement method applyMProcPreDelivery.
public MProcResult applyMProcPreDelivery(final MProcRuleRaProvider anMProcRuleRa, Sms sms, ProcessingType processingType) {
if (this.mprocs.size() == 0) {
return new MProcResult();
}
FastList<MProcRule> cur = this.mprocs;
PostPreDeliveryProcessorImpl pap = new PostPreDeliveryProcessorImpl(this.smscPropertiesManagement.getDefaultValidityPeriodHours(), this.smscPropertiesManagement.getMaxValidityPeriodHours(), logger);
MProcMessage message = new MProcMessageImpl(sms, processingType, null);
try {
for (FastList.Node<MProcRule> n = cur.head(), end = cur.tail(); (n = n.getNext()) != end; ) {
MProcRule rule = n.getValue();
if (rule.isForPostPreDeliveryState() && rule.matchesPostPreDelivery(message)) {
if (logger.isDebugEnabled()) {
logger.debug("MRule matches at PreDelivery phase to a message: rule: " + rule + "message: " + sms);
}
rule.onPostPreDelivery(anMProcRuleRa, pap, message);
}
}
} catch (Throwable e) {
logger.error("Exception when invoking rule.matches(message) or onPostPreDelivery(): " + e.getMessage(), e);
return new MProcResult();
}
FastList<MProcNewMessage> newMsgs = pap.getPostedMessages();
MProcResult res = new MProcResult();
FastList<Sms> res0 = new FastList<Sms>();
for (FastList.Node<MProcNewMessage> n = newMsgs.head(), end = newMsgs.tail(); (n = n.getNext()) != end; ) {
MProcNewMessageImpl newMsg = (MProcNewMessageImpl) n.getValue();
res0.add(newMsg.getSmsContent());
}
res.setMessageList(res0);
if (pap.isNeedDropMessages()) {
res.setMessageDropped(true);
}
if (pap.isNeedRerouteMessages()) {
res.setMessageIsRerouted(true);
res.setNewNetworkId(pap.getNewNetworkId());
}
return res;
}
use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcManagement method applyMProcArrival.
public MProcResult applyMProcArrival(final MProcRuleRaProvider anMProcRuleRa, Sms sms, PersistenseCommonInterface persistence) {
if (this.mprocs.size() == 0) {
FastList<Sms> res0 = new FastList<Sms>();
res0.add(sms);
MProcResult res = new MProcResult();
res.setMessageList(res0);
return res;
}
FastList<MProcRule> cur = this.mprocs;
PostArrivalProcessorImpl pap = new PostArrivalProcessorImpl(this.smscPropertiesManagement.getDefaultValidityPeriodHours(), this.smscPropertiesManagement.getMaxValidityPeriodHours(), logger);
MProcMessage message = new MProcMessageImpl(sms, null, persistence);
try {
for (FastList.Node<MProcRule> n = cur.head(), end = cur.tail(); (n = n.getNext()) != end; ) {
MProcRule rule = n.getValue();
if (rule.isForPostArrivalState() && rule.matchesPostArrival(message)) {
if (logger.isDebugEnabled()) {
logger.debug("MRule matches at Arrival phase to a message: rule: " + rule + "message: " + sms);
}
pap.setRuleIdInProcessing(rule.getId());
rule.onPostArrival(anMProcRuleRa, pap, message);
}
}
} catch (Throwable e) {
logger.error("Exception when invoking rule.matches(message) or applyMProcArrival: " + e.getMessage(), e);
MProcResult res = new MProcResult();
res.setMessageDropped(true);
return res;
}
MProcResult res = new MProcResult();
FastList<Sms> res0 = new FastList<Sms>();
res.setMessageList(res0);
FastList<MProcNewMessage> newMsgs = pap.getPostedMessages();
if (pap.isNeedDropMessage()) {
res.setMessageDropped(true);
res.setRuleIdDropReject(pap.getRuleIdDropReject());
} else if (pap.isNeedRejectMessage()) {
res.setMessageRejected(true);
// res.setMprocRejectingRuleId(pap.);
res.setMapErrorCode(pap.getMapErrorCode());
res.setHttpErrorCode(pap.getHttpErrorCode());
res.setSmppErrorCode(pap.getSmppErrorCode());
res.setRuleIdDropReject(pap.getRuleIdDropReject());
} else {
res0.add(sms);
}
for (FastList.Node<MProcNewMessage> n = newMsgs.head(), end = newMsgs.tail(); (n = n.getNext()) != end; ) {
MProcNewMessageImpl newMsg = (MProcNewMessageImpl) n.getValue();
res0.add(newMsg.getSmsContent());
}
return res;
}
use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcRuleDefaultTest method testA.
@Test(groups = { "MProcRule" })
public void testA() throws Exception {
Sms sms = new Sms();
SmsSet smsSet = new SmsSet();
sms.setSmsSet(smsSet);
// code 8
smsSet.setStatus(ErrorCode.ABSENT_SUBSCRIBER);
MProcMessage message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
MProcRuleDefaultImpl pmr = new MProcRuleDefaultImpl();
pmr.updateRuleParameters("processingtype SIP");
assertEquals(pmr.getProcessingType(), ProcessingType.SIP);
pmr.updateRuleParameters("processingtype -1");
pmr.updateRuleParameters("errorcode 6");
boolean res = pmr.matchesPostArrival(message);
assertFalse(res);
pmr.updateRuleParameters("errorcode 6,7,8");
res = pmr.matchesPostArrival(message);
assertTrue(res);
}
use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcRuleDefaultImpl method matches.
private boolean matches(MProcMessage message) {
if (destTonMask != -1 && destTonMask != message.getDestAddrTon())
return false;
if (destNpiMask != -1 && destNpiMask != message.getDestAddrNpi())
return false;
if (destDigMaskPattern != null) {
if (message.getDestAddr() == null)
return false;
Matcher m = this.destDigMaskPattern.matcher(message.getDestAddr());
if (!m.matches())
return false;
}
if (sourceTonMask != -1 && sourceTonMask != message.getSourceAddrTon())
return false;
if (sourceNpiMask != -1 && sourceNpiMask != message.getSourceAddrNpi())
return false;
if (sourceDigMaskPattern != null) {
if (message.getSourceAddr() == null)
return false;
Matcher m = this.sourceDigMaskPattern.matcher(message.getSourceAddr());
if (!m.matches())
return false;
}
if (originatingMask != null && originatingMask != message.getOriginationType())
return false;
if (networkIdMask != -1 && networkIdMask != message.getNetworkId())
return false;
if (originNetworkIdMask != -1 && originNetworkIdMask != message.getOrigNetworkId())
return false;
if (receiptNetworkIdMask != -1) {
boolean matched = false;
if (message.isDeliveryReceipt()) {
Long receiptLocalMessageId = message.getReceiptLocalMessageId();
DeliveryReceiptData deliveryReceiptData = message.getDeliveryReceiptData();
if (receiptLocalMessageId != null && deliveryReceiptData != null) {
MProcMessage sentMsg = message.getOriginMessageForDeliveryReceipt(receiptLocalMessageId);
if (sentMsg != null) {
if (receiptNetworkIdMask == sentMsg.getOrigNetworkId())
matched = true;
}
}
}
if (!matched)
return false;
}
if (origEsmeNameMaskPattern != null) {
if (message.getOrigEsmeName() == null)
return false;
Matcher m = this.origEsmeNameMaskPattern.matcher(message.getOrigEsmeName());
if (!m.matches())
return false;
}
if (originatorSccpAddressMaskPattern != null) {
if (message.getOriginatorSccpAddress() == null)
return false;
Matcher m = this.originatorSccpAddressMaskPattern.matcher(message.getOriginatorSccpAddress());
if (!m.matches())
return false;
}
if (imsiDigitsMaskPattern != null) {
if (message.getImsiDigits() == null)
return false;
Matcher m = this.imsiDigitsMaskPattern.matcher(message.getImsiDigits());
if (!m.matches())
return false;
}
if (nnnDigitsMaskPattern != null) {
if (message.getNnnDigits() == null)
return false;
Matcher m = this.nnnDigitsMaskPattern.matcher(message.getNnnDigits());
if (!m.matches())
return false;
}
if (processingType != null && processingType != message.getProcessingType())
return false;
if (errorCodePattern != null) {
if (!this.errorCodePattern.containsKey(message.getErrorCode()))
return false;
}
if (this.originatorSccpAddressMask != null && this.originatorSccpAddressMask.length() > 0 && !this.originatorSccpAddressMask.equals("-1") && message.getOriginatorSccpAddress() != null && message.getOriginatorSccpAddress().length() > 0 && this.originatorSccpAddressMask.charAt(0) != message.getOriginatorSccpAddress().charAt(0))
return false;
// check tlv
if ((this.tlvTagToMatch != -1 && this.tlvValueTypeToMatch != null && tlvValueToMatch != null && !tlvValueToMatch.isEmpty())) {
TlvSet tlvSet = message.getTlvSet();
if (tlvSet.hasOptionalParameter(this.tlvTagToMatch)) {
Tlv tlv = tlvSet.getOptionalParameter(this.tlvTagToMatch);
try {
String val = "";
switch(this.tlvValueTypeToMatch) {
case BYTE:
val = (new Byte(tlv.getValueAsByte())).toString();
break;
case INT:
val = (new Integer(tlv.getValueAsInt())).toString();
break;
case STRING:
default:
val = tlv.getValueAsString();
break;
}
if (!this.tlvValueToMatch.equals(val)) {
return false;
}
} catch (Exception e) {
return false;
}
} else {
return false;
}
}
if (percent != -1) {
return MProcUtility.checkRuleProbability(percent);
}
return true;
}
Aggregations