1 package ca.uhn.hl7v2.examples.hoh;
2
3 import java.io.IOException;
4 import java.util.Map;
5
6 import ca.uhn.hl7v2.HL7Exception;
7 import ca.uhn.hl7v2.hoh.hapi.server.HohServlet;
8 import ca.uhn.hl7v2.model.Message;
9 import ca.uhn.hl7v2.protocol.ReceivingApplication;
10 import ca.uhn.hl7v2.protocol.ReceivingApplicationException;
11 import jakarta.servlet.ServletConfig;
12
13
14
15
16
17 public class ExampleHl7OverHttpServletWithOneApplication extends HohServlet {
18
19
20
21
22 @Override
23 public void init(ServletConfig theConfig) {
24
25
26
27
28 setApplication(new MyApplication());
29
30 }
31
32
33
34
35 private static class MyApplication implements ReceivingApplication<Message>
36 {
37
38
39
40
41
42
43
44
45
46 @Override
47 public Message../../../ca/uhn/hl7v2/model/Message.html#Message">Message processMessage(Message theMessage, Map<String, Object> theMetadata) throws ReceivingApplicationException, HL7Exception {
48 System.out.println("Received message:\n" + theMessage.encode());
49
50
51
52
53
54
55 Message response;
56 try {
57 response = theMessage.generateACK();
58 } catch (IOException e) {
59 throw new ReceivingApplicationException(e);
60 }
61
62
63
64
65
66
67
68 boolean somethingFailed = false;
69
70 return response;
71 }
72
73
74
75
76 @Override
77 public boolean canProcess(Message theMessage) {
78 return true;
79 }
80
81 }
82
83 }