Search in sources :

Example 36 with DataCodingScheme

use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme 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

DataCodingScheme (org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme)21 DataCodingSchemeImpl (org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)19 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)18 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)18 Sms (org.mobicents.smsc.library.Sms)17 Test (org.testng.annotations.Test)17 SmsSet (org.mobicents.smsc.library.SmsSet)16 SmsSignalInfo (org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo)16 UserDataHeader (org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)16 ArrayList (java.util.ArrayList)15 SM_RP_DA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA)15 UserData (org.restcomm.protocols.ss7.map.api.smstpdu.UserData)15 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)14 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)14 ISDNAddressStringImpl (org.restcomm.protocols.ss7.map.primitives.ISDNAddressStringImpl)14 Date (java.util.Date)13 SM_RP_OA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_OA)10 UUID (java.util.UUID)9 SmscPropertiesManagement (org.mobicents.smsc.domain.SmscPropertiesManagement)9 MAPTestEvent (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy.MAPTestEvent)9