1 | |
package ca.uhn.hl7v2.hoh.hapi.server; |
2 | |
|
3 | |
import java.util.HashMap; |
4 | |
|
5 | |
import ca.uhn.hl7v2.HL7Exception; |
6 | |
import ca.uhn.hl7v2.hoh.api.IMessageHandler; |
7 | |
import ca.uhn.hl7v2.hoh.api.IReceivable; |
8 | |
import ca.uhn.hl7v2.hoh.api.IResponseSendable; |
9 | |
import ca.uhn.hl7v2.hoh.api.MessageProcessingException; |
10 | |
import ca.uhn.hl7v2.hoh.raw.api.RawSendable; |
11 | |
import ca.uhn.hl7v2.hoh.raw.server.HohRawServlet; |
12 | |
import ca.uhn.hl7v2.model.Message; |
13 | |
import ca.uhn.hl7v2.protocol.ApplicationRouter; |
14 | |
import ca.uhn.hl7v2.protocol.ReceivingApplication; |
15 | |
import ca.uhn.hl7v2.protocol.Transportable; |
16 | |
import ca.uhn.hl7v2.protocol.impl.AppRoutingDataImpl; |
17 | |
import ca.uhn.hl7v2.protocol.impl.ApplicationRouterImpl; |
18 | |
import ca.uhn.hl7v2.protocol.impl.TransportableImpl; |
19 | |
|
20 | 20 | public class HohServlet extends HohRawServlet { |
21 | |
|
22 | |
private static final long serialVersionUID = 1L; |
23 | |
private ApplicationRouter myApplicationRouter; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 20 | public HohServlet() { |
29 | 20 | super.setMessageHandler(new MessageHandlerImpl()); |
30 | 20 | } |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public void setApplication(ReceivingApplication<? extends Message> theApplication) { |
41 | 20 | myApplicationRouter = new ApplicationRouterImpl(); |
42 | 20 | myApplicationRouter.bindApplication(new AppRoutingDataImpl("*", "*", "*", "*"), theApplication); |
43 | 20 | } |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public void setApplicationRouter(ApplicationRouter theApplicationRouter) { |
55 | 0 | myApplicationRouter = theApplicationRouter; |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Override |
62 | |
public void setMessageHandler(IMessageHandler<String> theMessageHandler) { |
63 | 0 | throw new UnsupportedOperationException(); |
64 | |
} |
65 | |
|
66 | 40 | private class MessageHandlerImpl implements IMessageHandler<String> { |
67 | |
|
68 | |
public IResponseSendable<String> messageReceived(IReceivable<String> theMessage) throws MessageProcessingException { |
69 | |
|
70 | 20 | Transportable received = new TransportableImpl(theMessage.getMessage(), new HashMap<String, Object>(theMessage.getMetadata())); |
71 | |
Transportable response; |
72 | |
try { |
73 | 20 | response = myApplicationRouter.processMessage(received); |
74 | 0 | } catch (HL7Exception e) { |
75 | 0 | throw new MessageProcessingException(e); |
76 | 20 | } |
77 | |
|
78 | 20 | return new RawSendable(response.getMessage()); |
79 | |
} |
80 | |
|
81 | |
} |
82 | |
|
83 | |
} |