Search in sources :

Example 1 with SgipSubmitResponseMessage

use of com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage in project SMSGate by Lihuanghe.

the class SGIPMessageReceiveHandler method reponse.

@Override
protected ChannelFuture reponse(final ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof SgipDeliverRequestMessage) {
        SgipDeliverRequestMessage deli = (SgipDeliverRequestMessage) msg;
        SgipDeliverResponseMessage resp = new SgipDeliverResponseMessage(deli.getHeader());
        resp.setResult((short) 0);
        resp.setTimestamp(deli.getTimestamp());
        List<SgipDeliverRequestMessage> deliarr = deli.getFragments();
        if (deliarr != null) {
            for (SgipDeliverRequestMessage item : deliarr) {
                SgipDeliverResponseMessage item_resp = new SgipDeliverResponseMessage(item.getHeader());
                item_resp.setResult((short) 0);
                item_resp.setTimestamp(item.getTimestamp());
                ctx.writeAndFlush(item_resp);
            }
        }
        return ctx.writeAndFlush(resp);
    } else if (msg instanceof SgipSubmitRequestMessage) {
        SgipSubmitRequestMessage submit = (SgipSubmitRequestMessage) msg;
        SgipSubmitResponseMessage resp = new SgipSubmitResponseMessage(submit.getHeader());
        resp.setTimestamp(submit.getTimestamp());
        resp.setResult((short) 0);
        boolean sendreport = 1 == submit.getReportflag();
        List<SgipSubmitRequestMessage> deliarr = submit.getFragments();
        if (deliarr != null) {
            for (SgipSubmitRequestMessage item : deliarr) {
                SgipSubmitResponseMessage item_resp = new SgipSubmitResponseMessage(item.getHeader());
                item_resp.setResult((short) 0);
                item_resp.setTimestamp(item.getTimestamp());
                ctx.writeAndFlush(item_resp);
                if (sendreport) {
                    SgipReportRequestMessage report = new SgipReportRequestMessage();
                    report.setSequenceId(item_resp.getSequenceNumber());
                    ctx.writeAndFlush(report);
                }
            }
        }
        ChannelFuture future = ctx.writeAndFlush(resp);
        if (sendreport) {
            SgipReportRequestMessage report = new SgipReportRequestMessage();
            report.setSequenceId(resp.getSequenceNumber());
            ctx.writeAndFlush(report);
        }
        return future;
    }
    return null;
}
Also used : SgipDeliverRequestMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage) ChannelFuture(io.netty.channel.ChannelFuture) SgipReportRequestMessage(com.zx.sms.codec.sgip12.msg.SgipReportRequestMessage) SgipSubmitRequestMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage) SgipSubmitResponseMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage) List(java.util.List) SgipDeliverResponseMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverResponseMessage)

Example 2 with SgipSubmitResponseMessage

use of com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage in project SMSGate by Lihuanghe.

the class SgipSubmitResponseMessageCodec 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;
    }
    SgipSubmitResponseMessage responseMessage = new SgipSubmitResponseMessage(msg.getHeader());
    responseMessage.setTimestamp(msg.getTimestamp());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    responseMessage.setResult(bodyBuffer.readUnsignedByte());
    responseMessage.setReserve(bodyBuffer.readCharSequence(SgipSubmitResponse.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(responseMessage);
}
Also used : SgipSubmitResponseMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

SgipSubmitResponseMessage (com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage)2 SgipDeliverRequestMessage (com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage)1 SgipDeliverResponseMessage (com.zx.sms.codec.sgip12.msg.SgipDeliverResponseMessage)1 SgipReportRequestMessage (com.zx.sms.codec.sgip12.msg.SgipReportRequestMessage)1 SgipSubmitRequestMessage (com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1 List (java.util.List)1