Search in sources :

Example 1 with TargetAddress

use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testSubmitSm_createSmsEvent.

@Test(groups = { "TxSmppServer" })
public void testSubmitSm_createSmsEvent() throws Exception {
    if (!this.cassandraDbInited)
        return;
    this.smppSess = new SmppSessionsProxy();
    this.sbb.setSmppServerSessions(smppSess);
    TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Utf8);
    SmscPropertiesManagement spm = SmscPropertiesManagement.getInstance("Test");
    String sMsgA = "������Hel";
    // only message part
    Charset utf8 = Charset.forName("UTF-8");
    ByteBuffer bb = utf8.encode(sMsgA);
    byte[] aMsgA = new byte[bb.limit()];
    bb.get(aMsgA);
    Charset ucs2 = Charset.forName("UTF-16BE");
    bb = ucs2.encode(sMsgA);
    byte[] aMsgAA = new byte[bb.limit()];
    bb.get(aMsgAA);
    com.cloudhopper.smpp.pdu.SubmitSm event = new com.cloudhopper.smpp.pdu.SubmitSm();
    Address addr = new Address();
    addr.setNpi((byte) 1);
    addr.setTon((byte) 1);
    addr.setAddress("2222");
    event.setSourceAddress(addr);
    Address addr2 = new Address();
    addr2.setNpi((byte) 1);
    addr2.setTon((byte) 1);
    addr2.setAddress("5555");
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 8);
    event.setShortMessage(aMsgA);
    Esme origEsme = new Esme();
    TargetAddress ta = ta1;
    Sms sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), sMsgA);
    // message part and UDH
    byte[] udh = new byte[] { 0x05, 0x00, 0x03, 0x29, 0x02, 0x02 };
    byte[] aMsgB = new byte[aMsgA.length + udh.length];
    System.arraycopy(udh, 0, aMsgB, 0, udh.length);
    System.arraycopy(aMsgA, 0, aMsgB, udh.length, aMsgA.length);
    event = new com.cloudhopper.smpp.pdu.SubmitSm();
    event.setSourceAddress(addr);
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 8);
    event.setShortMessage(aMsgB);
    event.setEsmClass(SmppConstants.ESM_CLASS_UDHI_MASK);
    sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), sMsgA);
    assertEquals(sms.getShortMessageBin(), udh);
    // binary GSM8
    String s1 = "Optic xxx";
    Charset iso = Charset.forName("ISO-8859-1");
    byte[] aMsgC = s1.getBytes(iso);
    byte[] aMsgCC = new byte[aMsgC.length + udh.length];
    System.arraycopy(udh, 0, aMsgCC, 0, udh.length);
    System.arraycopy(aMsgC, 0, aMsgCC, udh.length, aMsgC.length);
    event = new com.cloudhopper.smpp.pdu.SubmitSm();
    event.setSourceAddress(addr);
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 4);
    event.setShortMessage(aMsgCC);
    event.setEsmClass(SmppConstants.ESM_CLASS_UDHI_MASK);
    sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), s1);
    assertEquals(sms.getShortMessageBin(), udh);
    // GSM7
    event = new com.cloudhopper.smpp.pdu.SubmitSm();
    event.setSourceAddress(addr);
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 0);
    event.setShortMessage(aMsgC);
    sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), s1);
    assertNull(sms.getShortMessageBin());
}
Also used : TargetAddress(org.mobicents.smsc.library.TargetAddress) Address(com.cloudhopper.smpp.type.Address) Esme(org.restcomm.smpp.Esme) Charset(java.nio.charset.Charset) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) ByteBuffer(java.nio.ByteBuffer) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) Sms(org.mobicents.smsc.library.Sms) Test(org.testng.annotations.Test)

Example 2 with TargetAddress

use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.

the class DBOperations method c2_sortRecordList.

public ArrayList<SmsSet> c2_sortRecordList(ArrayList<SmsSet> sourceLst) {
    FastMap<String, SmsSet> res = new FastMap<String, SmsSet>();
    // aggregating messages for one targetId
    for (SmsSet smsSet : sourceLst) {
        SmsSet smsSet2 = null;
        try {
            smsSet2 = res.get(smsSet.getTargetId());
        } catch (Throwable e) {
            int dd = 0;
        }
        if (smsSet2 != null) {
            smsSet2.addSms(smsSet.getSms(0));
            if (smsSet2.getCorrelationId() == null) {
                // filling correcationId if not all SmsSet are filled
                smsSet2.setCorrelationId(smsSet.getCorrelationId());
            }
        } else {
            res.put(smsSet.getTargetId(), smsSet);
        }
    }
    // adding into SmsSetCashe
    ArrayList<SmsSet> res2 = new ArrayList<SmsSet>();
    // 60 min timeout
    Date timeOutDate = new Date(new Date().getTime() - 1000 * 60 * 30);
    for (SmsSet smsSet : res.values()) {
        smsSet.resortSms();
        TargetAddress lock = SmsSetCache.getInstance().addSmsSet(new TargetAddress(smsSet));
        try {
            SmsSet smsSet2;
            synchronized (lock) {
                smsSet2 = SmsSetCache.getInstance().getProcessingSmsSet(smsSet.getTargetId());
                if (smsSet2 != null) {
                    if (smsSet2.getLastUpdateTime().after(timeOutDate)) {
                        smsSet2.addSmsSet(smsSet);
                    // for (int i1 = 0; i1 < smsSet.getSmsCount(); i1++) {
                    // Sms smsx = smsSet.getSms(i1);
                    // if (!smsSet2.checkSmsPresent(smsx)) {
                    // smsSet2.addSmsSet(smsx);
                    // }
                    // }
                    } else {
                        logger.warn("Timeout of SmsSet in ProcessingSmsSet: targetId=" + smsSet2.getTargetId() + ", messageCount=" + smsSet2.getSmsCount());
                        smsSet2 = smsSet;
                        SmsSetCache.getInstance().addProcessingSmsSet(smsSet2.getTargetId(), smsSet2, processingSmsSetTimeout);
                    }
                } else {
                    smsSet2 = smsSet;
                    SmsSetCache.getInstance().addProcessingSmsSet(smsSet2.getTargetId(), smsSet2, processingSmsSetTimeout);
                }
            }
            res2.add(smsSet2);
        } finally {
            SmsSetCache.getInstance().removeSmsSet(lock);
        }
    }
    return res2;
}
Also used : FastMap(javolution.util.FastMap) ArrayList(java.util.ArrayList) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmsSet(org.mobicents.smsc.library.SmsSet) Date(java.util.Date)

Example 3 with TargetAddress

use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.

the class DBOperations method c2_checkProcessingSmsSet.

public boolean c2_checkProcessingSmsSet(SmsSet smsSet) {
    Date timeOutDate = new Date(new Date().getTime() - 1000 * 60 * 30);
    TargetAddress lock = SmsSetCache.getInstance().addSmsSet(new TargetAddress(smsSet));
    try {
        synchronized (lock) {
            SmsSet smsSet2 = SmsSetCache.getInstance().getProcessingSmsSet(smsSet.getTargetId());
            if (smsSet2 != null) {
                if (smsSet2.getLastUpdateTime().after(timeOutDate)) {
                    smsSet2.addSmsSet(smsSet);
                    // }
                    return false;
                } else {
                    logger.warn("Timeout of SmsSet in ProcessingSmsSet: targetId=" + smsSet2.getTargetId() + ", messageCount=" + smsSet2.getSmsCount());
                    smsSet2 = smsSet;
                    SmsSetCache.getInstance().addProcessingSmsSet(smsSet2.getTargetId(), smsSet2, processingSmsSetTimeout);
                }
            } else {
                smsSet2 = smsSet;
                SmsSetCache.getInstance().addProcessingSmsSet(smsSet2.getTargetId(), smsSet2, processingSmsSetTimeout);
            }
        }
    } finally {
        SmsSetCache.getInstance().removeSmsSet(lock);
    }
    return true;
}
Also used : TargetAddress(org.mobicents.smsc.library.TargetAddress) Date(java.util.Date) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 4 with TargetAddress

use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testSubmitSm_MProc.

@Test(groups = { "TxSmppServer" })
public void testSubmitSm_MProc() throws Exception {
    if (!this.cassandraDbInited)
        return;
    MProcManagement mProcManagement = MProcManagement.getInstance();
    SmscManagement smscManagement = SmscManagement.getInstance("Test");
    SmppManagement smppManagement = SmppManagement.getInstance("Test");
    smscManagement.setSmppManagement(smppManagement);
    mProcManagement.setSmscManagement(smscManagement);
    smscManagement.registerRuleFactory(new MProcRuleFactoryDefault());
    // this.pers.stop();
    DBOperations.getInstance().stop();
    smscManagement.start();
    try {
        mProcManagement.destroyMProcRule(1);
    } catch (Exception e) {
    }
    try {
        mProcManagement.destroyMProcRule(2);
    } catch (Exception e) {
    }
    mProcManagement.createMProcRule(1, MProcRuleFactoryDefault.RULE_CLASS_NAME, "desttonmask 1 destnpimask 1 originatingmask SMPP networkidmask 0 newnetworkid 5 adddestdigprefix 47 makecopy true");
    mProcManagement.createMProcRule(2, MProcRuleFactoryDefault.RULE_CLASS_NAME, "networkidmask 5 newdestnpi 2 makecopy true");
    // TODO: ***** make proper mproc rules testing
    // MProcManagement.getInstance().createMProcRule(1, 1, 1, "-1", "SMPP", 0, 5, -1, -1, "47", true);
    // MProcManagement.getInstance().createMProcRule(2, -1, -1, "-1", null, 5, -1, -1, 2, "-1", true);
    // destTonMask, destNpiMask, destDigMask, originatingMask, networkIdMask, newNetworkId, newDestTon, newDestNpi,
    // addDestDigPrefix, makeCopy
    // TODO: ***** make proper mproc rules testing
    this.smppSess = new SmppSessionsProxy();
    this.sbb.setSmppServerSessions(smppSess);
    int windowSize = SmppConstants.DEFAULT_WINDOW_SIZE;
    long connectTimeout = SmppConstants.DEFAULT_CONNECT_TIMEOUT;
    long requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
    long clientBindTimeout = SmppConstants.DEFAULT_BIND_TIMEOUT;
    long windowMonitorInterval = SmppConstants.DEFAULT_WINDOW_MONITOR_INTERVAL;
    long windowWaitTimeout = SmppConstants.DEFAULT_WINDOW_WAIT_TIMEOUT;
    Esme esme = new Esme("Esme_1", "Esme_systemId_1", "pwd", "host", 0, false, null, SmppInterfaceVersionType.SMPP34, -1, -1, null, SmppBindType.TRANSCEIVER, SmppSession.Type.CLIENT, windowSize, connectTimeout, requestExpiryTimeout, clientBindTimeout, windowMonitorInterval, windowWaitTimeout, "Esme_1", true, 30000, 0, 0, -1, -1, "^[0-9a-zA-Z]*", -1, -1, "^[0-9a-zA-Z]*", 0, false, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1);
    ActivityContextInterface aci = new SmppTransactionProxy(esme);
    SubmitSm event = new SubmitSm();
    Date curDate = new Date();
    this.fillSm(event, curDate, true);
    event.setShortMessage(msgUcs2);
    long dueSlot = this.pers.c2_getDueSlotForTime(scheduleDeliveryTime);
    PreparedStatementCollection psc = this.pers.getStatementCollection(scheduleDeliveryTime);
    int b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    long b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
    assertEquals(b1, 0);
    assertEquals(b2, 0L);
    TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Unicode);
    this.sbb.onSubmitSm(event, aci);
    TargetAddress tax1 = new TargetAddress(1, 1, "475555", 5);
    TargetAddress tax2 = new TargetAddress(1, 2, "475555", 5);
    // int addrTon, int addrNpi, String addr, int networkId
    b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
    assertEquals(b1, 1);
    b1 = this.pers.checkSmsExists(dueSlot, tax1.getTargetId());
    assertEquals(b1, 1);
    b1 = this.pers.checkSmsExists(dueSlot, tax2.getTargetId());
    assertEquals(b1, 1);
    SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
    SmsSet smsSet2 = this.pers.c2_getRecordListForTargeId(dueSlot, tax1.getTargetId());
    SmsSet smsSet3 = this.pers.c2_getRecordListForTargeId(dueSlot, tax2.getTargetId());
    assertEquals(smsSet.getDestAddr(), "5555");
    assertEquals(smsSet.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet.getNetworkId(), 0);
    assertEquals(smsSet2.getDestAddr(), "475555");
    assertEquals(smsSet2.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet2.getDestAddrNpi(), SmppConstants.NPI_E164);
    assertEquals(smsSet2.getNetworkId(), 5);
    assertEquals(smsSet3.getDestAddr(), "475555");
    assertEquals(smsSet3.getDestAddrTon(), SmppConstants.TON_INTERNATIONAL);
    assertEquals(smsSet3.getDestAddrNpi(), SmppConstants.NPI_ISDN);
    assertEquals(smsSet3.getNetworkId(), 5);
    // this.checkSmsSet(smsSet, curDate, true);
    // Sms sms = smsSet.getSms(0);
    // assertEquals(sms.getShortMessageText(), sMsg); // msgUcs2
    // assertEquals(sms.getShortMessageBin(), udhCode);
    // 
    // assertEquals(this.smppSess.getReqList().size(), 0);
    // assertEquals(this.smppSess.getRespList().size(), 1);
    PduResponse resp = this.smppSess.getRespList().get(0);
    assertEquals(resp.getCommandStatus(), 0);
    assertEquals(resp.getOptionalParameterCount(), 0);
    try {
        mProcManagement.destroyMProcRule(1);
        mProcManagement.destroyMProcRule(2);
    } catch (Exception e) {
    }
}
Also used : MProcManagement(org.mobicents.smsc.domain.MProcManagement) PduResponse(com.cloudhopper.smpp.pdu.PduResponse) ActivityContextInterface(javax.slee.ActivityContextInterface) Esme(org.restcomm.smpp.Esme) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) TransactionRolledbackLocalException(javax.slee.TransactionRolledbackLocalException) TransactionRequiredLocalException(javax.slee.TransactionRequiredLocalException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) SLEEException(javax.slee.SLEEException) Date(java.util.Date) PreparedStatementCollection(org.mobicents.smsc.cassandra.PreparedStatementCollection) MProcRuleFactoryDefault(org.mobicents.smsc.mproc.impl.MProcRuleFactoryDefault) SmscManagement(org.mobicents.smsc.domain.SmscManagement) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SmppManagement(org.restcomm.smpp.SmppManagement) SmsSet(org.mobicents.smsc.library.SmsSet) Test(org.testng.annotations.Test)

Example 5 with TargetAddress

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("\nReceived 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("\nReceived 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("\nReceived AlertServiceCentre for MSISDN=%s, dueSlot was scheduled but no SmsSet was loaded", addr));
                                }
                            }
                        } else {
                            if (logger.isInfoEnabled()) {
                                logger.info(String.format("\nReceived 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("\nReceived 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);
    }
}
Also used : PersistenceRAInterface(org.mobicents.smsc.slee.resources.persistence.PersistenceRAInterface) SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) MAPDialogSms(org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms) Sms(org.mobicents.smsc.library.Sms) ArrayList(java.util.ArrayList) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) SmsSet(org.mobicents.smsc.library.SmsSet) CreateException(javax.slee.CreateException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) MAPException(org.mobicents.protocols.ss7.map.api.MAPException)

Aggregations

TargetAddress (org.mobicents.smsc.library.TargetAddress)33 Sms (org.mobicents.smsc.library.Sms)27 Date (java.util.Date)12 SmsSet (org.mobicents.smsc.library.SmsSet)12 ArrayList (java.util.ArrayList)10 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)8 Esme (org.restcomm.smpp.Esme)8 ISDNAddressString (org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString)7 FastList (javolution.util.FastList)6 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)6 MProcResult (org.mobicents.smsc.mproc.impl.MProcResult)6 EsmeManagement (org.restcomm.smpp.EsmeManagement)6 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)5 CreateException (javax.slee.CreateException)4 AddressString (org.mobicents.protocols.ss7.map.api.primitives.AddressString)4 Test (org.testng.annotations.Test)4 MAPException (org.mobicents.protocols.ss7.map.api.MAPException)3 MAPDialogSms (org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms)3 SM_RP_DA (org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA)3 DataCodingSchemeImpl (org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)3