use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcRuleDefaultTest method testTlvOptions.
@Test(groups = { "MProcRule" })
public void testTlvOptions() throws Exception {
Sms sms = new Sms();
MProcRuleDefaultImpl pmr = null;
MProcMessage message = null;
TlvSet tlvSet = null;
// FIXME:add more failing tests
// test tlvbyte_*
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 7 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
pmr = new MProcRuleDefaultImpl();
pmr.setInitialRuleParameters("tlv_byte_1550 7");
assertEquals(pmr.getRuleParameters(), "tlvByte_1550=7", "error");
assertTrue(pmr.matchesPostArrival(message));
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 13 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
assertFalse(pmr.matchesPostArrival(message));
pmr.setInitialRuleParameters("tlv_byte_1550 13");
assertEquals(pmr.getRuleParameters(), "tlvByte_1550=13", "error");
assertTrue(pmr.matchesPostArrival(message));
// test tlvint_*
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 0, 0, 0, 7 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
pmr = new MProcRuleDefaultImpl();
pmr.setInitialRuleParameters("tlv_int_1550 7");
assertEquals(pmr.getRuleParameters(), "tlvInt_1550=7", "error");
assertTrue(pmr.matchesPostArrival(message));
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, new byte[] { 0, 0, 0, 13 }));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
assertFalse(pmr.matchesPostArrival(message));
pmr.setInitialRuleParameters("tlv_int_1550 13");
assertEquals(pmr.getRuleParameters(), "tlvInt_1550=13", "error");
assertTrue(pmr.matchesPostArrival(message));
// test tlvstring_*
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, "7".getBytes()));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
pmr = new MProcRuleDefaultImpl();
pmr.setInitialRuleParameters("tlv_string_1550 7");
assertEquals(pmr.getRuleParameters(), "tlvString_1550=7", "error");
assertTrue(pmr.matchesPostArrival(message));
tlvSet = new TlvSet();
tlvSet.addOptionalParameter(new Tlv(SmppConstants.TAG_DEST_NETWORK_ID, "13".getBytes()));
sms.setTlvSet(tlvSet);
message = new MProcMessageImpl(sms, ProcessingType.SMPP, null);
assertFalse(pmr.matchesPostArrival(message));
pmr.setInitialRuleParameters("tlv_string_1550 13");
assertEquals(pmr.getRuleParameters(), "tlvString_1550=13", "error");
assertTrue(pmr.matchesPostArrival(message));
}
use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcManagement method applyMProcImsiRequest.
public MProcResult applyMProcImsiRequest(final MProcRuleRaProvider anMProcRuleRa, Sms sms, String imsi, String nnnDigits, int nnnNumberingPlan, int nnnAddressNature) {
if (this.mprocs.size() == 0)
return new MProcResult();
FastList<MProcRule> cur = this.mprocs;
PostImsiProcessorImpl pap = new PostImsiProcessorImpl(logger);
MProcMessage message = new MProcMessageImpl(sms, ProcessingType.SS7_SRI, null);
try {
for (FastList.Node<MProcRule> n = cur.head(), end = cur.tail(); (n = n.getNext()) != end; ) {
MProcRule rule = n.getValue();
if (rule.isForPostImsiRequestState() && rule.matchesPostImsiRequest(message)) {
if (logger.isDebugEnabled()) {
logger.debug("MRule matches at ImsiRequest phase to a message:\nrule: " + rule + "\nmessage: " + sms);
}
rule.onPostImsiRequest(anMProcRuleRa, pap, message);
}
}
} catch (Throwable e) {
logger.error("Exception when invoking rule.matches(message) or applyMProcImsiRequest(): " + e.getMessage(), e);
return new MProcResult();
}
if (pap.isNeedDropMessages()) {
MProcResult res = new MProcResult();
res.setMessageDropped(true);
return res;
}
if (pap.isNeedRerouteMessages()) {
MProcResult res = new MProcResult();
res.setMessageIsRerouted(true);
res.setNewNetworkId(pap.getNewNetworkId());
return res;
}
return new MProcResult();
}
use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcManagement method applyMProcHrSri.
public MProcResult applyMProcHrSri(final MProcRuleRaProvider anMProcRuleRa, CorrelationIdValue correlationIdValue) {
if (this.mprocs.size() == 0) {
return new MProcResult();
}
FastList<MProcRule> cur = this.mprocs;
PostHrSriProcessorImpl pap = new PostHrSriProcessorImpl(logger);
MProcMessage message = new MProcMessageHrImpl(correlationIdValue);
try {
for (FastList.Node<MProcRule> n = cur.head(), end = cur.tail(); (n = n.getNext()) != end; ) {
MProcRule rule = n.getValue();
if (rule.isForPostHrSriState() && rule.matchesPostHrSri(message)) {
if (logger.isDebugEnabled()) {
logger.debug("MRule matches at HrSri phase to a message:\nrule: " + rule + "\ncorrelationIdValue: " + correlationIdValue);
}
rule.onPostHrSri(anMProcRuleRa, pap, message);
}
}
} catch (Throwable e) {
logger.error("Exception when invoking rule.matches(message) or onPostHrSri(): " + e.getMessage(), e);
return new MProcResult();
}
MProcResult res = new MProcResult();
if (pap.isHrByPassed()) {
res.setHrIsByPassed(true);
}
return res;
}
use of org.mobicents.smsc.mproc.MProcMessage in project smscgateway by RestComm.
the class MProcManagement method applyMProcDelivery.
public MProcResult applyMProcDelivery(final MProcRuleRaProvider anMProcRuleRa, Sms sms, boolean deliveryFailure, ProcessingType processingType) {
if (this.mprocs.size() == 0) {
return new MProcResult();
}
FastList<MProcRule> cur = this.mprocs;
PostDeliveryProcessorImpl pap = new PostDeliveryProcessorImpl(this.smscPropertiesManagement.getDefaultValidityPeriodHours(), this.smscPropertiesManagement.getMaxValidityPeriodHours(), logger, deliveryFailure);
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.isForPostDeliveryState() && rule.matchesPostDelivery(message)) {
if (logger.isDebugEnabled()) {
logger.debug("MRule matches at Delivery phase to a message:\nrule: " + rule + "\nmessage: " + sms);
}
rule.onPostDelivery(anMProcRuleRa, pap, message);
}
}
} catch (Throwable e) {
logger.error("Exception when invoking rule.matches(message) or onPostDelivery(): " + 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.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 applyMProcDeliveryTempFailure.
public MProcResult applyMProcDeliveryTempFailure(final MProcRuleRaProvider anMProcRuleRa, Sms sms, ProcessingType processingType) {
if (this.mprocs.size() == 0) {
return new MProcResult();
}
FastList<MProcRule> cur = this.mprocs;
PostDeliveryTempFailureProcessorImpl pap = new PostDeliveryTempFailureProcessorImpl(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.isForPostDeliveryTempFailureState() && rule.matchesPostDeliveryTempFailure(message)) {
if (logger.isDebugEnabled()) {
logger.debug("MRule matches at DeliveryTempFailure phase to a message:\nrule: " + rule + "\nmessage: " + sms);
}
rule.onPostDeliveryTempFailure(anMProcRuleRa, pap, message);
}
}
} catch (Throwable e) {
logger.error("Exception when invoking rule.matches(message) or onPostDeliveryTempFailure(): " + 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;
}
Aggregations