Search in sources :

Example 1 with CmppQueryRequestMessage

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

the class CMPPSessionConnectedHandler method channelRead.

public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof CmppDeliverRequestMessage) {
        CmppDeliverRequestMessage e = (CmppDeliverRequestMessage) msg;
        if (e.getFragments() != null) {
            // 长短信会带有片断
            for (CmppDeliverRequestMessage frag : e.getFragments()) {
                CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(frag.getHeader().getSequenceId());
                responseMessage.setResult(0);
                responseMessage.setMsgId(frag.getMsgId());
                ctx.channel().write(responseMessage);
            }
        }
        CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(e.getHeader().getSequenceId());
        responseMessage.setResult(0);
        responseMessage.setMsgId(e.getMsgId());
        ctx.channel().writeAndFlush(responseMessage);
    } else if (msg instanceof CmppDeliverResponseMessage) {
        CmppDeliverResponseMessage e = (CmppDeliverResponseMessage) msg;
    } else if (msg instanceof CmppSubmitRequestMessage) {
        // 接收到 CmppSubmitRequestMessage 消息
        CmppSubmitRequestMessage e = (CmppSubmitRequestMessage) msg;
        final List<CmppDeliverRequestMessage> reportlist = new ArrayList<CmppDeliverRequestMessage>();
        if (e.getFragments() != null) {
            // 长短信会可能带有片断,每个片断都要回复一个response
            for (CmppSubmitRequestMessage frag : e.getFragments()) {
                CmppSubmitResponseMessage responseMessage = new CmppSubmitResponseMessage(frag.getHeader().getSequenceId());
                responseMessage.setResult(0);
                ctx.channel().write(responseMessage);
                CmppDeliverRequestMessage deliver = new CmppDeliverRequestMessage();
                deliver.setDestId(e.getSrcId());
                deliver.setSrcterminalId(e.getDestterminalId()[0]);
                CmppReportRequestMessage report = new CmppReportRequestMessage();
                report.setDestterminalId(deliver.getSrcterminalId());
                report.setMsgId(responseMessage.getMsgId());
                String t = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyMMddHHmm");
                report.setSubmitTime(t);
                report.setDoneTime(t);
                report.setStat("DELIVRD");
                report.setSmscSequence(0);
                deliver.setReportRequestMessage(report);
                reportlist.add(deliver);
            }
        }
        final CmppSubmitResponseMessage resp = new CmppSubmitResponseMessage(e.getHeader().getSequenceId());
        resp.setResult(0);
        ctx.channel().writeAndFlush(resp);
        // 回复状态报告
        if (e.getRegisteredDelivery() == 1) {
            final CmppDeliverRequestMessage deliver = new CmppDeliverRequestMessage();
            deliver.setDestId(e.getSrcId());
            deliver.setSrcterminalId(e.getDestterminalId()[0]);
            CmppReportRequestMessage report = new CmppReportRequestMessage();
            report.setDestterminalId(deliver.getSrcterminalId());
            report.setMsgId(resp.getMsgId());
            String t = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyMMddHHmm");
            report.setSubmitTime(t);
            report.setDoneTime(t);
            report.setStat("DELIVRD");
            report.setSmscSequence(0);
            deliver.setReportRequestMessage(report);
            reportlist.add(deliver);
            ctx.executor().submit(new Runnable() {

                public void run() {
                    for (CmppDeliverRequestMessage t : reportlist) ctx.channel().writeAndFlush(t);
                }
            });
        }
    } else if (msg instanceof CmppSubmitResponseMessage) {
        CmppSubmitResponseMessage e = (CmppSubmitResponseMessage) msg;
    } else if (msg instanceof CmppQueryRequestMessage) {
        CmppQueryRequestMessage e = (CmppQueryRequestMessage) msg;
        CmppQueryResponseMessage res = new CmppQueryResponseMessage(e.getHeader().getSequenceId());
        ctx.channel().writeAndFlush(res);
    } else {
        ctx.fireChannelRead(msg);
    }
}
Also used : CmppQueryRequestMessage(com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage) CmppQueryResponseMessage(com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage) CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppDeliverResponseMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage) ArrayList(java.util.ArrayList) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Example 2 with CmppQueryRequestMessage

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

the class CmppQueryRequestMessageCodec 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;
    }
    CmppQueryRequestMessage requestMessage = new CmppQueryRequestMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setTime(bodyBuffer.readCharSequence(CmppQueryRequest.TIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setQueryType(bodyBuffer.readUnsignedByte());
    requestMessage.setQueryCode(bodyBuffer.readCharSequence(CmppQueryRequest.QUERYCODE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setReserve(bodyBuffer.readCharSequence(CmppQueryRequest.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(requestMessage);
}
Also used : CmppQueryRequestMessage(com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with CmppQueryRequestMessage

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

the class CMPPResponseSenderHandler method channelRead.

@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
    // 此时未经过长短信合并
    if (msg instanceof CmppDeliverRequestMessage) {
        CmppDeliverRequestMessage e = (CmppDeliverRequestMessage) msg;
        CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(e.getHeader().getSequenceId());
        responseMessage.setResult(0);
        responseMessage.setMsgId(e.getMsgId());
        ctx.channel().writeAndFlush(responseMessage);
    } else if (msg instanceof CmppSubmitRequestMessage) {
        CmppSubmitRequestMessage e = (CmppSubmitRequestMessage) msg;
        CmppSubmitResponseMessage resp = new CmppSubmitResponseMessage(e.getHeader().getSequenceId());
        resp.setResult(0);
        ctx.channel().writeAndFlush(resp);
        if (e.getRegisteredDelivery() == 1) {
            final CmppDeliverRequestMessage deliver = new CmppDeliverRequestMessage();
            deliver.setDestId(e.getSrcId());
            deliver.setSrcterminalId(e.getDestterminalId()[0]);
            CmppReportRequestMessage report = new CmppReportRequestMessage();
            report.setDestterminalId(deliver.getSrcterminalId());
            report.setMsgId(resp.getMsgId());
            String t = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyMMddHHmm");
            report.setSubmitTime(t);
            report.setDoneTime(t);
            report.setStat("DELIVRD");
            report.setSmscSequence(0);
            deliver.setReportRequestMessage(report);
            ctx.executor().submit(new Runnable() {

                public void run() {
                    ctx.channel().writeAndFlush(deliver);
                }
            });
        }
    } else if (msg instanceof CmppQueryRequestMessage) {
        CmppQueryRequestMessage e = (CmppQueryRequestMessage) msg;
        CmppQueryResponseMessage res = new CmppQueryResponseMessage(e.getHeader().getSequenceId());
        ctx.channel().writeAndFlush(res);
    }
    ctx.fireChannelRead(msg);
}
Also used : CmppQueryRequestMessage(com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage) CmppQueryResponseMessage(com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage) CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppDeliverResponseMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Example 4 with CmppQueryRequestMessage

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

the class TestCmppQueryRequestMessageCodec method testCodec.

@Test
public void testCodec() {
    CmppQueryRequestMessage msg = new CmppQueryRequestMessage();
    msg.setQueryCode("sdf");
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    int expectLength = CmppQueryRequest.QUERYCODE.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());
    CmppQueryRequestMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getQueryCode(), result.getQueryCode());
}
Also used : CmppQueryRequestMessage(com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

CmppQueryRequestMessage (com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage)4 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)2 CmppDeliverResponseMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage)2 CmppQueryResponseMessage (com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage)2 CmppReportRequestMessage (com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage)2 CmppSubmitRequestMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)2 CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)2 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1