1 package ca.uhn.hl7v2.examples.upgrade;
2
3 import java.io.IOException;
4 import java.net.ServerSocket;
5 import java.util.Map;
6
7 import ca.uhn.hl7v2.DefaultHapiContext;
8 import ca.uhn.hl7v2.HL7Exception;
9 import ca.uhn.hl7v2.app.HL7Service;
10 import ca.uhn.hl7v2.model.Message;
11 import ca.uhn.hl7v2.protocol.impl.AppRoutingDataImpl;
12 import ca.uhn.hl7v2.protocol.impl.ApplicationRouterImpl;
13 import ca.uhn.hl7v2.protocol.impl.HL7Server;
14 import ca.uhn.hl7v2.protocol.impl.NullSafeStorage;
15
16 public class UpgradeToHapi2_1 {
17
18
19
20
21 public static void main(String[] args) {
22
23 }
24
25 @SuppressWarnings("unused")
26 private void oldWay() throws IOException {
27
28
29
30 ApplicationRouterImpluterImpl.html#ApplicationRouterImpl">ApplicationRouterImpl router = new ApplicationRouterImpl();
31 AppRoutingDataImplmpl.html#AppRoutingDataImpl">AppRoutingDataImpl routingData = new AppRoutingDataImpl("*", "*", "*", "*");
32
33
34 MyReceivingApplication application = new MyReceivingApplication();
35 router.bindApplication(routingData, application);
36
37
38 ServerSocket socket = new ServerSocket(8888);
39 NullSafeStorageStorage.html#NullSafeStorage">NullSafeStorage storage = new NullSafeStorage();
40 HL7Servererver.html#HL7Server">HL7Server hl7Server = new HL7Server(socket, router, storage);
41 hl7Server.start(null);
42
43
44 }
45
46 @SuppressWarnings("unused")
47 private void newWay() {
48
49
50
51 DefaultHapiContextml#DefaultHapiContext">DefaultHapiContext ctx = new DefaultHapiContext();
52 HL7Service server = ctx.newServer(8888, false);
53
54
55 MyReceivingApplication application = new MyReceivingApplication();
56 server.registerApplication(application);
57
58
59 server.start();
60
61
62 }
63
64
65 public static class MyReceivingApplication implements ca.uhn.hl7v2.protocol.ReceivingApplication<Message> {
66
67 public Message../../../ca/uhn/hl7v2/model/Message.html#Message">Message processMessage(Message theMessage, Map<String, Object> theMetadata) throws HL7Exception {
68
69
70
71 try {
72 return theMessage.generateACK();
73 } catch (IOException e) {
74 throw new HL7Exception(e);
75 }
76 }
77
78 public boolean canProcess(Message theMessage) {
79 return true;
80 }
81
82 }
83
84
85
86
87 public static class MyApplication implements ca.uhn.hl7v2.app.Application {
88
89 public Message../../../ca/uhn/hl7v2/model/Message.html#Message">Message processMessage(Message theMessage) throws HL7Exception {
90
91 try {
92 return theMessage.generateACK();
93 } catch (IOException e) {
94 throw new HL7Exception(e);
95 }
96 }
97
98 public boolean canProcess(Message theMessage) {
99 return true;
100 }
101
102 }
103
104
105 }