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
26
27
28
29
30
31
32
33
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
41
42 HohRawClientSimpleentSimple.html#HohRawClientSimple">HohRawClientSimple client = new HohRawClientSimple("remotehost", 8080, "/");
43
44
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
53 IReceivable<String> response = client.sendAndReceive(sendable);
54
55 }
56
57
58
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
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
79 Connection connection = ctx.newClient(host, port, tls);
80
81
82
83 }
84
85 }