Search in sources :

Example 6 with SMGPSubmitMessage

use of com.zx.sms.codec.smgp.msg.SMGPSubmitMessage in project SMSGate by Lihuanghe.

the class SMGPMessageCodec method fromBytes.

private SMGPBaseMessage fromBytes(byte[] bytes) throws Exception {
    if (bytes == null) {
        return null;
    }
    if (bytes.length < SMGPBaseMessage.SZ_HEADER) {
        return null;
    }
    int commandLength = ByteUtil.byte2int(bytes, 0);
    assert bytes.length == commandLength;
    int commandId = ByteUtil.byte2int(bytes, 4);
    SMGPBaseMessage baseMsg = null;
    switch(commandId) {
        case SMGPConstants.SMGP_LOGIN:
            baseMsg = new SMGPLoginMessage();
            break;
        case SMGPConstants.SMGP_LOGIN_RESP:
            baseMsg = new SMGPLoginRespMessage();
            break;
        case SMGPConstants.SMGP_SUBMIT:
            baseMsg = new SMGPSubmitMessage();
            break;
        case SMGPConstants.SMGP_SUBMIT_RESP:
            baseMsg = new SMGPSubmitRespMessage();
            break;
        case SMGPConstants.SMGP_DELIVER:
            baseMsg = new SMGPDeliverMessage();
            break;
        case SMGPConstants.SMGP_DELIVER_RESP:
            baseMsg = new SMGPDeliverRespMessage();
            break;
        case SMGPConstants.SMGP_ACTIVE_TEST:
            baseMsg = new SMGPActiveTestMessage();
            break;
        case SMGPConstants.SMGP_ACTIVE_TEST_RESP:
            baseMsg = new SMGPActiveTestRespMessage();
            break;
        case SMGPConstants.SMGP_EXIT_TEST:
            baseMsg = new SMGPExitMessage();
            break;
        case SMGPConstants.SMGP_EXIT_RESP:
            baseMsg = new SMGPExitRespMessage();
            break;
        default:
            baseMsg = new SMGPUnknownMessage(commandId);
            break;
    }
    baseMsg.fromBytes(bytes, version);
    return baseMsg;
}
Also used : SMGPDeliverMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverMessage) SMGPExitMessage(com.zx.sms.codec.smgp.msg.SMGPExitMessage) SMGPBaseMessage(com.zx.sms.codec.smgp.msg.SMGPBaseMessage) SMGPDeliverRespMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverRespMessage) SMGPLoginMessage(com.zx.sms.codec.smgp.msg.SMGPLoginMessage) SMGPActiveTestRespMessage(com.zx.sms.codec.smgp.msg.SMGPActiveTestRespMessage) SMGPUnknownMessage(com.zx.sms.codec.smgp.msg.SMGPUnknownMessage) SMGPExitRespMessage(com.zx.sms.codec.smgp.msg.SMGPExitRespMessage) SMGPLoginRespMessage(com.zx.sms.codec.smgp.msg.SMGPLoginRespMessage) SMGPSubmitRespMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitRespMessage) SMGPActiveTestMessage(com.zx.sms.codec.smgp.msg.SMGPActiveTestMessage) SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)

Example 7 with SMGPSubmitMessage

use of com.zx.sms.codec.smgp.msg.SMGPSubmitMessage in project SMSGate by Lihuanghe.

the class SMGPMessageReceiveHandler method reponse.

@Override
protected ChannelFuture reponse(final ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof SMGPDeliverMessage) {
        SMGPDeliverRespMessage resp = new SMGPDeliverRespMessage();
        resp.setSequenceNo(((SMGPDeliverMessage) msg).getSequenceNo());
        resp.setMsgId(((SMGPDeliverMessage) msg).getMsgId());
        resp.setStatus(0);
        return ctx.writeAndFlush(resp);
    } else if (msg instanceof SMGPSubmitMessage) {
        SMGPSubmitRespMessage resp = new SMGPSubmitRespMessage();
        resp.setSequenceNo(((SMGPSubmitMessage) msg).getSequenceNo());
        resp.setStatus(0);
        return ctx.writeAndFlush(resp);
    }
    return null;
}
Also used : SMGPDeliverMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverMessage) SMGPDeliverRespMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverRespMessage) SMGPSubmitRespMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitRespMessage) SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)

Example 8 with SMGPSubmitMessage

use of com.zx.sms.codec.smgp.msg.SMGPSubmitMessage in project SMSGate by Lihuanghe.

the class TestSMGPSubmitMessage method test1.

@Test
public void test1() {
    SMGPSubmitMessage msg = new SMGPSubmitMessage();
    msg.setDestTermIdArray(new String[] { "13800138000", "13800138001", "13800138002", "13800138003" });
    msg.setLinkId("1023rsd");
    msg.setMsgContent("第一种:通过注解@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作");
    msg.setSrcTermId("10086988");
    msg.setMsgSrc("901988");
    test0(msg);
}
Also used : SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage) Test(org.junit.Test)

Example 9 with SMGPSubmitMessage

use of com.zx.sms.codec.smgp.msg.SMGPSubmitMessage in project SMSGate by Lihuanghe.

the class TestSMGPSubmitMessage method testuUnknowTLV.

@Test
public // 网络反馈的一个报错的smgp报文
void testuUnknowTLV() throws DecoderException, org.apache.commons.codec.DecoderException {
    // byte[] arr = Hex.decodeHex("000000e6000000021b46734c0601020000000000000000000030303030303030300000000000000000000000000000000000000000000000000000000000000000000000313030383600000000000000000000000000000000000000000000000000000000000000000000000000013133383030313338303030000000000000000000002464666138656236612d616439662d343635342d393466612d6631313437313865643035610000000000000000000100010000020001000004000100000500010000070001000009000101000a000101000b000100000c0001000012000441424300".toCharArray());
    byte[] arr = Hex.decodeHex("000000eb000000021b46734c0601020000000000000000000030303030303030300000000000000000000000000000000000000000000000000000000000000000000000313030383600000000000000000000000000000000000000000000000000000000000000000000000000013133383030313338303030000000000000000000002464666138656236612d616439662d343635342d393466612d66313134373138656430356100000000000000000001000100000200010000040001000005000100001400010100070001000009000101000a000101000b000100000c0001000012000441424300".toCharArray());
    ByteBuf data = Unpooled.wrappedBuffer(arr);
    try {
        SMGPSubmitMessage result = new SMGPSubmitMessage();
        result.fromBytes(arr, 0x13);
        Assert.assertEquals("ABC", result.getMServiceId());
    } catch (Exception ex) {
        Assert.assertTrue(ex instanceof DecoderException);
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage) ByteBuf(io.netty.buffer.ByteBuf) DecoderException(io.netty.handler.codec.DecoderException) Test(org.junit.Test)

Example 10 with SMGPSubmitMessage

use of com.zx.sms.codec.smgp.msg.SMGPSubmitMessage in project SMSGate by Lihuanghe.

the class TestSMGPSubmitMessage method test0.

private void test0(SMGPSubmitMessage msg) {
    System.out.println(msg);
    ByteBuf buf = encode(msg);
    ByteBuf newbuf = buf.copy();
    int length = buf.readableBytes();
    buf.release();
    SMGPSubmitMessage result = decode(newbuf);
    System.out.println(result);
    Assert.assertEquals(msg.getSequenceNo(), result.getSequenceNo());
    Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
    Assert.assertEquals(msg.getSrcTermId(), result.getSrcTermId());
    Assert.assertArrayEquals(msg.getDestTermIdArray(), result.getDestTermIdArray());
    Assert.assertEquals(msg.getSrcTermId(), result.getSrcTermId());
}
Also used : SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

SMGPSubmitMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)10 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)4 SMGPDeliverMessage (com.zx.sms.codec.smgp.msg.SMGPDeliverMessage)3 SMGPDeliverRespMessage (com.zx.sms.codec.smgp.msg.SMGPDeliverRespMessage)2 SMGPSubmitRespMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitRespMessage)2 DecoderException (io.netty.handler.codec.DecoderException)2 CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)1 SMGPActiveTestMessage (com.zx.sms.codec.smgp.msg.SMGPActiveTestMessage)1 SMGPActiveTestRespMessage (com.zx.sms.codec.smgp.msg.SMGPActiveTestRespMessage)1 SMGPBaseMessage (com.zx.sms.codec.smgp.msg.SMGPBaseMessage)1 SMGPExitMessage (com.zx.sms.codec.smgp.msg.SMGPExitMessage)1 SMGPExitRespMessage (com.zx.sms.codec.smgp.msg.SMGPExitRespMessage)1 SMGPLoginMessage (com.zx.sms.codec.smgp.msg.SMGPLoginMessage)1 SMGPLoginRespMessage (com.zx.sms.codec.smgp.msg.SMGPLoginRespMessage)1 SMGPUnknownMessage (com.zx.sms.codec.smgp.msg.SMGPUnknownMessage)1 MsgId (com.zx.sms.common.util.MsgId)1 EndpointEntity (com.zx.sms.connect.manager.EndpointEntity)1 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1