View Javadoc
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  	 * @param args
24  	 * @throws Exception 
25  	 */
26  	public static void main(String[] args) throws Exception {
27  
28  //START SNIPPET: llp 
29  // Create a socketfactory which references the keystore
30  CustomCertificateTlsSocketFactoryustomCertificateTlsSocketFactory">CustomCertificateTlsSocketFactory serverSocketFactory = new CustomCertificateTlsSocketFactory();
31  serverSocketFactory.setKeystoreFilename("/path/to/keystore/keystore.jks");
32  serverSocketFactory.setKeystorePassphrase("changeit");
33  
34  // Create a new HAPI context
35  HapiContext ctx = new DefaultHapiContext();
36  
37  // The socket factory needs to be wrapped for use in HAPI
38  HapiSocketTlsFactoryWrapperpiSocketTlsFactoryWrapper">HapiSocketTlsFactoryWrapper hapiSocketFactory = new HapiSocketTlsFactoryWrapper(serverSocketFactory);
39  ctx.setSocketFactory(hapiSocketFactory);
40  
41  // Create an HoH LLP instance
42  LowerLayerProtocol llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.SERVER);
43  
44  // Start a server listening on port 443 with a pipe parseer
45  ctx.setLowerLayerProtocol(llp);
46  
47  HL7Service server = ctx.newServer(443, true);
48  
49  // ...Register applications...
50  
51  server.start();
52  //END SNIPPET: llp 
53  
54  // START SNIPPET: server 
55  // Create a Jetty Server
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  // END SNIPPET: server 
76  	}
77  
78  }