Package com.cloudhopper.smpp.tlv

Examples of com.cloudhopper.smpp.tlv.Tlv


            bound = true;

            //
            // negotiate version in use based on response back from server
            //
            Tlv scInterfaceVersion = bindResponse.getOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION);

            if (scInterfaceVersion == null) {
                // this means version 3.3 is in use
                this.interfaceVersion = SmppConstants.VERSION_3_3;
            } else {
                try {
                    byte tempInterfaceVersion = scInterfaceVersion.getValueAsByte();
                    if (tempInterfaceVersion >= SmppConstants.VERSION_3_4) {
                        this.interfaceVersion = SmppConstants.VERSION_3_4;
                    } else {
                        this.interfaceVersion = SmppConstants.VERSION_3_3;
                    }
View Full Code Here


            // verify 1 optional parameter was included in bind response
            Assert.assertEquals(1, bindResponse.getOptionalParameterCount());
            Assert.assertEquals("cloudhopper", bindResponse.getSystemId());

            Tlv scInterfaceVersion = bindResponse.getOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION);
            Assert.assertNotNull(scInterfaceVersion);
            Assert.assertEquals(SmppConstants.VERSION_3_4, scInterfaceVersion.getValueAsByte());

            serverSession0.close();
            Thread.sleep(200);
            Assert.assertEquals(0, serverHandler.sessions.size());
            Assert.assertEquals(0, server0.getChannels().size());
View Full Code Here

            // verify 1 optional parameter was included in bind response
            Assert.assertEquals(1, bindResponse.getOptionalParameterCount());
            Assert.assertEquals("cloudhopper", bindResponse.getSystemId());

            Tlv scInterfaceVersion = bindResponse.getOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION);
            Assert.assertNotNull(scInterfaceVersion);
            Assert.assertEquals(SmppConstants.VERSION_3_4, scInterfaceVersion.getValueAsByte());

            serverSession0.close();
            Thread.sleep(200);
            Assert.assertEquals(0, serverHandler.sessions.size());
            Assert.assertEquals(0, server0.getChannels().size());
View Full Code Here

        Assert.assertArrayEquals(HexUtil.toByteArray("4100"), BufferHelper.createByteArray(buffer0));
    }

    @Test
    public void readTlv() throws Exception {
        Tlv tlv0 = null;
        ChannelBuffer buffer0 = null;

        // a single byte TLV
        buffer0 = BufferHelper.createBuffer("0210000134");
        tlv0 = ChannelBufferUtil.readTlv(buffer0);

        Assert.assertEquals(0, buffer0.readableBytes());
        Assert.assertEquals((short)0x0210, tlv0.getTag());
        Assert.assertEquals((short)0x01, tlv0.getLength());
        Assert.assertArrayEquals(new byte[] {0x34}, tlv0.getValue());

        // a C-string TLV
        buffer0 = BufferHelper.createBuffer("140200056331657400");
        tlv0 = ChannelBufferUtil.readTlv(buffer0);

        Assert.assertEquals(0, buffer0.readableBytes());
        Assert.assertEquals((short)0x1402, tlv0.getTag());
        Assert.assertEquals((short)0x05, tlv0.getLength());
        Assert.assertArrayEquals(HexUtil.toByteArray("6331657400"), tlv0.getValue());

        // a short or just 2 byte TLV
        buffer0 = BufferHelper.createBuffer("02040002ce34");
        tlv0 = ChannelBufferUtil.readTlv(buffer0);

        Assert.assertEquals(0, buffer0.readableBytes());
        Assert.assertEquals((short)0x0204, tlv0.getTag());
        Assert.assertEquals((short)0x02, tlv0.getLength());
        Assert.assertArrayEquals(HexUtil.toByteArray("ce34"), tlv0.getValue());

        // a sample message payload TLV
        buffer0 = BufferHelper.createBuffer("0424002f4f4d4720492077616e7420746f207365652022546865204372617a69657322206c6f6f6b73207369636b21203d5d20");
        tlv0 = ChannelBufferUtil.readTlv(buffer0);
        // OMG I want to see "The Crazies" looks sick! =]
        Assert.assertEquals(0, buffer0.readableBytes());
        Assert.assertEquals((short)0x0424, tlv0.getTag());
        Assert.assertEquals((short)0x2f, tlv0.getLength());
        // convert bytes to actual chars
        Assert.assertEquals("OMG I want to see \"The Crazies\" looks sick! =] ", new String(tlv0.getValue()));

        // multiple TLVs in a row
        buffer0 = BufferHelper.createBuffer("000e000101000600010104240001");
        tlv0 = ChannelBufferUtil.readTlv(buffer0);
        Assert.assertEquals(9, buffer0.readableBytes());
        Assert.assertEquals((short)0x0e, tlv0.getTag());
        Assert.assertEquals((short)0x01, tlv0.getLength());
        Assert.assertArrayEquals(HexUtil.toByteArray("01"), tlv0.getValue());

        tlv0 = ChannelBufferUtil.readTlv(buffer0);
        Assert.assertEquals(4, buffer0.readableBytes());
        Assert.assertEquals((short)0x06, tlv0.getTag());
        Assert.assertEquals((short)0x01, tlv0.getLength());
        Assert.assertArrayEquals(HexUtil.toByteArray("01"), tlv0.getValue());

        try {
            // this should error out since we don't have enough bytes
            tlv0 = ChannelBufferUtil.readTlv(buffer0);
            Assert.fail();
        } catch (NotEnoughDataInBufferException e) {
            // correct behavior
            Assert.assertEquals(0, buffer0.readableBytes());
        }

        // a TLV with an unsigned short length (1 above 15-bit integer)
        StringBuilder buf = new StringBuilder(40000);
        buf.append("FFFF8000");
        for (int i = 0; i < 0x8000; i++) {
            buf.append("01");
        }
        buffer0 = BufferHelper.createBuffer(buf.toString());
        tlv0 = ChannelBufferUtil.readTlv(buffer0);
        Assert.assertEquals(0, buffer0.readableBytes());
        Assert.assertEquals((short)0xffff, tlv0.getTag());
        Assert.assertEquals(32768, tlv0.getUnsignedLength());
        Assert.assertEquals(-32768, tlv0.getLength())// the "signed" version of the length

        // a TLV with an unsigned short length (1 above 15-bit integer)
        buf = new StringBuilder(70000);
        buf.append("FFFFFFFF");
        for (int i = 0; i < 0xFFFF; i++) {
            buf.append("02");
        }
        buffer0 = BufferHelper.createBuffer(buf.toString());
        tlv0 = ChannelBufferUtil.readTlv(buffer0);
        Assert.assertEquals(0, buffer0.readableBytes());
        Assert.assertEquals((short)0xffff, tlv0.getTag());
        Assert.assertEquals(-1, tlv0.getLength())// the "signed" version of the length
    }
View Full Code Here

        Assert.assertEquals(-1, tlv0.getLength())// the "signed" version of the length
    }

    @Test
    public void writeTlv() throws Exception {
        Tlv tlv0 = null;
        ChannelBuffer buffer0 = null;

        buffer0 = ChannelBuffers.dynamicBuffer(10);

        // handle null case
        buffer0.clear();
        ChannelBufferUtil.writeTlv(buffer0, tlv0);
        Assert.assertArrayEquals(HexUtil.toByteArray(""), BufferHelper.createByteArray(buffer0));

        buffer0.clear();
        tlv0 = new Tlv((short)0xFFFF, new byte[] { 0x41, 0x42 });
        ChannelBufferUtil.writeTlv(buffer0, tlv0);
        Assert.assertArrayEquals(HexUtil.toByteArray("FFFF00024142"), BufferHelper.createByteArray(buffer0));
    }
View Full Code Here

public class TlvUtilTest {
    private static final Logger logger = LoggerFactory.getLogger(TlvUtilTest.class);

    @Test
    public void createNullTerminatedStringTlv() throws Exception {
        Tlv tlv0 = null;

        // null string should just be 0x00
        tlv0 = TlvUtil.createNullTerminatedStringTlv((short)0x0001, null, "ISO-8859-1");
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("00"), tlv0.getValue());

        tlv0 = TlvUtil.createNullTerminatedStringTlv((short)0x0001, "", "ISO-8859-1");
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("00"), tlv0.getValue());

        tlv0 = TlvUtil.createNullTerminatedStringTlv((short)0x0001, "a");
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("6100"), tlv0.getValue());

        tlv0 = TlvUtil.createNullTerminatedStringTlv((short)0x0001, "c1net");
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("63316e657400"), tlv0.getValue());
    }
View Full Code Here

        Assert.assertArrayEquals(HexUtil.toByteArray("63316e657400"), tlv0.getValue());
    }

    @Test
    public void createFixedLengthStringTlv() throws Exception {
        Tlv tlv0 = null;

        tlv0 = TlvUtil.createFixedLengthStringTlv((short)0x0001, null, 2, "ISO-8859-1");
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("0000"), tlv0.getValue());

        tlv0 = TlvUtil.createFixedLengthStringTlv((short)0x0001, "", 2);
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("0000"), tlv0.getValue());

        tlv0 = TlvUtil.createFixedLengthStringTlv((short)0x0001, "1", 2, "ISO-8859-1");
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("3100"), tlv0.getValue());

        tlv0 = TlvUtil.createFixedLengthStringTlv((short)0x0001, "12", 2);
        Assert.assertEquals((short)0x0001, tlv0.getTag());
        Assert.assertArrayEquals(HexUtil.toByteArray("3132"), tlv0.getValue());

        try {
            tlv0 = TlvUtil.createFixedLengthStringTlv((short)0x0001, "12", 1, "ISO-8859-1");
            Assert.fail();
        } catch (TlvConvertException e) {
View Full Code Here

        Assert.assertEquals(235874, pdu0.getSequenceNumber());
        Assert.assertEquals(true, pdu0.isResponse());
        Assert.assertEquals("twitter", pdu0.getSystemId());
        Assert.assertEquals(1, pdu0.getOptionalParameters().size());
        Assert.assertEquals(true, pdu0.hasOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION));
        Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION);
        Assert.assertEquals(SmppConstants.TAG_SC_INTERFACE_VERSION, tlv0.getTag());
        Assert.assertEquals(1, tlv0.getLength());
        Assert.assertArrayEquals(new byte[] { (byte)0x34 }, tlv0.getValue());

        // interesting -- this example has optional parameters it happened to skip...
        Assert.assertEquals(0, buffer.readableBytes());
    }
View Full Code Here

        Assert.assertEquals(0x00, pdu0.getDefaultMsgId());
        Assert.assertEquals(8, pdu0.getShortMessage().length);
        Assert.assertArrayEquals(HexUtil.toByteArray("4024232125262f3a"), pdu0.getShortMessage());

        Assert.assertEquals(2, pdu0.getOptionalParameters().size());
        Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SOURCE_NETWORK_TYPE);
        Assert.assertEquals(0x01, tlv0.getValueAsByte());
        Tlv tlv1 = pdu0.getOptionalParameter(SmppConstants.TAG_DEST_NETWORK_TYPE);
        Assert.assertEquals(0x01, tlv1.getValueAsByte());

        // interesting -- this example has optional parameters it happened to skip...
        Assert.assertEquals(0, buffer.readableBytes());
    }
View Full Code Here

        Assert.assertEquals(0x00, pdu0.getDefaultMsgId());
        Assert.assertEquals(110, pdu0.getShortMessage().length);
        Assert.assertArrayEquals(HexUtil.toByteArray("69643a30303539313133393738207375623a30303120646c7672643a303031207375626d697420646174653a3130303231303137333020646f6e6520646174653a3130303231303137333120737461743a44454c49565244206572723a30303020746578743a4024232125262f3a"), pdu0.getShortMessage());

        Assert.assertEquals(4, pdu0.getOptionalParameters().size());
        Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SOURCE_NETWORK_TYPE);
        Assert.assertEquals(0x01, tlv0.getValueAsByte());
        Tlv tlv1 = pdu0.getOptionalParameter(SmppConstants.TAG_DEST_NETWORK_TYPE);
        Assert.assertEquals(0x01, tlv1.getValueAsByte());
        Tlv tlv2 = pdu0.getOptionalParameter(SmppConstants.TAG_RECEIPTED_MSG_ID);
        Assert.assertEquals("38601fa", tlv2.getValueAsString());
        Tlv tlv3 = pdu0.getOptionalParameter(SmppConstants.TAG_MSG_STATE);
        Assert.assertEquals(SmppConstants.STATE_DELIVERED, tlv3.getValueAsByte());

        // interesting -- this example has optional parameters it happened to skip...
        Assert.assertEquals(0, buffer.readableBytes());
    }
View Full Code Here

TOP

Related Classes of com.cloudhopper.smpp.tlv.Tlv

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.