org.productivity.java.syslog4j.server.impl.net.udp.UDPNetSyslogServerConfig Java Examples

The following examples show how to use org.productivity.java.syslog4j.server.impl.net.udp.UDPNetSyslogServerConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Syslog4jAppenderTest.java    From logback-syslog4j with MIT License 6 votes vote down vote up
protected void setUp() {
    serverStream = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(serverStream);

    final TCPNetSyslogServerConfig tcpNetSyslogServerConfig = new TCPNetSyslogServerConfig(45553);
    tcpNetSyslogServerConfig.addEventHandler(new PrintStreamSyslogServerEventHandler(ps));

    final UDPNetSyslogServerConfig udpNetSyslogServerConfig = new UDPNetSyslogServerConfig(45553);
    udpNetSyslogServerConfig.addEventHandler(new PrintStreamSyslogServerEventHandler(ps));

    final SSLTCPNetSyslogServerConfig ssltcpNetSyslogServerConfig = new SSLTCPNetSyslogServerConfig();
    ssltcpNetSyslogServerConfig.setPort(45554);
    ssltcpNetSyslogServerConfig.addEventHandler(new PrintStreamSyslogServerEventHandler(ps));
    ssltcpNetSyslogServerConfig.setKeyStore(this.getClass().getClassLoader().getResource("test-keystore.jks").getFile());
    ssltcpNetSyslogServerConfig.setKeyStorePassword("password");
    ssltcpNetSyslogServerConfig.setTrustStore(this.getClass().getClassLoader().getResource("test-keystore.jks").getFile());
    ssltcpNetSyslogServerConfig.setTrustStorePassword("password");

    SyslogServer.createThreadedInstance("testTcp", tcpNetSyslogServerConfig);
    SyslogServer.createThreadedInstance("testUdp", udpNetSyslogServerConfig);
    SyslogServer.createThreadedInstance("testTls", ssltcpNetSyslogServerConfig);
}
 
Example #2
Source File: SyslogCreateAndDestroyTest.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testCreateAndDestroyServerByProtocol() {
	UDPNetSyslogServerConfig config = new UDPNetSyslogServerConfig();
	config.setPort(999);
	
	SyslogServerIF server = SyslogServer.createInstance("udpToDestroy",config);
	
	SyslogServerIF matchServer = SyslogServer.getInstance("udpToDestroy");
	
	assertEquals(server,matchServer);
	
	SyslogServer.destroyInstance("");
	SyslogServer.destroyInstance("udpToDestroy");
	
	try {
		SyslogServer.getInstance("udpToDestroy");
		fail("udpToDestroy should not exist");
		
	} catch (SyslogRuntimeException sre) {
		//
	}
	
	assertFalse(SyslogServer.getSuppressRuntimeExceptions());
	SyslogServer.setSuppressRuntimeExceptions(true);
	assertTrue(SyslogServer.getSuppressRuntimeExceptions());

	assertNull(SyslogServer.getInstance("udpToDestroy"));

	SyslogServer.setSuppressRuntimeExceptions(false);
}
 
Example #3
Source File: SyslogServer.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public synchronized static void initialize() {
	createInstance(UDP,new UDPNetSyslogServerConfig());
	createInstance(TCP,new TCPNetSyslogServerConfig());
}
 
Example #4
Source File: SyslogServerSessionTest.java    From syslog4j with GNU Lesser General Public License v2.1 2 votes vote down vote up
public void testUDPSession() {
	SyslogServerConfigIF serverConfig = new UDPNetSyslogServerConfig(9999);
	
	UDPSessionHandler handler1 = new UDPSessionHandler("a");
	serverConfig.addEventHandler(handler1);
	
	UDPSessionHandler handler2 = new UDPSessionHandler("b");
	serverConfig.addEventHandler(handler2);
	
	SyslogServer.createThreadedInstance("udp_session",serverConfig);
	
	SyslogUtility.sleep(100);
	
	assertTrue(handler1.initialized);
	assertTrue(handler2.initialized);

	SyslogConfigIF config = new UDPNetSyslogConfig();
	config.setPort(9999);
	
	SyslogIF syslog1 = Syslog.createInstance("udp_session_1",config);
	
	syslog1.info("1");
	syslog1.info("2");

	SyslogIF syslog2 = Syslog.createInstance("udp_session_2",config);
	
	syslog2.info("3");
	syslog2.info("4");

	SyslogUtility.sleep(100);
	
	syslog1.shutdown();
	syslog2.shutdown();
	SyslogServer.destroyInstance("udp_session");
	
	try {
		SyslogServer.getInstance("udp_session");
		fail();
		
	} catch (SyslogRuntimeException sre) {
		//
	}
	
	assertTrue(handler1.okay);
	assertTrue(handler2.okay);
	
	SyslogUtility.sleep(250);
	
	assertTrue(handler1.destroyed);
	assertTrue(handler2.destroyed);
}