use of com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage in project SMSGate by Lihuanghe.
the class CmppTerminateResponseMessageCodec 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;
}
;
CmppTerminateResponseMessage responseMessage = new CmppTerminateResponseMessage(msg.getHeader());
out.add(responseMessage);
}
use of com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage in project SMSGate by Lihuanghe.
the class CmppTerminateRequestMessageHandler method channelRead0.
/*
* (non-Javadoc)
*
* @see
* org.jboss.netty.channel.SimpleChannelUpstreamHandler#messageReceived(
* org.jboss.netty.channel.ChannelHandlerContext,
* org.jboss.netty.channel.MessageEvent)
*/
@Override
public void channelRead0(final ChannelHandlerContext ctx, CmppTerminateRequestMessage e) throws Exception {
CmppTerminateResponseMessage responseMessage = new CmppTerminateResponseMessage(e.getHeader().getSequenceId());
ChannelFuture future = ctx.channel().writeAndFlush(responseMessage);
final ChannelHandlerContext finalctx = ctx;
future.addListeners(new GenericFutureListener() {
@Override
public void operationComplete(Future future) throws Exception {
ctx.executor().schedule(new Runnable() {
@Override
public void run() {
finalctx.channel().close();
}
}, 500, TimeUnit.MILLISECONDS);
}
});
}
use of com.zx.sms.codec.cmpp.msg.CmppTerminateResponseMessage in project SMSGate by Lihuanghe.
the class TestCmppTerminateResponseMessageCodec method testCodec.
@Test
public void testCodec() {
CmppTerminateResponseMessage msg = new CmppTerminateResponseMessage(1);
ByteBuf buf = encode(msg);
ByteBuf copybuf = buf.copy();
Assert.assertEquals(12, buf.readableBytes());
Assert.assertEquals(12, buf.readInt());
Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
CmppTerminateResponseMessage result = decode(copybuf);
Assert.assertTrue(result instanceof CmppTerminateResponseMessage);
Assert.assertEquals(msg.getHeader().getSequenceId(), ((CmppTerminateResponseMessage) result).getHeader().getSequenceId());
}
Aggregations