use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage 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);
}
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project SMSGate by Lihuanghe.
the class TestSpeedError method test.
@Test
public void test() throws InterruptedException {
SessionStateManager sessionhandler = (SessionStateManager) ch.pipeline().get("session");
// 测试超速错误的重发机制
CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
msg.setDestterminalId(new String[] { "13800138000" });
msg.setLinkID("0000");
msg.setMsgContent("123");
msg.setServiceId("10086");
msg.setSrcId("10086");
ch.writeOutbound(msg);
// 等待重发
Thread.sleep((reSendTime + 1) * 1000);
// 一共发送了2条MT消息
Assert.assertEquals(2, sessionhandler.getWriteCount());
// 有一条等待发送的消息
Assert.assertEquals(1, sessionhandler.getWaittingResp());
ByteBuf recvMsg = ch.readOutbound();
Assert.assertNotNull(recvMsg);
// 新为上面等待超时,会重发一次,所以这里会收到两条
recvMsg = ch.readOutbound();
Assert.assertNotNull(recvMsg);
// 回复一条超速错误
CmppSubmitResponseMessage resp = new CmppSubmitResponseMessage(msg.getHeader().getSequenceId());
resp.setResult(8L);
// 把resp转化为ByteBuf
ch.writeOutbound(resp);
ch.writeInbound(ch.readOutbound());
Thread.sleep((reSendTime + 2) * 1000);
// 一共发送了3条MT消息
Assert.assertEquals(3, sessionhandler.getWriteCount());
// 收到超速错,会再次重发一次
recvMsg = ch.readOutbound();
Assert.assertNotNull(recvMsg);
// 回复一条正确接收
resp = new CmppSubmitResponseMessage(msg.getHeader().getSequenceId());
resp.setResult(0L);
// 把resp转化为ByteBuf
ch.writeOutbound(resp);
ch.writeInbound(ch.readOutbound());
CmppSubmitResponseMessage respret = ch.readInbound();
// System.out.println(respret.getRequest());
Assert.assertSame(msg, respret.getRequest());
Assert.assertNotEquals(respret.getMsgId(), msg.getMsgid());
// 没有等待发送的消息
Assert.assertEquals(0, sessionhandler.getWaittingResp());
// 等待重发超时
Thread.sleep((reSendTime + 1) * 1000);
// 因为已收到response,发送成功了,不会再重发了,因此这次接收的是Null
recvMsg = ch.readOutbound();
Assert.assertNull(recvMsg);
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage in project fastjson by alibaba.
the class Issue2685 method test_field.
public void test_field() throws Exception {
SMGPSubmitMessage smgpSubmitMessage = new SMGPSubmitMessage();
smgpSubmitMessage.setSequenceNo(1);
smgpSubmitMessage.setServiceId("hell");
// 注释掉可以正常
smgpSubmitMessage.setMsgContent("hello");
smgpSubmitMessage.setChargeTermId("123555");
smgpSubmitMessage.setSrcTermId("10086");
CmppSubmitResponseMessage submitResponseMessage = new CmppSubmitResponseMessage(1);
submitResponseMessage.setResult(0);
submitResponseMessage.setMsgId(new MsgId());
String smsMsg = JSON.toJSONString(smgpSubmitMessage);
// System.out.println(smsMsg);
JSON.addMixInAnnotations(SMGPSubmitMessage.class, Mixin.class);
smgpSubmitMessage = JSON.parseObject(smsMsg, SMGPSubmitMessage.class);
assertEquals("hello", smgpSubmitMessage.getMsgContent());
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage 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);
}
Aggregations