use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage in project SMSGate by Lihuanghe.
the class Cmpp20DeliverResponseMessageCodec 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;
}
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(msg.getHeader());
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
responseMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, Cmpp20DeliverResponse.MSGID.getLength())));
responseMessage.setResult(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
}
use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage in project SMSGate by Lihuanghe.
the class TestCmpp20DeliverResponseMessageCodec method testCode.
@Test
public void testCode() {
CmppDeliverResponseMessage msg = new CmppDeliverResponseMessage(238);
msg.setMsgId(new MsgId());
msg.setResult(3413);
ByteBuf buf = encode(msg);
ByteBuf copybuf = buf.copy();
int length = buf.readableBytes();
int expectLength = Cmpp20DeliverResponse.RESULT.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());
CmppDeliverResponseMessage result = decode(copybuf);
Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
Assert.assertEquals(msg.getMsgId(), result.getMsgId());
Assert.assertEquals(msg.getResult() & 0xff, result.getResult());
}
use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage in project SMSGate by Lihuanghe.
the class TestCmppDeliverResponseMessageCodec method testCode.
@Test
public void testCode() {
CmppDeliverResponseMessage msg = new CmppDeliverResponseMessage(238);
msg.setMsgId(new MsgId());
msg.setResult(3);
ByteBuf buf = encode(msg);
ByteBuf copybuf = buf.copy();
int length = buf.readableBytes();
int expectLength = (getVersion() == 0x30 ? CmppDeliverResponse.MSGID.getBodyLength() : Cmpp20DeliverResponse.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());
CmppDeliverResponseMessage result = decode(copybuf);
Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
Assert.assertEquals(msg.getMsgId(), result.getMsgId());
Assert.assertEquals(msg.getResult(), result.getResult());
}
use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage in project SMSGate by Lihuanghe.
the class CMPPDeliverLongMessageHandler method response.
@Override
protected BaseMessage response(CmppDeliverRequestMessage msg) {
// 短信片断未接收完全,直接给网关回复resp,等待其它片断
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(msg.getHeader());
responseMessage.setResult(0);
return responseMessage;
}
use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage 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);
}
}
Aggregations