Search in sources :

Example 6 with MProcMessage

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;
}
Also used : MProcRule(org.mobicents.smsc.mproc.MProcRule) MProcNewMessage(org.mobicents.smsc.mproc.MProcNewMessage) FastList(javolution.util.FastList) MProcNewMessageImpl(org.mobicents.smsc.mproc.impl.MProcNewMessageImpl) PostPreDeliveryProcessorImpl(org.mobicents.smsc.mproc.impl.PostPreDeliveryProcessorImpl) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) MProcMessageImpl(org.mobicents.smsc.mproc.impl.MProcMessageImpl) Sms(org.mobicents.smsc.library.Sms) MProcMessage(org.mobicents.smsc.mproc.MProcMessage)

Example 7 with MProcMessage

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;
}
Also used : MProcRule(org.mobicents.smsc.mproc.MProcRule) MProcNewMessage(org.mobicents.smsc.mproc.MProcNewMessage) FastList(javolution.util.FastList) MProcNewMessageImpl(org.mobicents.smsc.mproc.impl.MProcNewMessageImpl) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) MProcMessageImpl(org.mobicents.smsc.mproc.impl.MProcMessageImpl) PostArrivalProcessorImpl(org.mobicents.smsc.mproc.impl.PostArrivalProcessorImpl) Sms(org.mobicents.smsc.library.Sms) MProcMessage(org.mobicents.smsc.mproc.MProcMessage)

Example 8 with MProcMessage

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);
}
Also used : Sms(org.mobicents.smsc.library.Sms) MProcMessage(org.mobicents.smsc.mproc.MProcMessage) SmsSet(org.mobicents.smsc.library.SmsSet) Test(org.testng.annotations.Test)

Example 9 with MProcMessage

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;
}
Also used : DeliveryReceiptData(org.mobicents.smsc.mproc.DeliveryReceiptData) Matcher(java.util.regex.Matcher) MProcMessage(org.mobicents.smsc.mproc.MProcMessage) TlvSet(org.restcomm.smpp.parameter.TlvSet) XMLStreamException(javolution.xml.stream.XMLStreamException) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

MProcMessage (org.mobicents.smsc.mproc.MProcMessage)9 FastList (javolution.util.FastList)6 Sms (org.mobicents.smsc.library.Sms)6 MProcRule (org.mobicents.smsc.mproc.MProcRule)6 MProcResult (org.mobicents.smsc.mproc.impl.MProcResult)6 MProcMessageImpl (org.mobicents.smsc.mproc.impl.MProcMessageImpl)5 MProcNewMessage (org.mobicents.smsc.mproc.MProcNewMessage)4 MProcNewMessageImpl (org.mobicents.smsc.mproc.impl.MProcNewMessageImpl)4 Tlv (com.cloudhopper.smpp.tlv.Tlv)2 TlvSet (org.restcomm.smpp.parameter.TlvSet)2 Test (org.testng.annotations.Test)2 Matcher (java.util.regex.Matcher)1 XMLStreamException (javolution.xml.stream.XMLStreamException)1 SmsSet (org.mobicents.smsc.library.SmsSet)1 DeliveryReceiptData (org.mobicents.smsc.mproc.DeliveryReceiptData)1 MProcMessageHrImpl (org.mobicents.smsc.mproc.impl.MProcMessageHrImpl)1 PostArrivalProcessorImpl (org.mobicents.smsc.mproc.impl.PostArrivalProcessorImpl)1 PostDeliveryProcessorImpl (org.mobicents.smsc.mproc.impl.PostDeliveryProcessorImpl)1 PostDeliveryTempFailureProcessorImpl (org.mobicents.smsc.mproc.impl.PostDeliveryTempFailureProcessorImpl)1 PostHrSriProcessorImpl (org.mobicents.smsc.mproc.impl.PostHrSriProcessorImpl)1