1 package ca.uhn.hl7v2.examples.hoh;
2
3 import java.io.IOException;
4
5 import ca.uhn.hl7v2.HL7Exception;
6 import ca.uhn.hl7v2.hoh.api.DecodeException;
7 import ca.uhn.hl7v2.hoh.api.EncodeException;
8 import ca.uhn.hl7v2.hoh.api.IAuthorizationClientCallback;
9 import ca.uhn.hl7v2.hoh.api.IReceivable;
10 import ca.uhn.hl7v2.hoh.api.ISendable;
11 import ca.uhn.hl7v2.hoh.api.MessageMetadataKeys;
12 import ca.uhn.hl7v2.hoh.auth.SingleCredentialClientCallback;
13 import ca.uhn.hl7v2.hoh.hapi.api.MessageSendable;
14 import ca.uhn.hl7v2.hoh.hapi.client.HohClientSimple;
15 import ca.uhn.hl7v2.hoh.sockets.TlsSocketFactory;
16 import ca.uhn.hl7v2.model.Message;
17 import ca.uhn.hl7v2.model.v25.message.ADT_A01;
18 import ca.uhn.hl7v2.parser.Parser;
19 import ca.uhn.hl7v2.parser.PipeParser;
20
21 public class HohClientSimpleExample {
22
23
24
25
26 public static void main(String[] args) throws HL7Exception, IOException {
27
28
29
30
31 String host = "localhost";
32 int port = 8080;
33 String uri = "/AppContext";
34
35
36 Parser parser = PipeParser.getInstanceWithNoValidation();
37
38
39 HohClientSimple client = new HohClientSimple(host, port, uri, parser);
40
41
42 client.setSocketFactory(new TlsSocketFactory());
43
44
45
46 IAuthorizationClientCallback authCalback = new SingleCredentialClientCallback("ausername", "somepassword");
47 client.setAuthorizationCallback(authCalback);
48
49
50
51 ADT_A01 adt = new ADT_A01();
52 adt.initQuickstart("ADT", "A01", "T");
53
54
55
56 ISendable<Message> sendable = new MessageSendable(adt);
57
58 try {
59
60 IReceivable<Message> receivable = client.sendAndReceiveMessage(sendable);
61
62
63 Message message = receivable.getMessage();
64 System.out.println("Response was:\n" + message.encode());
65
66
67 String remoteHostIp = (String) receivable.getMetadata().get(MessageMetadataKeys.REMOTE_HOST_ADDRESS);
68 System.out.println("From:\n" + remoteHostIp);
69
70
71
72
73
74
75 } catch (DecodeException | EncodeException | IOException e) {
76
77 e.printStackTrace();
78 }
79
80
81
82 }
83
84 }