1 package ca.uhn.hl7v2.examples;
2
3 import ca.uhn.hl7v2.DefaultHapiContext;
4 import ca.uhn.hl7v2.HL7Exception;
5 import ca.uhn.hl7v2.HapiContext;
6 import ca.uhn.hl7v2.app.Connection;
7 import ca.uhn.hl7v2.app.HL7Service;
8 import ca.uhn.hl7v2.hoh.sockets.CustomCertificateTlsSocketFactory;
9 import ca.uhn.hl7v2.hoh.util.HapiSocketTlsFactoryWrapper;
10
11 public class UsingTls {
12
13
14
15
16 @SuppressWarnings("unused")
17 public static void main(String[] args) throws HL7Exception {
18
19
20
21
22
23
24
25
26
27
28
29
30
31 HapiContext ctx = new DefaultHapiContext();
32
33 boolean useTls = true;
34 int port = 8888;
35 HL7Service server = ctx.newServer(port, useTls);
36 Connection client = ctx.newClient("localhost", port, useTls);
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 CustomCertificateTlsSocketFactory sfac = new CustomCertificateTlsSocketFactory();
57 sfac.setKeystoreFilename("file://C:/keystores/client.jks");
58 sfac.setKeystorePassphrase("keystorepass");
59
60
61 ctx.setSocketFactory(new HapiSocketTlsFactoryWrapper(sfac));
62
63
64 client = ctx.newClient("localhost", port, useTls);
65 }
66
67 }