View Javadoc

1   package ca.uhn.hl7v2.examples.hoh;
2   
3   import org.mortbay.jetty.Server;
4   import org.mortbay.jetty.security.SslSelectChannelConnector;
5   
6   import ca.uhn.hl7v2.DefaultHapiContext;
7   import ca.uhn.hl7v2.HapiContext;
8   import ca.uhn.hl7v2.app.HL7Service;
9   import ca.uhn.hl7v2.hoh.llp.Hl7OverHttpLowerLayerProtocol;
10  import ca.uhn.hl7v2.hoh.sockets.CustomCertificateTlsSocketFactory;
11  import ca.uhn.hl7v2.hoh.util.HapiSocketTlsFactoryWrapper;
12  import ca.uhn.hl7v2.hoh.util.ServerRoleEnum;
13  import ca.uhn.hl7v2.llp.LowerLayerProtocol;
14  
15  public class CustomCertificateServer {
16  
17  	/**
18  	 * @param args
19  	 * @throws Exception 
20  	 */
21  	public static void main(String[] args) throws Exception {
22  
23  //START SNIPPET: llp 
24  // Create a socketfactory which references the keystore
25  CustomCertificateTlsSocketFactory serverSocketFactory = new CustomCertificateTlsSocketFactory();
26  serverSocketFactory.setKeystoreFilename("/path/to/keystore/keystore.jks");
27  serverSocketFactory.setKeystorePassphrase("changeit");
28  
29  // Create a new HAPI context
30  HapiContext ctx = new DefaultHapiContext();
31  
32  // The socket factory needs to be wrapped for use in HAPI
33  HapiSocketTlsFactoryWrapper hapiSocketFactory = new HapiSocketTlsFactoryWrapper(serverSocketFactory);
34  ctx.setSocketFactory(hapiSocketFactory);
35  
36  // Create an HoH LLP instance
37  LowerLayerProtocol llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.SERVER);
38  
39  // Start a server listening on port 443 with a pipe parseer
40  ctx.setLowerLayerProtocol(llp);
41  
42  HL7Service server = ctx.newServer(443, true);
43  
44  // ...Register applications...
45  
46  server.start();
47  //END SNIPPET: llp 
48  
49  // START SNIPPET: server 
50  // Create a Jetty Server
51  Server s = new Server();
52  
53  SslSelectChannelConnector ssl = new SslSelectChannelConnector();
54  ssl.setKeystore("src/test/resources/keystore.jks");
55  ssl.setPassword("changeit");
56  ssl.setKeyPassword("changeit");
57  ssl.setPort(443);
58  
59  s.addConnector(ssl);
60  s.start();
61  // END SNIPPET: server 
62  	}
63  
64  }