1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.client.samples.notification;
15
16 import java.io.IOException;
17
18 import javax.servlet.ServletException;
19 import javax.servlet.http.HttpServlet;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import javax.servlet.http.HttpSession;
23
24 import uk.nhs.interoperability.infrastructure.ITKAddress;
25 import uk.nhs.interoperability.infrastructure.ITKAddressImpl;
26 import uk.nhs.interoperability.infrastructure.ITKIdentity;
27 import uk.nhs.interoperability.infrastructure.ITKIdentityImpl;
28 import uk.nhs.interoperability.infrastructure.ITKMessageProperties;
29 import uk.nhs.interoperability.infrastructure.ITKMessagePropertiesImpl;
30 import uk.nhs.interoperability.infrastructure.ITKMessagingException;
31 import uk.nhs.interoperability.payload.ITKMessage;
32 import uk.nhs.interoperability.payload.SimpleMessage;
33 import uk.nhs.interoperability.source.ITKMessageSender;
34 import uk.nhs.interoperability.source.ITKMessageSenderImpl;
35 import uk.nhs.interoperability.util.Logger;
36
37
38
39
40
41
42
43 public class NotificationSenderServlet extends HttpServlet {
44
45
46 private static final long serialVersionUID = 1L;
47
48
49 private static final String ORGID = "urn:nhs-uk:identity:ods:TESTORGS:ORGA";
50
51
52 private static final ITKIdentity AUDITID = new ITKIdentityImpl(ORGID);
53
54
55 private static final String FROMADDRESS = "urn:nhs-uk:addressing:ods:R59:oncology";
56
57
58 private static final String NOTIFICATION_SERVICENAME = "urn:nhs-itk:services:201005:SendEventNotification-v1-0";
59
60
61 private static final String NOTIFICATION_PROFILEID = "urn:nhs-en:profile:EventNotification-v1-0";
62
63
64
65
66
67 public NotificationSenderServlet() {
68 super();
69 }
70
71
72
73
74 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
75 processRequest(request, response);
76 }
77
78
79
80
81 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
82 processRequest(request, response);
83 }
84
85
86
87
88
89
90
91
92
93 private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
94
95 Logger.debug("this is NotificationSenderServlet.processRequest");
96 String messageId = request.getParameter("messageId");
97 String nhsNumber = request.getParameter("nhsNumber");
98 String dateOfBirth = request.getParameter("dateOfBirth");
99
100 String senderOrg = request.getParameter("senderOrg");
101 String recipientOrg = request.getParameter("recipientOrg");
102 String recipientAddress = request.getParameter("recipientAddress");
103 String patientName = request.getParameter("patientName");
104 String patientAddress = request.getParameter("patientAddress");
105 String contactName = request.getParameter("contactName");
106 String contactAddress = request.getParameter("contactAddress");
107 String contactOrg = request.getParameter("contactOrg");
108
109 String businessAckRequired = request.getParameter("businessAckRequired");
110 String serviceAddress = request.getParameter("serviceAddress");
111 ITKAddress itkServiceAddress = new ITKAddressImpl(serviceAddress);
112
113 HttpSession session = request.getSession(true);
114 session.removeAttribute("errorMessage");
115 session.removeAttribute("outcomeMessage");
116 session.removeAttribute("responseMessage");
117
118 Notification n = new Notification();
119 n.setMessageId(messageId);
120 n.setNHSNumber(nhsNumber);
121 n.setDateOfBirth(dateOfBirth);
122
123 n.setEffectiveTime("20121127151500+0000");
124 n.setSenderOrg(senderOrg);
125 n.setRecipientOrg(recipientOrg);
126 n.setRecipientAddress(recipientAddress);
127 n.setPatientName(patientName);
128 n.setPatientAddress(patientAddress);
129
130 n.setEventTypeCode("01");
131 n.setEventTypeDesc("DocumentEvent");
132
133 n.setContactName(contactName);
134 n.setContactAddress(contactAddress);
135 n.setContactOrg(contactOrg);
136
137
138 ITKMessage msg = new SimpleMessage();
139 msg.setBusinessPayload(n.serialise());
140
141
142 ITKMessageProperties mp = new ITKMessagePropertiesImpl();
143 mp.setAuditIdentity(AUDITID);
144 mp.setFromAddress(new ITKAddressImpl(FROMADDRESS));
145 mp.setToAddress(itkServiceAddress);
146 mp.setServiceId(NOTIFICATION_SERVICENAME);
147 mp.setBusinessPayloadId(n.getMessageId());
148 mp.setProfileId(NOTIFICATION_PROFILEID);
149
150 if (businessAckRequired.equalsIgnoreCase("Y")){
151 mp.addHandlingSpecification(ITKMessageProperties.BUSINESS_ACK_HANDLING_SPECIFICATION_KEY, "true");
152 }
153
154
155 msg.setMessageProperties(mp);
156
157
158 ITKMessageSender sender = new ITKMessageSenderImpl();
159
160 try {
161
162 sender.sendAsync(msg);
163
164 Logger.info("Notification Message Sent.");
165 session.setAttribute("outcomeMessage", "Notification Message Sent.");
166
167 } catch (ITKMessagingException e) {
168 Logger.error("Error Sending ITK Message",e);
169 session.setAttribute("errorMessage", "Sorry - I couldn't send the Notification this time.");
170 }
171
172 response.sendRedirect("./NotificationSent.jsp");
173
174 Logger.trace("*** NotificationSenderServlet: Ending send");
175 }
176
177 }