Search in sources :

Example 11 with Address

use of com.cloudhopper.smpp.type.Address in project smscgateway by RestComm.

the class SmppTestingForm method doSubmitMessage.

private void doSubmitMessage(int dcs, ArrayList<byte[]> msgLst, int msgRef, boolean addSegmTlv, int esmClass, SmppSimulatorParameters.ValidityType validityType, int segmentCnt, String destAddr, int messageClassVal) throws Exception {
    int i1 = 0;
    for (byte[] buf : msgLst) {
        i1++;
        BaseSm pdu;
        switch(this.param.getSendingMessageType()) {
            case SubmitSm:
                SubmitSm submitPdu = new SubmitSm();
                pdu = submitPdu;
                break;
            case DataSm:
                DataSm dataPdu = new DataSm();
                pdu = dataPdu;
                break;
            case DeliverSm:
                DeliverSm deliverPdu = new DeliverSm();
                pdu = deliverPdu;
                break;
            case SubmitMulti:
                SubmitMulti submitMulti = new SubmitMulti();
                pdu = submitMulti;
                break;
            default:
                return;
        }
        pdu.setSourceAddress(new Address((byte) this.param.getSourceTON().getCode(), (byte) this.param.getSourceNPI().getCode(), this.param.getSourceAddress()));
        if (this.param.getSendingMessageType() == SendingMessageType.SubmitMulti) {
            long daOrig = 1;
            try {
                daOrig = Long.parseLong(destAddr);
            } catch (Exception e) {
            }
            for (int i2 = 0; i2 < this.param.getSubmitMultiMessageCnt(); i2++) {
                // this code can be used for testing of address rejections
                // if(i2 == 0){
                // ((SubmitMulti) pdu).addDestAddresses(new Address((byte)
                // 8, (byte) this.param.getDestNPI().getCode(), String
                // .valueOf(daOrig + i2)));
                // }else {
                // ((SubmitMulti) pdu).addDestAddresses(new Address((byte)
                // this.param.getDestTON().getCode(), (byte)
                // this.param.getDestNPI().getCode(), String
                // .valueOf(daOrig + i2)));
                // }
                ((SubmitMulti) pdu).addDestAddresses(new Address((byte) this.param.getDestTON().getCode(), (byte) this.param.getDestNPI().getCode(), String.valueOf(daOrig + i2)));
            }
        } else {
            pdu.setDestAddress(new Address((byte) this.param.getDestTON().getCode(), (byte) this.param.getDestNPI().getCode(), destAddr));
        }
        pdu.setEsmClass((byte) esmClass);
        switch(validityType) {
            case ValidityPeriod_5min:
                pdu.setValidityPeriod(MessageUtil.printSmppRelativeDate(0, 0, 0, 0, 5, 0));
                break;
            case ValidityPeriod_2hours:
                pdu.setValidityPeriod(MessageUtil.printSmppRelativeDate(0, 0, 0, 2, 0, 0));
                break;
            case ScheduleDeliveryTime_5min:
                pdu.setScheduleDeliveryTime(MessageUtil.printSmppRelativeDate(0, 0, 0, 0, 5, 0));
                break;
        }
        pdu.setDataCoding((byte) dcs);
        pdu.setRegisteredDelivery((byte) this.param.getMcDeliveryReceipt().getCode());
        if (buf.length < 250 && this.param.getSendingMessageType() != SmppSimulatorParameters.SendingMessageType.DataSm)
            pdu.setShortMessage(buf);
        else {
            Tlv tlv = new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, buf);
            pdu.addOptionalParameter(tlv);
        }
        if (addSegmTlv) {
            byte[] buf1 = new byte[2];
            buf1[0] = 0;
            buf1[1] = (byte) msgRef;
            Tlv tlv = new Tlv(SmppConstants.TAG_SAR_MSG_REF_NUM, buf1);
            pdu.addOptionalParameter(tlv);
            buf1 = new byte[1];
            buf1[0] = (byte) msgLst.size();
            tlv = new Tlv(SmppConstants.TAG_SAR_TOTAL_SEGMENTS, buf1);
            pdu.addOptionalParameter(tlv);
            buf1 = new byte[1];
            buf1[0] = (byte) i1;
            tlv = new Tlv(SmppConstants.TAG_SAR_SEGMENT_SEQNUM, buf1);
            pdu.addOptionalParameter(tlv);
        }
        if (messageClassVal > 0) {
            byte[] buf1 = new byte[1];
            buf1[0] = (byte) messageClassVal;
            Tlv tlv = new Tlv(SmppConstants.TAG_DEST_ADDR_SUBUNIT, buf1);
            pdu.addOptionalParameter(tlv);
        }
        if (this.param.isSendOptionalParameter()) {
            for (Tlv tlv : this.param.getTlvSet().getOptionalParameters()) {
                pdu.addOptionalParameter(tlv);
            }
        }
        WindowFuture<Integer, PduRequest, PduResponse> future0 = session0.sendRequestPdu(pdu, 10000, false);
        this.messagesSent.incrementAndGet();
        if (this.timer == null) {
            this.addMessage("Request=" + pdu.getName(), pdu.toString());
        }
    }
    this.segmentsSent.addAndGet(segmentCnt);
}
Also used : PduResponse(com.cloudhopper.smpp.pdu.PduResponse) Address(com.cloudhopper.smpp.type.Address) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) CharacterCodingException(java.nio.charset.CharacterCodingException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PduRequest(com.cloudhopper.smpp.pdu.PduRequest) DataSm(com.cloudhopper.smpp.pdu.DataSm) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SubmitMulti(com.cloudhopper.smpp.pdu.SubmitMulti) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Aggregations

Address (com.cloudhopper.smpp.type.Address)11 SubmitSm (com.cloudhopper.smpp.pdu.SubmitSm)6 Tlv (com.cloudhopper.smpp.tlv.Tlv)6 SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)4 Date (java.util.Date)4 TargetAddress (org.mobicents.smsc.library.TargetAddress)4 Esme (org.restcomm.smpp.Esme)4 CharacterCodingException (java.nio.charset.CharacterCodingException)3 Sms (org.mobicents.smsc.library.Sms)3 DeliverSm (com.cloudhopper.smpp.pdu.DeliverSm)2 SubmitMulti (com.cloudhopper.smpp.pdu.SubmitMulti)2 SubmitMultiResp (com.cloudhopper.smpp.pdu.SubmitMultiResp)2 SubmitSmResp (com.cloudhopper.smpp.pdu.SubmitSmResp)2 TlvConvertException (com.cloudhopper.smpp.tlv.TlvConvertException)2 UnsucessfulSME (com.cloudhopper.smpp.type.UnsucessfulSME)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SmppSessionsProxy (org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy)2 Test (org.testng.annotations.Test)2