use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.
the class TestSMPPEndPoint method testSMPPEndpoint.
@Test
public void testSMPPEndpoint() throws Exception {
final EndpointManager manager = EndpointManager.INS;
int port = 27761;
SMPPServerEndpointEntity server = new SMPPServerEndpointEntity();
server.setId("smppserver");
server.setHost("127.0.0.1");
server.setPort(port);
server.setValid(true);
// 使用ssl加密数据流
server.setUseSSL(false);
SMPPServerChildEndpointEntity child = new SMPPServerChildEndpointEntity();
child.setId("smppchild");
child.setSystemId("901782");
child.setPassword("ICP");
child.setValid(true);
child.setChannelType(ChannelType.DUPLEX);
child.setMaxChannels((short) 3);
child.setRetryWaitTimeSec((short) 30);
child.setMaxRetryCnt((short) 3);
child.setReSendFailMsg(false);
child.setIdleTimeSec((short) 15);
// child.setWriteLimit(200);
// child.setReadLimit(200);
List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
serverhandlers.add(new SMPPMessageReceiveHandler());
child.setBusinessHandlerSet(serverhandlers);
server.addchild(child);
SMPPClientEndpointEntity client = new SMPPClientEndpointEntity();
client.setId("smppclient");
client.setHost("127.0.0.1");
client.setPort(port);
client.setSystemId("901782");
client.setPassword("ICP");
client.setChannelType(ChannelType.DUPLEX);
client.setMaxChannels((short) 12);
client.setRetryWaitTimeSec((short) 100);
client.setUseSSL(false);
client.setReSendFailMsg(false);
// client.setWriteLimit(200);
// client.setReadLimit(200);
// 接收长短信时不自动合并
client.setSupportLongmsg(SupportLongMessage.SEND);
List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
clienthandlers.add(new SMPPSessionConnectedHandler(10));
client.setBusinessHandlerSet(clienthandlers);
manager.addEndpointEntity(server);
manager.addEndpointEntity(client);
manager.openAll();
Thread.sleep(1000);
System.out.println("start.....");
LockSupport.park();
EndpointManager.INS.close();
}
use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.
the class TestWithOpenSMPP method test.
@Test
public void test() throws Exception {
final EndpointManager manager = EndpointManager.INS;
SMPPServerEndpointEntity server = new SMPPServerEndpointEntity();
server.setId("sms-core-smppserver");
server.setHost("127.0.0.1");
server.setPort(port);
server.setValid(true);
// 使用ssl加密数据流
server.setUseSSL(false);
SMPPServerChildEndpointEntity child = new SMPPServerChildEndpointEntity();
child.setId("smppchild");
child.setSystemId(systemId);
child.setPassword(password);
child.setValid(true);
child.setChannelType(ChannelType.DOWN);
child.setMaxChannels((short) 3);
child.setRetryWaitTimeSec((short) 30);
child.setMaxRetryCnt((short) 3);
child.setReSendFailMsg(false);
child.setIdleTimeSec((short) 15);
// child.setWriteLimit(200);
// child.setReadLimit(200);
List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
serverhandlers.add(new SMPPMessageReceiveHandler());
child.setBusinessHandlerSet(serverhandlers);
server.addchild(child);
manager.addEndpointEntity(server);
manager.openAll();
Thread.sleep(2000);
System.out.println("start.....");
bind();
String randomStr = String.valueOf(RandomUtils.nextInt(0, 10000));
sendsubmit("@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà^{}\\[~]|" + randomStr, Data.ENC_GSM7BIT);
sendsubmit("尊敬的客户,您好!您于2016-03-23 14:51:36通过中国移动10085销售专线订购的【一加手机高清防刮保护膜】" + randomStr, Data.ENC_UTF16_BE);
unbind();
}
use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.
the class AbstractEndpointConnector method bindHandler.
/**
* 连接建立成功后要加载的channelHandler
*/
protected void bindHandler(ChannelPipeline pipe, EndpointEntity entity) {
if (entity instanceof CMPPServerEndpointEntity) {
return;
}
pipe.addFirst("socketLog", new LoggingHandler(String.format(GlobalConstance.loggerNamePrefix, entity.getId()), LogLevel.TRACE));
// 调用子类的bind方法
doBindHandler(pipe, entity);
pipe.addAfter(GlobalConstance.codecName, "msgLog", new MessageLogHandler(entity));
List<BusinessHandlerInterface> handlers = entity.getBusinessHandlerSet();
if (handlers != null && handlers.size() > 0) {
for (BusinessHandlerInterface handler : handlers) {
if (handler instanceof AbstractBusinessHandler) {
AbstractBusinessHandler buziHandler = (AbstractBusinessHandler) handler;
buziHandler.setEndpointEntity(entity);
if (buziHandler.isSharable()) {
pipe.addLast(buziHandler.name(), buziHandler);
} else {
AbstractBusinessHandler cloned = null;
try {
cloned = buziHandler.clone();
} catch (CloneNotSupportedException e) {
logger.error("handlers is not shareable and not implements Cloneable", e);
}
if (cloned != null) {
cloned.setEndpointEntity(entity);
pipe.addLast(buziHandler.name(), cloned);
logger.info("handlers is not shareable . clone it success. {}", cloned);
}
}
} else {
handler.setEndpointEntity(entity);
pipe.addLast(handler.name(), handler);
logger.info("add share handlers . {}", handler);
}
}
}
// 黑洞处理,丢弃所有消息
pipe.addLast("BlackHole", GlobalConstance.blackhole);
}
Aggregations