1 package ca.uhn.hl7v2.examples.hoh;
2
3 import ca.uhn.hl7v2.DefaultHapiContext;
4 import ca.uhn.hl7v2.HapiContext;
5 import ca.uhn.hl7v2.app.HL7Service;
6 import ca.uhn.hl7v2.hoh.llp.Hl7OverHttpLowerLayerProtocol;
7 import ca.uhn.hl7v2.hoh.sockets.CustomCertificateTlsSocketFactory;
8 import ca.uhn.hl7v2.hoh.util.HapiSocketTlsFactoryWrapper;
9 import ca.uhn.hl7v2.hoh.util.ServerRoleEnum;
10 import ca.uhn.hl7v2.llp.LowerLayerProtocol;
11 import org.eclipse.jetty.server.Connector;
12 import org.eclipse.jetty.server.HttpConfiguration;
13 import org.eclipse.jetty.server.HttpConnectionFactory;
14 import org.eclipse.jetty.server.SecureRequestCustomizer;
15 import org.eclipse.jetty.server.Server;
16 import org.eclipse.jetty.server.ServerConnector;
17 import org.eclipse.jetty.server.SslConnectionFactory;
18 import org.eclipse.jetty.util.ssl.SslContextFactory;
19
20 public class CustomCertificateServer {
21
22
23
24
25
26 public static void main(String[] args) throws Exception {
27
28
29
30 CustomCertificateTlsSocketFactoryustomCertificateTlsSocketFactory">CustomCertificateTlsSocketFactory serverSocketFactory = new CustomCertificateTlsSocketFactory();
31 serverSocketFactory.setKeystoreFilename("/path/to/keystore/keystore.jks");
32 serverSocketFactory.setKeystorePassphrase("changeit");
33
34
35 HapiContext ctx = new DefaultHapiContext();
36
37
38 HapiSocketTlsFactoryWrapperpiSocketTlsFactoryWrapper">HapiSocketTlsFactoryWrapper hapiSocketFactory = new HapiSocketTlsFactoryWrapper(serverSocketFactory);
39 ctx.setSocketFactory(hapiSocketFactory);
40
41
42 LowerLayerProtocol llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.SERVER);
43
44
45 ctx.setLowerLayerProtocol(llp);
46
47 HL7Service server = ctx.newServer(443, true);
48
49
50
51 server.start();
52
53
54
55
56 Server s = new Server();
57
58 HttpConfiguration https = new HttpConfiguration();
59 https.addCustomizer(new SecureRequestCustomizer());
60
61 SslContextFactory.Server ssl = new SslContextFactory.Server();
62 ssl.setKeyStorePath("src/test/resources/keystore.jks");
63 ssl.setKeyStorePassword("changeit");
64 ssl.setKeyManagerPassword("changeit");
65
66 ServerConnector sslConnector = new ServerConnector(s,
67 new SslConnectionFactory(ssl, "http/1.1"),
68 new HttpConnectionFactory(https));
69 sslConnector.setPort(443);
70 sslConnector.setIdleTimeout(50000);
71
72 s.setConnectors(new Connector[]{ sslConnector });
73
74 s.start();
75
76 }
77
78 }