Search in sources :

Example 1 with BusinessHandlerInterface

use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.

the class TestCMPPEndPoint method testCMPPEndpoint.

@Test
public void testCMPPEndpoint() throws Exception {
    ResourceLeakDetector.setLevel(Level.ADVANCED);
    final EndpointManager manager = EndpointManager.INS;
    CMPPServerEndpointEntity server = new CMPPServerEndpointEntity();
    server.setId("server");
    server.setHost("0.0.0.0");
    server.setPort(7890);
    server.setValid(true);
    // 使用ssl加密数据流
    server.setUseSSL(false);
    CMPPServerChildEndpointEntity child = new CMPPServerChildEndpointEntity();
    child.setId("child");
    child.setChartset(Charset.forName("utf-8"));
    child.setGroupName("test");
    child.setUserName("901783");
    child.setPassword("ICP001");
    child.setValid(true);
    child.setVersion((short) 0x30);
    child.setMaxChannels((short) 1);
    child.setRetryWaitTimeSec((short) 30);
    child.setMaxRetryCnt((short) 3);
    // 不开启IP白名单
    // List<String> iplist = new ArrayList<String>();
    // iplist.add("192.168.98.48/18");
    // child.setAllowedAddr(iplist);
    child.setReSendFailMsg(false);
    // child.setWriteLimit(200);
    // child.setReadLimit(200);
    List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
    CMPPMessageReceiveHandler receiver = new CMPPMessageReceiveHandler();
    serverhandlers.add(new AbstractBusinessHandler() {

        @Override
        public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
            CMPPResponseSenderHandler handler = new CMPPResponseSenderHandler();
            handler.setEndpointEntity(getEndpointEntity());
            ctx.pipeline().addAfter("sessionStateManager", handler.name(), handler);
            ctx.pipeline().remove(this);
        }

        @Override
        public String name() {
            return "AddCMPPResponseSenderHandler";
        }
    });
    serverhandlers.add(receiver);
    child.setBusinessHandlerSet(serverhandlers);
    server.addchild(child);
    manager.addEndpointEntity(server);
    CMPPClientEndpointEntity client = new CMPPClientEndpointEntity();
    client.setId("client");
    // client.setLocalhost("127.0.0.1");
    // client.setLocalport(65521);
    client.setHost("127.0.0.1");
    client.setPort(7890);
    client.setChartset(Charset.forName("utf-8"));
    client.setGroupName("test");
    client.setUserName("901783");
    client.setPassword("ICP001");
    client.setMaxChannels((short) 1);
    client.setVersion((short) 0x30);
    client.setRetryWaitTimeSec((short) 30);
    client.setUseSSL(false);
    // client.setWriteLimit(100);
    client.setReSendFailMsg(true);
    client.setSupportLongmsg(SupportLongMessage.BOTH);
    List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
    int count = 2000000;
    CMPPSessionConnectedHandler sender = new CMPPSessionConnectedHandler(count);
    clienthandlers.add(sender);
    client.setBusinessHandlerSet(clienthandlers);
    manager.addEndpointEntity(client);
    manager.openEndpoint(server);
    manager.openEndpoint(client);
    Thread.sleep(5000);
    manager.startConnectionCheckTask();
    System.out.println("start.....");
    while (receiver.getCnt().get() < count) {
        Thread.sleep(1000);
    }
    Thread.sleep(3000);
    EndpointManager.INS.close();
    Thread.sleep(4000);
    System.out.println("end.....");
}
Also used : BusinessHandlerInterface(com.zx.sms.handler.api.BusinessHandlerInterface) ArrayList(java.util.ArrayList) EndpointManager(com.zx.sms.connect.manager.EndpointManager) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) AbstractBusinessHandler(com.zx.sms.handler.api.AbstractBusinessHandler) Test(org.junit.Test)

Example 2 with BusinessHandlerInterface

use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.

the class TestSgipEndPoint method testsgipEndpoint.

@Test
public void testsgipEndpoint() throws Exception {
    ResourceLeakDetector.setLevel(Level.ADVANCED);
    final EndpointManager manager = EndpointManager.INS;
    SgipServerEndpointEntity server = new SgipServerEndpointEntity();
    server.setId("sgipserver");
    server.setHost("127.0.0.1");
    server.setPort(8001);
    server.setValid(true);
    // 使用ssl加密数据流
    server.setUseSSL(false);
    SgipServerChildEndpointEntity child = new SgipServerChildEndpointEntity();
    child.setId("sgipchild");
    child.setLoginName("333");
    child.setLoginPassowrd("0555");
    child.setNodeId(3025000001L);
    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) 30);
    // child.setWriteLimit(200);
    // child.setReadLimit(200);
    child.setSupportLongmsg(SupportLongMessage.BOTH);
    List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
    serverhandlers.add(new SGIPMessageReceiveHandler());
    child.setBusinessHandlerSet(serverhandlers);
    server.addchild(child);
    manager.addEndpointEntity(server);
    SgipClientEndpointEntity client = new SgipClientEndpointEntity();
    client.setId("sgipclient");
    client.setHost("127.0.0.1");
    client.setPort(8001);
    client.setLoginName("333");
    client.setLoginPassowrd("0555");
    client.setChannelType(ChannelType.DUPLEX);
    client.setNodeId(3073100002L);
    client.setMaxChannels((short) 10);
    client.setRetryWaitTimeSec((short) 100);
    client.setUseSSL(false);
    client.setReSendFailMsg(false);
    client.setIdleTimeSec((short) 120);
    // client.setWriteLimit(200);
    // client.setReadLimit(200);
    List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
    clienthandlers.add(new SgipReportRequestMessageHandler());
    clienthandlers.add(new SGIPSessionConnectedHandler(10000));
    client.setBusinessHandlerSet(clienthandlers);
    manager.addEndpointEntity(client);
    manager.openAll();
    Thread.sleep(1000);
    System.out.println("start.....");
    LockSupport.park();
    EndpointManager.INS.close();
}
Also used : SgipReportRequestMessageHandler(com.zx.sms.handler.sgip.SgipReportRequestMessageHandler) BusinessHandlerInterface(com.zx.sms.handler.api.BusinessHandlerInterface) ArrayList(java.util.ArrayList) EndpointManager(com.zx.sms.connect.manager.EndpointManager) Test(org.junit.Test)

Example 3 with BusinessHandlerInterface

use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.

the class TestSMGPEndPoint method testSMGPEndpoint.

@Test
public void testSMGPEndpoint() throws Exception {
    final EndpointManager manager = EndpointManager.INS;
    SMGPServerEndpointEntity server = new SMGPServerEndpointEntity();
    server.setId("smgpserver");
    server.setHost("127.0.0.1");
    server.setPort(9890);
    server.setValid(true);
    // 使用ssl加密数据流
    server.setUseSSL(false);
    SMGPServerChildEndpointEntity child = new SMGPServerChildEndpointEntity();
    child.setId("smgpchild");
    child.setClientID("333");
    child.setPassword("0555");
    child.setValid(true);
    child.setChannelType(ChannelType.DUPLEX);
    child.setClientVersion((byte) 0x13);
    child.setMaxChannels((short) 3);
    child.setRetryWaitTimeSec((short) 30);
    child.setMaxRetryCnt((short) 3);
    child.setReSendFailMsg(false);
    child.setIdleTimeSec((short) 15);
    // 接收长短信时不自动合并
    child.setSupportLongmsg(SupportLongMessage.SEND);
    List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
    serverhandlers.add(new SMGPMessageReceiveHandler());
    child.setBusinessHandlerSet(serverhandlers);
    server.addchild(child);
    manager.addEndpointEntity(server);
    SMGPClientEndpointEntity client = new SMGPClientEndpointEntity();
    client.setId("smgpclient");
    client.setHost("127.0.0.1");
    client.setPort(9890);
    client.setClientID("333");
    client.setPassword("0555");
    client.setChannelType(ChannelType.DUPLEX);
    client.setMaxChannels((short) 30);
    client.setRetryWaitTimeSec((short) 100);
    client.setUseSSL(false);
    client.setReSendFailMsg(false);
    client.setClientVersion((byte) 0x13);
    // client.setWriteLimit(200);
    // client.setReadLimit(200);
    List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
    clienthandlers.add(new SMGPSessionConnectedHandler(10000));
    client.setBusinessHandlerSet(clienthandlers);
    manager.addEndpointEntity(client);
    manager.openAll();
    Thread.sleep(1000);
    for (int i = 0; i < child.getMaxChannels(); i++) manager.openEndpoint(client);
    System.out.println("start.....");
    LockSupport.park();
    EndpointManager.INS.close();
}
Also used : BusinessHandlerInterface(com.zx.sms.handler.api.BusinessHandlerInterface) ArrayList(java.util.ArrayList) EndpointManager(com.zx.sms.connect.manager.EndpointManager) Test(org.junit.Test)

Example 4 with BusinessHandlerInterface

use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.

the class CMPPChargingDemoTest method testCharging.

/*
	 *使用自己扩展的Entity 
	 */
@Test
public void testCharging() throws Exception {
    final EndpointManager manager = EndpointManager.INS;
    CMPPServerEndpointEntity server = new CMPPServerEndpointEntity();
    server.setId("server");
    server.setHost("127.0.0.1");
    server.setPort(7892);
    server.setValid(true);
    // 使用ssl加密数据流
    server.setUseSSL(false);
    CMPPServerChildEndpointEntity child = new CMPPServerChildEndpointEntity();
    child.setId("child");
    child.setChartset(Charset.forName("utf-8"));
    child.setGroupName("test");
    child.setUserName("GSDT01");
    child.setPassword("1qaz2wsx");
    child.setValid(true);
    child.setVersion((short) 0x20);
    child.setMaxChannels((short) 20);
    child.setRetryWaitTimeSec((short) 30);
    child.setMaxRetryCnt((short) 3);
    // child.setReSendFailMsg(true);
    // child.setWriteLimit(200);
    // child.setReadLimit(200);
    List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
    serverhandlers.add(new CMPPMessageReceiveHandler());
    serverhandlers.add(new AbstractBusinessHandler() {

        @Override
        public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
            CMPPResponseSenderHandler handler = new CMPPResponseSenderHandler();
            handler.setEndpointEntity(getEndpointEntity());
            ctx.pipeline().addBefore("sessionStateManager", handler.name(), handler);
            ctx.pipeline().remove(this);
        }

        @Override
        public String name() {
            return "AddCMPPResponseSenderHandler";
        }
    });
    child.setBusinessHandlerSet(serverhandlers);
    server.addchild(child);
    manager.addEndpointEntity(server);
    MyCMPPClientEndpointEntity client = new MyCMPPClientEndpointEntity();
    client.setId("client");
    client.setHost("127.0.0.1");
    client.setPort(7892);
    client.setChartset(Charset.forName("utf-8"));
    client.setGroupName("test");
    client.setUserName("GSDT01");
    client.setPassword("1qaz2wsx");
    client.setMaxChannels((short) 12);
    client.setVersion((short) 0x20);
    client.setRetryWaitTimeSec((short) 10);
    client.setUseSSL(false);
    client.setReSendFailMsg(false);
    List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
    clienthandlers.add(new CMPPSessionConnectedHandler(10));
    client.setBusinessHandlerSet(clienthandlers);
    manager.addEndpointEntity(client);
    manager.openAll();
    // LockSupport.park();
    System.out.println("start.....");
    Thread.sleep(300000);
    EndpointManager.INS.close();
}
Also used : BusinessHandlerInterface(com.zx.sms.handler.api.BusinessHandlerInterface) ArrayList(java.util.ArrayList) EndpointManager(com.zx.sms.connect.manager.EndpointManager) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) AbstractBusinessHandler(com.zx.sms.handler.api.AbstractBusinessHandler) Test(org.junit.Test)

Example 5 with BusinessHandlerInterface

use of com.zx.sms.handler.api.BusinessHandlerInterface in project SMSGate by Lihuanghe.

the class ClientTestCMPPEndPoint method testCMPPEndpoint.

@Test
public void testCMPPEndpoint() throws Exception {
    final EndpointManager manager = EndpointManager.INS;
    CMPPClientEndpointEntity client = new CMPPClientEndpointEntity();
    client.setId("GSDT01");
    client.setHost("127.0.0.1");
    client.setPort(7891);
    client.setChartset(Charset.forName("utf-8"));
    client.setGroupName("test");
    client.setUserName("901782");
    client.setPassword("ICP");
    client.setSpCode("1069039128");
    client.setMaxChannels((short) 11);
    client.setVersion((short) 0x20);
    client.setRetryWaitTimeSec((short) 30);
    client.setUseSSL(false);
    client.setReSendFailMsg(false);
    // client.setWriteLimit(500);
    List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
    clienthandlers.add(new CMPPSessionConnectedHandler(100));
    client.setBusinessHandlerSet(clienthandlers);
    manager.addEndpointEntity(client);
    CMPPClientEndpointEntity client1 = new CMPPClientEndpointEntity();
    client1.setId("GSDT02");
    client1.setHost("127.0.0.1");
    client1.setPort(7891);
    client1.setChartset(Charset.forName("utf-8"));
    client1.setGroupName("test");
    client1.setSpCode("1069039129");
    client1.setUserName("901782");
    client1.setPassword("ICP");
    // client1.setProxy("http://username:password@127.0.0.1:1080");
    client1.setMaxChannels((short) 30);
    client1.setVersion((short) 0x20);
    client1.setRetryWaitTimeSec((short) 30);
    client1.setUseSSL(false);
    client1.setReSendFailMsg(true);
    // client.setWriteLimit(10);
    List<BusinessHandlerInterface> clienthandlers1 = new ArrayList<BusinessHandlerInterface>();
    clienthandlers1.add(new CMPPSessionConnectedHandler(0));
    client1.setBusinessHandlerSet(clienthandlers1);
    // manager.addEndpointEntity(client1);
    // manager.openAll();
    // LockSupport.park();
    Thread.sleep(1000);
    manager.openEndpoint(client);
    // manager.openEndpoint(client);Thread.sleep(1000);
    // manager.startConnectionCheckTask();
    // while(true){
    // 
    // try{
    // Thread.sleep(20000);
    // }catch(Exception e){
    // break;
    // }
    // EndpointConnector conn = manager.getEndpointConnector(client);
    // conn.fetch().close();
    // }
    System.out.println("start.....");
    LockSupport.park();
    EndpointManager.INS.close();
}
Also used : BusinessHandlerInterface(com.zx.sms.handler.api.BusinessHandlerInterface) ArrayList(java.util.ArrayList) EndpointManager(com.zx.sms.connect.manager.EndpointManager) Test(org.junit.Test)

Aggregations

BusinessHandlerInterface (com.zx.sms.handler.api.BusinessHandlerInterface)8 EndpointManager (com.zx.sms.connect.manager.EndpointManager)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 AbstractBusinessHandler (com.zx.sms.handler.api.AbstractBusinessHandler)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 CMPPServerEndpointEntity (com.zx.sms.connect.manager.cmpp.CMPPServerEndpointEntity)1 SMPPMessageReceiveHandler (com.zx.sms.connect.manager.smpp.SMPPMessageReceiveHandler)1 SMPPServerChildEndpointEntity (com.zx.sms.connect.manager.smpp.SMPPServerChildEndpointEntity)1 SMPPServerEndpointEntity (com.zx.sms.connect.manager.smpp.SMPPServerEndpointEntity)1 MessageLogHandler (com.zx.sms.handler.MessageLogHandler)1 SgipReportRequestMessageHandler (com.zx.sms.handler.sgip.SgipReportRequestMessageHandler)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1