Search in sources :

Example 21 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class CdrGenerator method generateCdr.

public static void generateCdr(Sms smsEvent, String status, String reason, boolean generateReceiptCdr, boolean generateCdr, boolean messageIsSplitted, boolean lastSegment, boolean calculateMsgPartsLenCdr, boolean delayParametersInCdr, int seqNumber) {
    if (!generateCdr)
        return;
    if (!generateReceiptCdr && smsEvent.isMcDeliveryReceipt())
        // we do not generate CDR's for receipt if generateReceiptCdr option is off
        return;
    int msgParts = 0, charNumbers = 0;
    if (calculateMsgPartsLenCdr) {
        if (messageIsSplitted) {
            msgParts = 1;
        } else {
            DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(smsEvent.getDataCoding());
            msgParts = MessageUtil.calculateMsgParts(smsEvent.getShortMessageText(), dataCodingScheme, smsEvent.getNationalLanguageLockingShift(), smsEvent.getNationalLanguageSingleShift());
        }
        if (lastSegment) {
            charNumbers = smsEvent.getShortMessageText().length();
        } else {
            charNumbers = 0;
        }
    }
    int dcs = smsEvent.getDataCoding();
    Long receiptLocalMessageId = smsEvent.getReceiptLocalMessageId();
    long msgPartDelTime = -1;
    if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber - 1)) {
        msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getMsgPartDelTime(seqNumber - 1);
    } else if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber)) {
        msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getSubmitDate().getTime();
    }
    DeliveryReceiptData deliveryReceiptData = MessageUtil.parseDeliveryReceipt(smsEvent.getShortMessageText(), smsEvent.getTlvSet());
    String st = null;
    int tlvMessageState = -1;
    int err = -1;
    if (deliveryReceiptData != null) {
        st = deliveryReceiptData.getStatus();
        tlvMessageState = deliveryReceiptData.getTlvMessageState() == null ? -1 : deliveryReceiptData.getTlvMessageState();
        err = deliveryReceiptData.getError();
    }
    StringBuffer sb = new StringBuffer();
    sb.append(DATE_FORMAT.format(smsEvent.getSubmitDate())).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(status).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginationType()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getReceiptLocalMessageId() == null ? "message" : "dlr").append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigSystemId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getDlvMessageId()).append(CdrGenerator.CDR_SEPARATOR).append((receiptLocalMessageId != null && receiptLocalMessageId == -1) ? "xxxx" : smsEvent.getReceiptLocalMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getLocationInfoWithLMSI() != null ? smsEvent.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddress() : null).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getImsi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getCorrelationId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginatorSccpAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMtServiceCenterAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMprocNotes()).append(CdrGenerator.CDR_SEPARATOR).append(msgParts).append(CdrGenerator.CDR_SEPARATOR).append(charNumbers).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getProcessingTime(smsEvent.getSubmitDate()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getScheduleDeliveryDelayMilis(smsEvent.getSubmitDate(), smsEvent.getScheduleDeliveryTime()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? smsEvent.getDeliveryCount() : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(msgPartDelTime != -1 ? msgPartDelTime : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(dcs).append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(getFirst20CharOfSMS(smsEvent.getShortMessageText()))).append("\"").append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(reason)).append("\"").append(CdrGenerator.CDR_SEPARATOR).append(st != null ? st : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(tlvMessageState != -1 ? tlvMessageState : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(err != -1 ? err : CdrGenerator.CDR_EMPTY);
    CdrGenerator.generateCdr(sb.toString());
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) DeliveryReceiptData(org.mobicents.smsc.mproc.DeliveryReceiptData) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)

Example 22 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class TxSipServerSbb method onMESSAGE.

// *********
// SIP Event Handlers
public void onMESSAGE(javax.sip.RequestEvent event, ActivityContextInterface aci) {
    if (this.logger.isFineEnabled()) {
        this.logger.fine("onMESSAGE " + event);
    }
    Sip sip = sipManagement.getSipByName(SipManagement.SIP_NAME);
    try {
        final Request request = event.getRequest();
        byte[] message = request.getRawContent();
        final ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
        final String toUser = ((SipUri) toHeader.getAddress().getURI()).getUser();
        final FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
        final String fromUser = ((SipUri) fromHeader.getAddress().getURI()).getUser();
        // Persist this message
        TargetAddress ta = this.createDestTargetAddress(toUser, sip.getNetworkId());
        byte[] udh = null;
        Header udhHeader = request.getHeader(SipXHeaders.XSmsUdh);
        if (udhHeader != null) {
            udh = this.hexStringToByteArray(((SIPHeader) udhHeader).getValue());
        }
        Header codingHeader = request.getHeader(SipXHeaders.XSmsCoding);
        DataCodingSchemeImpl codingSchme = dcsGsm7;
        if (codingHeader != null) {
            int dcs = Integer.parseInt(((SIPHeader) codingHeader).getValue());
            codingSchme = this.createDataCodingScheme(dcs);
        }
        Date validityPeriod = null;
        Header validityHeader = request.getHeader(SipXHeaders.XSmsValidty);
        if (validityHeader != null) {
            try {
                validityPeriod = MessageUtil.parseDate(((SIPHeader) validityHeader).getValue());
            } catch (ParseException e) {
                logger.severe("ParseException when parsing ValidityPeriod field: " + e.getMessage(), e);
                if (smscPropertiesManagement.isGenerateRejectionCdr()) {
                    generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e.getMessage(), true);
                }
                ServerTransaction serverTransaction = event.getServerTransaction();
                Response res;
                try {
                    res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
                    event.getServerTransaction().sendResponse(res);
                } catch (Exception e1) {
                    this.logger.severe("Exception while trying to send 500 response to sip", e1);
                }
                return;
            }
        }
        // Registered Delivery
        int regDeliveryInt = 0;
        Header regDeliveryHeader = request.getHeader(SipXHeaders.XRegDelivery);
        if (regDeliveryHeader != null) {
            regDeliveryInt = Integer.parseInt(((SIPHeader) regDeliveryHeader).getValue());
        }
        Sms sms = null;
        try {
            sms = this.createSmsEvent(fromUser, message, ta, persistence, udh, codingSchme, validityPeriod, regDeliveryInt, sip.getNetworkId());
            this.processSms(sms, persistence);
        } catch (SmscProcessingException e1) {
            if (!e1.isSkipErrorLogging()) {
                if (e1.isIsWarning()) {
                    this.logger.warning(e1.getMessage());
                } else {
                    this.logger.severe(e1.getMessage(), e1);
                }
                smscStatAggregator.updateMsgInFailedAll();
            }
            if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
                if (sms != null) {
                    generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), false, true);
                } else {
                    generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
                }
            }
            ServerTransaction serverTransaction = event.getServerTransaction();
            Response res;
            try {
                res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
                event.getServerTransaction().sendResponse(res);
            } catch (Exception e) {
                this.logger.severe("Exception while trying to send Ok response to sip", e);
            }
            return;
        } catch (Throwable e1) {
            this.logger.severe("Exception while processing a message from sip", e1);
            smscStatAggregator.updateMsgInFailedAll();
            if (smscPropertiesManagement.isGenerateRejectionCdr()) {
                generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
            }
            ServerTransaction serverTransaction = event.getServerTransaction();
            Response res;
            try {
                // TODO: we possibly need to response ERROR message to sip
                res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
                event.getServerTransaction().sendResponse(res);
            } catch (Exception e) {
                this.logger.severe("Exception while trying to send Ok response to sip", e);
            }
            return;
        }
        ServerTransaction serverTransaction = event.getServerTransaction();
        Response res;
        try {
            res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
            event.getServerTransaction().sendResponse(res);
        } catch (Exception e) {
            this.logger.severe("Exception while trying to send Ok response to sip", e);
        }
    } catch (Exception e) {
        this.logger.severe("Error while trying to process received the SMS " + event, e);
    }
}
Also used : FromHeader(javax.sip.header.FromHeader) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Request(javax.sip.message.Request) TargetAddress(org.mobicents.smsc.library.TargetAddress) SipUri(gov.nist.javax.sip.address.SipUri) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) Date(java.util.Date) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) ParseException(java.text.ParseException) Response(javax.sip.message.Response) ToHeader(javax.sip.header.ToHeader) FromHeader(javax.sip.header.FromHeader) SIPHeader(gov.nist.javax.sip.header.SIPHeader) Header(javax.sip.header.Header) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ToHeader(javax.sip.header.ToHeader) Sms(org.mobicents.smsc.library.Sms) Sip(org.mobicents.smsc.domain.Sip) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction)

Example 23 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class SmppTestingForm method submitMessage.

private void submitMessage(EncodingType encodingType, int messageClass, String messageText, SplittingType splittingType, ValidityType validityType, String destAddr, SmppSimulatorParameters.MessagingMode messagingMode, int specifiedSegmentLength) {
    if (session0 == null)
        return;
    try {
        int dcs = 0;
        ArrayList<byte[]> msgLst = new ArrayList<byte[]>();
        int msgRef = 0;
        switch(encodingType) {
            case GSM7_DCS_0:
                dcs = 0;
                break;
            case GSM8_DCS_4:
                dcs = 4;
                break;
            case UCS2_DCS_8:
                dcs = 8;
                break;
        }
        // if (messageClass) {
        // dcs += 16;
        // }
        int messageClassVal = 0;
        if (messageClass > 0) {
            messageClassVal = messageClass;
        }
        DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
        int maxLen = MessageUtil.getMaxSolidMessageCharsLength(dataCodingScheme);
        int maxSplLen = MessageUtil.getMaxSegmentedMessageCharsLength(dataCodingScheme);
        if (splittingType == SplittingType.SplitWithParameters_SpecifiedSegmentLength || splittingType == SplittingType.SplitWithUdh_SpecifiedSegmentLength) {
            maxLen = specifiedSegmentLength;
            maxSplLen = specifiedSegmentLength;
        }
        int segmCnt = 0;
        int esmClass = 0;
        boolean addSegmTlv = false;
        if (messageText.length() > maxLen) {
            // may be message splitting
            SplittingType st = splittingType;
            switch(st) {
                case DoNotSplit:
                    // we do not split
                    byte[] buf1 = encodeSegment(messageText, encodingType);
                    byte[] buf2;
                    if (encodingType == EncodingType.GSM8_DCS_4) {
                        // 4-bytes length
                        byte[] bf3 = new byte[7];
                        // total UDH length
                        bf3[0] = 6;
                        // UDH id
                        bf3[1] = 5;
                        // UDH length
                        bf3[2] = 4;
                        bf3[3] = 0x3E;
                        bf3[4] = (byte) 0x94;
                        bf3[5] = 0;
                        bf3[6] = 0;
                        // 0-bytes length
                        // bf3 = new byte[3];
                        // bf3[0] = 2; // total UDH length
                        // bf3[1] = 112; // UDH id
                        // bf3[2] = 0; // UDH length
                        buf2 = new byte[bf3.length + buf1.length];
                        System.arraycopy(bf3, 0, buf2, 0, bf3.length);
                        System.arraycopy(buf1, 0, buf2, bf3.length, buf1.length);
                        esmClass = 0x40;
                    } else {
                        buf2 = buf1;
                    }
                    msgLst.add(buf2);
                    ArrayList<String> r1 = this.splitStr(messageText, maxSplLen);
                    segmCnt = r1.size();
                    break;
                case SplitWithParameters_DefaultSegmentLength:
                case SplitWithParameters_SpecifiedSegmentLength:
                    msgRef = getNextMsgRef();
                    r1 = this.splitStr(messageText, maxSplLen);
                    for (String bf : r1) {
                        msgLst.add(encodeSegment(bf, encodingType));
                    }
                    segmCnt = msgLst.size();
                    addSegmTlv = true;
                    break;
                case SplitWithUdh_DefaultSegmentLength:
                case SplitWithUdh_SpecifiedSegmentLength:
                    msgRef = getNextMsgRef();
                    r1 = this.splitStr(messageText, maxSplLen);
                    byte[] bf1 = new byte[6];
                    // total UDH length
                    bf1[0] = 5;
                    // UDH id
                    bf1[1] = 0;
                    // UDH length
                    bf1[2] = 3;
                    // refNum
                    bf1[3] = (byte) msgRef;
                    // segmCnt
                    bf1[4] = (byte) r1.size();
                    int i1 = 0;
                    for (String bfStr : r1) {
                        byte[] bf = encodeSegment(bfStr, encodingType);
                        i1++;
                        // segmNum
                        bf1[5] = (byte) i1;
                        byte[] bf2 = new byte[bf1.length + bf.length];
                        System.arraycopy(bf1, 0, bf2, 0, bf1.length);
                        System.arraycopy(bf, 0, bf2, bf1.length, bf.length);
                        msgLst.add(bf2);
                    }
                    segmCnt = msgLst.size();
                    esmClass = 0x40;
                    break;
            }
        } else {
            byte[] buf = encodeSegment(messageText, encodingType);
            if (encodingType == EncodingType.GSM8_DCS_4) {
                byte[] bf1 = new byte[7];
                // total UDH length
                bf1[0] = 6;
                // UDH id
                bf1[1] = 5;
                // UDH length
                bf1[2] = 4;
                bf1[3] = 0x3e;
                bf1[4] = (byte) 0x94;
                bf1[5] = 0;
                bf1[6] = 0;
                // 0-bytes length
                // bf1 = new byte[3];
                // bf1[0] = 2; // total UDH length
                // bf1[1] = 112; // UDH id
                // bf1[2] = 0; // UDH length
                byte[] bf2 = new byte[bf1.length + buf.length];
                System.arraycopy(bf1, 0, bf2, 0, bf1.length);
                System.arraycopy(buf, 0, bf2, bf1.length, buf.length);
                msgLst.add(bf2);
                esmClass = 0x40;
            } else {
                msgLst.add(buf);
            }
            segmCnt = 1;
        }
        esmClass |= messagingMode.getCode();
        this.doSubmitMessage(dcs, msgLst, msgRef, addSegmTlv, esmClass, validityType, segmCnt, destAddr, messageClassVal);
    } catch (Exception e) {
        this.addMessage("Failure to submit message", e.toString());
        return;
    }
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) ArrayList(java.util.ArrayList) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) SplittingType(org.mobicents.smsc.tools.smppsimulator.SmppSimulatorParameters.SplittingType) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 24 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class ClientSmppSessionHandler method firePduRequestReceived.

// private int incMsgCnt = 0;
@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
    // incMsgCnt++;
    // if (incMsgCnt > 150) {
    // incMsgCnt = 0;
    // try {
    // Thread.sleep(60000);
    // } catch (InterruptedException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // }
    testingForm.addMessage("PduRequestReceived: " + pduRequest.getName(), pduRequest.toString());
    this.testingForm.messagesRcvd.incrementAndGet();
    PduResponse resp = pduRequest.createResponse();
    // here we can insert responses
    if (pduRequest.getCommandId() == SmppConstants.CMD_ID_DELIVER_SM || pduRequest.getCommandId() == SmppConstants.CMD_ID_DATA_SM || pduRequest.getCommandId() == SmppConstants.CMD_ID_SUBMIT_SM) {
        if (pduRequest instanceof BaseSm) {
            BaseSm dev = (BaseSm) pduRequest;
            byte[] data = dev.getShortMessage();
            if (dev.getShortMessageLength() == 0) {
                // Probably the message_payload Optional Parameter is being used
                Tlv messagePaylod = dev.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
                if (messagePaylod != null) {
                    data = messagePaylod.getValue();
                }
            }
            DataCodingScheme dcs = new DataCodingSchemeImpl(dev.getDataCoding());
            boolean udhPresent = (dev.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
            byte[] textPart = data;
            byte[] udhData = null;
            if (udhPresent && data.length > 2) {
                // UDH exists
                int udhLen = (data[0] & 0xFF) + 1;
                if (udhLen <= data.length) {
                    textPart = new byte[textPart.length - udhLen];
                    udhData = new byte[udhLen];
                    System.arraycopy(data, udhLen, textPart, 0, textPart.length);
                    System.arraycopy(data, 0, udhData, 0, udhLen);
                }
            }
            String s = null;
            switch(dcs.getCharacterSet()) {
                case GSM7:
                case UCS2:
                    if (this.testingForm.getSmppSimulatorParameters().getSmppEncoding() == 0) {
                        s = new String(textPart, utf8Charset);
                    } else if (this.testingForm.getSmppSimulatorParameters().getSmppEncoding() == 1) {
                        s = new String(textPart, ucs2Charset);
                    } else {
                        GSMCharsetDecoder decoder = (GSMCharsetDecoder) gsm7Charset.newDecoder();
                        decoder.setGSMCharsetDecodingData(new GSMCharsetDecodingData(Gsm7EncodingStyle.bit8_smpp_style, Integer.MAX_VALUE, 0));
                        ByteBuffer bb = ByteBuffer.wrap(textPart);
                        CharBuffer bf = null;
                        try {
                            bf = decoder.decode(bb);
                        } catch (CharacterCodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        s = bf.toString();
                    }
                    break;
                case GSM8:
                    s = new String(textPart, isoCharset);
                    break;
            }
            String s2 = "";
            if (udhData != null) {
                StringBuilder sb = new StringBuilder();
                sb.append("[");
                int i2 = 0;
                for (byte b : udhData) {
                    int i1 = (b & 0xFF);
                    if (i2 == 0)
                        i2 = 1;
                    else
                        sb.append(", ");
                    sb.append(i1);
                }
                sb.append("] ");
                s2 = sb.toString();
            }
            testingForm.addMessage("TextReceived: ", s2 + s);
        // try {
        // Thread.sleep(1000);
        // } catch (InterruptedException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
        }
        if (this.testingForm.getSmppSimulatorParameters().isRejectIncomingDeliveryMessage()) {
            resp.setCommandStatus(1);
        }
        long mId = this.testingForm.getMsgIdGenerator().incrementAndGet();
        String msgId;
        String msgId2;
        String msgId3;
        if (this.testingForm.getSmppSimulatorParameters().isIdResponseTlv()) {
            msgId = String.format("%08X", mId);
            msgId2 = MessageUtil.createMessageIdString(mId);
            msgId3 = msgId;
            if (this.testingForm.getSmppSimulatorParameters().isWrongMessageIdInDlr())
                msgId3 = msgId3 + "XYZ";
        } else {
            msgId = MessageUtil.createMessageIdString(mId);
            msgId2 = MessageUtil.createMessageIdString(mId);
            if (this.testingForm.getSmppSimulatorParameters().isWrongMessageIdInDlr())
                msgId2 = msgId2 + "XYZ";
            msgId3 = null;
        }
        MessageState msgState = null;
        if (this.testingForm.getSmppSimulatorParameters().isIdResponseTlvMessageState()) {
            if (this.testingForm.getSmppSimulatorParameters().isRejectIncomingDeliveryMessage())
                // message will have message_state set to REJECTED (value 8)
                msgState = MessageState.REJECTED;
            else if (this.testingForm.getSmppSimulatorParameters().getDeliveryResponseGenerating().equals(DeliveryResponseGenerating.Error8)) {
                // message will have message_state set to UNDELIVERABLE (value 5)
                msgState = MessageState.UNDELIVERABLE;
            } else {
                // message should have message_state set to DELIVERED (value 2)
                msgState = MessageState.DELIVERED;
            }
        }
        if (!(pduRequest instanceof DeliverSm) || this.testingForm.getSmppSimulatorParameters().isAddMessageIdIntoDeliverySmResp()) {
            ((BaseSmResp) resp).setMessageId(msgId);
        }
        // scheduling of delivery receipt if needed
        if (this.testingForm.getSmppSimulatorParameters().getDeliveryResponseGenerating() != DeliveryResponseGenerating.No) {
            int delay = 100;
            if (this.testingForm.getSmppSimulatorParameters().isDeliveryResponseAfter2Min())
                delay = 2 * 60 * 1000;
            this.testingForm.getExecutor().schedule(new DeliveryReceiptSender(this.testingForm.getSmppSimulatorParameters().getDeliveryResponseGenerating(), new Date(), msgId2, msgId3, msgState), delay, TimeUnit.MILLISECONDS);
        }
        testingForm.addMessage("PduResponseSent: " + resp.getName(), resp.toString());
    }
    boolean delayRequired = testingForm.getSmppSimulatorParameters().getResponseDelay() > 0;
    if (delayRequired)
        await(testingForm.getSmppSimulatorParameters().getResponseDelay(), TimeUnit.MILLISECONDS);
    return resp;
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) PduResponse(com.cloudhopper.smpp.pdu.PduResponse) BaseSm(com.cloudhopper.smpp.pdu.BaseSm) CharBuffer(java.nio.CharBuffer) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date) MessageState(org.mobicents.smsc.library.MessageState) BaseSmResp(com.cloudhopper.smpp.pdu.BaseSmResp) GSMCharsetDecoder(org.restcomm.protocols.ss7.map.datacoding.GSMCharsetDecoder) GSMCharsetDecodingData(org.restcomm.protocols.ss7.map.datacoding.GSMCharsetDecodingData) Tlv(com.cloudhopper.smpp.tlv.Tlv) DeliverSm(com.cloudhopper.smpp.pdu.DeliverSm)

Aggregations

DataCodingSchemeImpl (org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)24 DataCodingScheme (org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme)18 Test (org.testng.annotations.Test)12 Date (java.util.Date)11 Sms (org.mobicents.smsc.library.Sms)10 UserDataHeader (org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)8 ByteBuffer (java.nio.ByteBuffer)7 SmsSet (org.mobicents.smsc.library.SmsSet)7 AddressField (org.restcomm.protocols.ss7.map.api.smstpdu.AddressField)7 ProtocolIdentifier (org.restcomm.protocols.ss7.map.api.smstpdu.ProtocolIdentifier)7 SmsSignalInfoImpl (org.restcomm.protocols.ss7.map.service.sms.SmsSignalInfoImpl)7 AddressFieldImpl (org.restcomm.protocols.ss7.map.smstpdu.AddressFieldImpl)7 ProtocolIdentifierImpl (org.restcomm.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl)7 UserDataImpl (org.restcomm.protocols.ss7.map.smstpdu.UserDataImpl)7 CharacterCodingException (java.nio.charset.CharacterCodingException)6 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)6 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)6 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)6 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)6 SM_RP_DA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA)6