Search in sources :

Example 1 with SMGPDeliverMessage

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

the class SMGPSessionConnectedHandler method createTestReq.

@Override
protected BaseMessage createTestReq(String content) {
    final EndpointEntity finalentity = getEndpointEntity();
    if (finalentity instanceof ServerEndpoint) {
        SMGPDeliverMessage pdu = new SMGPDeliverMessage();
        pdu.setDestTermId("10086");
        pdu.setMsgContent(content);
        pdu.setSrcTermId("13800138000");
        return pdu;
    } else {
        SMGPSubmitMessage pdu = new SMGPSubmitMessage();
        pdu.setSrcTermId("10086");
        pdu.setDestTermIdArray("13800138000");
        pdu.setMsgContent(content);
        return pdu;
    }
}
Also used : SMGPDeliverMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverMessage) SMGPSubmitMessage(com.zx.sms.codec.smgp.msg.SMGPSubmitMessage) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint) EndpointEntity(com.zx.sms.connect.manager.EndpointEntity)

Example 2 with SMGPDeliverMessage

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

the class TestSMGPDeliverMessage method testlongCodec.

public void testlongCodec(SMGPDeliverMessage msg) {
    channel().writeOutbound(msg);
    ByteBuf buf = (ByteBuf) channel().readOutbound();
    ByteBuf copybuf = Unpooled.buffer();
    while (buf != null) {
        copybuf.writeBytes(buf.copy());
        int length = buf.readableBytes();
        Assert.assertEquals(length, buf.readInt());
        Assert.assertEquals(msg.getCommandId(), buf.readInt());
        buf = (ByteBuf) channel().readOutbound();
    }
    SMGPDeliverMessage result = decode(copybuf);
    Assert.assertNotNull(result);
    System.out.println(result);
    if (msg.isReport()) {
        Assert.assertEquals(msg.getReport().getStat(), result.getReport().getStat());
    } else {
        Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
        Assert.assertEquals(msg.getSrcTermId(), result.getSrcTermId());
        Assert.assertEquals(msg.getDestTermId(), result.getDestTermId());
        Assert.assertEquals(msg.getRecvTime(), result.getRecvTime());
    }
    Assert.assertEquals(msg.getSrcTermId(), result.getSrcTermId());
}
Also used : SMGPDeliverMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with SMGPDeliverMessage

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

the class TestSMGPDeliverMessage method test2.

@Test
public void test2() {
    SMGPDeliverMessage msg = new SMGPDeliverMessage();
    msg.setDestTermId("13800138000");
    msg.setLinkId("1023rsd");
    msg.setMsgContent("第一种:通过注解@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作,第一种:通过注解@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作");
    msg.setMsgId(new MsgId());
    msg.setSrcTermId("10086988");
    testlongCodec(msg);
}
Also used : SMGPDeliverMessage(com.zx.sms.codec.smgp.msg.SMGPDeliverMessage) MsgId(com.zx.sms.codec.smgp.msg.MsgId) Test(org.junit.Test)

Example 4 with SMGPDeliverMessage

use of com.zx.sms.codec.smgp.msg.SMGPDeliverMessage 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 5 with SMGPDeliverMessage

use of com.zx.sms.codec.smgp.msg.SMGPDeliverMessage 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)

Aggregations

SMGPDeliverMessage (com.zx.sms.codec.smgp.msg.SMGPDeliverMessage)8 MsgId (com.zx.sms.codec.smgp.msg.MsgId)4 Test (org.junit.Test)4 SMGPSubmitMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)3 SMGPDeliverRespMessage (com.zx.sms.codec.smgp.msg.SMGPDeliverRespMessage)2 SMGPSubmitRespMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitRespMessage)2 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 SMGPReportData (com.zx.sms.codec.smgp.msg.SMGPReportData)1 SMGPUnknownMessage (com.zx.sms.codec.smgp.msg.SMGPUnknownMessage)1 EndpointEntity (com.zx.sms.connect.manager.EndpointEntity)1 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1 ByteBuf (io.netty.buffer.ByteBuf)1