View Javadoc
1   package ca.uhn.hl7v2.examples.hoh;
2   
3   import java.io.FileNotFoundException;
4   import java.io.IOException;
5   import java.security.KeyStoreException;
6   import java.security.NoSuchAlgorithmException;
7   import java.security.cert.CertificateException;
8   
9   import ca.uhn.hl7v2.DefaultHapiContext;
10  import ca.uhn.hl7v2.HL7Exception;
11  import ca.uhn.hl7v2.app.Connection;
12  import ca.uhn.hl7v2.hoh.api.DecodeException;
13  import ca.uhn.hl7v2.hoh.api.EncodeException;
14  import ca.uhn.hl7v2.hoh.api.IReceivable;
15  import ca.uhn.hl7v2.hoh.api.ISendable;
16  import ca.uhn.hl7v2.hoh.llp.Hl7OverHttpLowerLayerProtocol;
17  import ca.uhn.hl7v2.hoh.raw.client.HohRawClientSimple;
18  import ca.uhn.hl7v2.hoh.sign.BouncyCastleCmsMessageSigner;
19  import ca.uhn.hl7v2.hoh.util.KeystoreUtils;
20  import ca.uhn.hl7v2.hoh.util.ServerRoleEnum;
21  
22  public class SignatureClient {
23  
24  	/**
25  	 * @param args
26  	 * @throws IOException 
27  	 * @throws FileNotFoundException 
28  	 * @throws CertificateException 
29  	 * @throws NoSuchAlgorithmException 
30  	 * @throws KeyStoreException 
31  	 * @throws EncodeException 
32  	 * @throws DecodeException 
33  	 * @throws HL7Exception 
34  	 */
35  	@SuppressWarnings("unused")
36     public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, DecodeException, EncodeException, HL7Exception {
37  
38  		ISendable<?> sendable=null;
39  		{
40  // START SNIPPET: client 
41  // Create a client
42  HohRawClientSimpleentSimple.html#HohRawClientSimple">HohRawClientSimple client = new HohRawClientSimple("remotehost", 8080, "/");
43  
44  // Create a message signer
45  BouncyCastleCmsMessageSignerner.html#BouncyCastleCmsMessageSigner">BouncyCastleCmsMessageSigner signer = new BouncyCastleCmsMessageSigner();
46  signer.setKeyStore(KeystoreUtils.loadKeystore("/path/to/keystore/keystore.jks", "store_password"));
47  signer.setKeyAlias("keyalias");
48  signer.setAliasPassword("key_password");
49  
50  client.setSigner(signer);
51  
52  // Send a message
53  IReceivable<String> response = client.sendAndReceive(sendable);
54  // END SNIPPET: client 
55  	}
56  
57  // START SNIPPET: llp
58  // Create the ConnectionHub
59  String host = "localhost";
60  int port = 8080;
61  boolean tls = false;
62  
63  Hl7OverHttpLowerLayerProtocol llp;
64  llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.CLIENT);
65  llp.setHost(host);
66  
67  //Create a message signer
68  BouncyCastleCmsMessageSignerner.html#BouncyCastleCmsMessageSigner">BouncyCastleCmsMessageSigner signer = new BouncyCastleCmsMessageSigner();
69  signer.setKeyStore(KeystoreUtils.loadKeystore("/path/to/keystore/keystore.jks", "store_password"));
70  signer.setKeyAlias("keyalias");
71  signer.setAliasPassword("key_password");
72  llp.setSigner(signer);
73  
74  
75  DefaultHapiContextml#DefaultHapiContext">DefaultHapiContext ctx = new DefaultHapiContext();
76  ctx.setLowerLayerProtocol(llp);
77  
78  // Connect
79  Connection connection = ctx.newClient(host, port, tls);
80  //END SNIPPET: llp
81  
82  
83  	}
84  
85  }