Search in sources :

Example 1 with CmppSubmitResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project SMSGate by Lihuanghe.

the class CmppSubmitResponseMessageCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
    int commandId = msg.getHeader().getCommandId();
    if (packetType.getCommandId() != commandId) {
        // 不解析,交给下一个codec
        out.add(msg);
        return;
    }
    CmppSubmitResponseMessage responseMessage = new CmppSubmitResponseMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    responseMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppSubmitResponse.MSGID.getLength())));
    responseMessage.setResult(bodyBuffer.readUnsignedInt());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(responseMessage);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Example 2 with CmppSubmitResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project SMSGate by Lihuanghe.

the class Cmpp20SubmitResponseMessageCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
    int commandId = msg.getHeader().getCommandId();
    if (packetType.getCommandId() != commandId) {
        // 不解析,交给下一个codec
        out.add(msg);
        return;
    }
    CmppSubmitResponseMessage responseMessage = new CmppSubmitResponseMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    responseMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, Cmpp20SubmitResponse.MSGID.getLength())));
    responseMessage.setResult(bodyBuffer.readUnsignedByte());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(responseMessage);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Example 3 with CmppSubmitResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project SMSGate by Lihuanghe.

the class TestCmpp20SubmitResponseMessageCodec method testCode.

@Test
public void testCode() {
    CmppSubmitResponseMessage msg = new CmppSubmitResponseMessage(238);
    msg.setMsgId(new MsgId());
    msg.setResult(3413);
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    int expectLength = Cmpp20SubmitResponse.MSGID.getBodyLength() + CmppHead.COMMANDID.getHeadLength();
    Assert.assertEquals(expectLength, length);
    Assert.assertEquals(expectLength, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppSubmitResponseMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getMsgId(), result.getMsgId());
    Assert.assertEquals(msg.getResult() & 0xff, result.getResult());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage) MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 4 with CmppSubmitResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project SMSGate by Lihuanghe.

the class TestCmppSubmitResponseMessageCodec method testCode.

@Test
public void testCode() {
    CmppSubmitResponseMessage msg = new CmppSubmitResponseMessage(238);
    msg.setMsgId(new MsgId());
    msg.setResult(3413 & 0xff);
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    int expectLength = (getVersion() == 0x30 ? CmppSubmitResponse.MSGID.getBodyLength() : Cmpp20SubmitResponse.MSGID.getBodyLength()) + CmppHead.COMMANDID.getHeadLength();
    Assert.assertEquals(expectLength, length);
    Assert.assertEquals(expectLength, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppSubmitResponseMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getMsgId(), result.getMsgId());
    Assert.assertEquals(msg.getResult(), result.getResult());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage) MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 5 with CmppSubmitResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project SMSGate by Lihuanghe.

the class CMPPSubmitLongMessageHandler method response.

@Override
protected BaseMessage response(CmppSubmitRequestMessage msg) {
    // 短信片断未接收完全,直接给网关回复resp,等待其它片断
    CmppSubmitResponseMessage responseMessage = new CmppSubmitResponseMessage(msg.getHeader());
    responseMessage.setResult(0);
    return responseMessage;
}
Also used : CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Aggregations

CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)9 ByteBuf (io.netty.buffer.ByteBuf)5 CmppSubmitRequestMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)3 MsgId (com.zx.sms.common.util.MsgId)3 Test (org.junit.Test)3 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)2 CmppDeliverResponseMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage)2 CmppQueryRequestMessage (com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage)2 CmppQueryResponseMessage (com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage)2 CmppReportRequestMessage (com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage)2 SMGPSubmitMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)1 SessionStateManager (com.zx.sms.session.cmpp.SessionStateManager)1 ArrayList (java.util.ArrayList)1