1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.commons.audit;
18
19 import io.vertx.core.AbstractVerticle;
20 import io.vertx.core.http.ClientAuth;
21 import io.vertx.core.net.JksOptions;
22 import io.vertx.core.net.NetServer;
23 import io.vertx.core.net.NetServerOptions;
24 import io.vertx.ext.unit.Async;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29
30
31 public class TCPSyslogServer extends AbstractVerticle {
32
33 private static final Logger LOG = LoggerFactory.getLogger(TCPSyslogServer.class);
34
35 private final int port;
36
37 private final NetServerOptions nsOptions;
38
39 private final Async async;
40
41 public TCPSyslogServer(int port, Async async){
42 this.port = port;
43 this.async = async;
44 nsOptions = new NetServerOptions()
45 .setReuseAddress(true)
46 .setHost("localhost")
47 .setSsl(false);
48 }
49
50 public TCPSyslogServer(int port, String clientAuth,
51 String trustStorePath, String trustStorePassword,
52 String keyStorePath, String keyStorePassword,
53 Async async){
54 this.port = port;
55 this.async = async;
56 nsOptions = new NetServerOptions()
57 .setReuseAddress(true)
58 .setHost("localhost")
59 .setClientAuth(ClientAuth.valueOf(clientAuth))
60 .setTrustStoreOptions(trustStorePath != null? new JksOptions().
61 setPath(trustStorePath).
62 setPassword(trustStorePassword): null)
63 .setKeyStoreOptions(keyStorePath != null? new JksOptions().
64 setPath(keyStorePath).
65 setPassword(keyStorePassword): null)
66 .setSsl(true);
67 }
68
69 @Override
70 public void start() {
71 NetServer netServer = vertx.createNetServer(nsOptions);
72 netServer.connectHandler(netSocket -> netSocket.handler(buffer -> {
73 LOG.debug("Received content on port {} ({}) : {}", port, async.count(), buffer.toString());
74 async.countDown();
75 })).listen(port);
76 }
77 }