Search in sources :

Example 1 with SgipBindResponseMessage

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

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

Example 2 with SgipBindResponseMessage

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

the class SgipSessionLoginManager method doLoginSuccess.

@Override
protected void doLoginSuccess(ChannelHandlerContext ctx, EndpointEntity entity, Object message) {
    // 发送bind请求
    SgipEndpointEntity sgipentity = (SgipEndpointEntity) entity;
    SgipBindResponseMessage resp = new SgipBindResponseMessage(((Message) message).getHeader());
    resp.setResult((short) 0);
    resp.setTimestamp(((Message) message).getTimestamp());
    ctx.channel().writeAndFlush(resp);
}
Also used : SgipBindResponseMessage(com.zx.sms.codec.sgip12.msg.SgipBindResponseMessage) SgipEndpointEntity(com.zx.sms.connect.manager.sgip.SgipEndpointEntity)

Example 3 with SgipBindResponseMessage

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

the class SgipSessionLoginManager method failedLogin.

@Override
protected void failedLogin(ChannelHandlerContext ctx, Object msg, long status) {
    if (msg instanceof SgipBindRequestMessage) {
        logger.error("Connected error status :{},msg : {}", status, msg);
        SgipBindRequestMessage message = (SgipBindRequestMessage) msg;
        // 认证失败
        SgipBindResponseMessage resp = new SgipBindResponseMessage(((Message) message).getHeader());
        resp.setResult((short) status);
        resp.setTimestamp(((Message) message).getTimestamp());
        ChannelFuture promise = ctx.writeAndFlush(resp);
        final ChannelHandlerContext finalctx = ctx;
        promise.addListener(new GenericFutureListener() {

            public void operationComplete(Future future) throws Exception {
                finalctx.close();
            }
        });
    } else {
        logger.error("connect msg type error : {}", msg);
        ctx.close();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) SgipBindResponseMessage(com.zx.sms.codec.sgip12.msg.SgipBindResponseMessage) SgipBindRequestMessage(com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Aggregations

SgipBindResponseMessage (com.zx.sms.codec.sgip12.msg.SgipBindResponseMessage)3 SgipBindRequestMessage (com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage)1 SgipEndpointEntity (com.zx.sms.connect.manager.sgip.SgipEndpointEntity)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1