1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.infrastructure;
15
16 import javax.xml.xpath.XPathExpressionException;
17
18 import org.w3c.dom.Document;
19
20 import com.xmlsolutions.annotation.Requirement;
21
22 import uk.nhs.interoperability.transport.ITKTransportProperties;
23 import uk.nhs.interoperability.transport.ITKTransportRoute;
24 import uk.nhs.interoperability.transport.ITKTransportRouteImpl;
25 import uk.nhs.interoperability.transport.WS.SOAPUtils;
26 import uk.nhs.interoperability.util.Logger;
27 import uk.nhs.interoperability.util.xml.XPaths;
28
29
30
31
32
33
34
35
36 public class ITKTransportPropertiesImpl implements ITKTransportProperties {
37
38
39 private String transportFrom;
40
41
42 private String transportTo;
43
44
45 private String invokedUrl;
46
47
48 private String transportRelatesTo;
49
50
51 private String transportReplyTo;
52
53
54 private String transportFaultTo;
55
56
57 private String transportAction;
58
59
60 private String transportMessageId;
61
62
63 private String transportType;
64
65
66
67
68
69
70 public ITKTransportPropertiesImpl(String transportType) {
71 this.transportType = transportType;
72 }
73
74
75
76
77 public String getTransportFrom() {
78 return transportFrom;
79 }
80
81
82
83
84 public void setTransportFrom(String transportFrom) {
85 this.transportFrom = transportFrom;
86 }
87
88
89
90
91 public String getTransportTo() {
92 return transportTo;
93 }
94
95
96
97
98 public void setTransportTo(String transportTo) {
99 this.transportTo = transportTo;
100 }
101
102
103
104
105 public String getInvokedUrl() {
106 return invokedUrl;
107 }
108
109
110
111
112 public void setInvokedUrl(String invokedUrl) {
113 this.invokedUrl = invokedUrl;
114 }
115
116
117
118
119 public String getTransportRelatesTo() {
120 return transportRelatesTo;
121 }
122
123
124
125
126 public void setTransportRelatesTo(String transportRelatesTo) {
127 this.transportRelatesTo = transportRelatesTo;
128 }
129
130
131
132
133 public String getTransportReplyTo() {
134 return transportReplyTo;
135 }
136
137
138
139
140 public void setTransportReplyTo(String transportReplyTo) {
141 this.transportReplyTo = transportReplyTo;
142 }
143
144
145
146
147 public String getTransportFaultTo() {
148 return transportFaultTo;
149 }
150
151
152
153
154 public void setTransportFaultTo(String transportFaultTo) {
155 this.transportFaultTo = transportFaultTo;
156 }
157
158
159
160
161 public String getTransportAction() {
162 return transportAction;
163 }
164
165
166
167
168 public void setTransportAction(String transportAction) {
169 this.transportAction = transportAction;
170 }
171
172
173
174
175 @Requirement(traceTo="WS-ADR-01", status="implemented")
176 public String getTransportMessageId() {
177 return transportMessageId;
178 }
179
180
181
182
183 @Requirement(traceTo="WS-ADR-01", status="implemented")
184 public void setTransportMessageId(String transportMessageId) {
185 this.transportMessageId = transportMessageId;
186 }
187
188
189
190
191 @Override
192 public void setTransportType(String transportType) {
193 this.transportType = transportType;
194 }
195
196
197
198
199 @Override
200 public ITKTransportRoute getTransportFaultToRoute() {
201 String address = SOAPUtils.resolveFaultToAddress(this);
202 if (address != null) {
203 return new ITKTransportRouteImpl(this.transportType, address);
204 }
205 return null;
206 }
207
208
209
210
211 @Override
212 public ITKTransportRoute getTransportReplyToRoute() {
213 String address = SOAPUtils.resolveReplyToAddress(this);
214 Logger.trace("Reply to address " + address);
215 if (address != null) {
216 return new ITKTransportRouteImpl(this.transportType, address);
217 }
218 return null;
219 }
220
221
222
223
224
225
226
227
228 @Requirement(traceTo="WS-EXT-03", status="not-started")
229 public static ITKTransportProperties buildFromSoap(Document doc) throws ITKMessagingException {
230
231 ITKTransportProperties itkTransportProperties = new ITKTransportPropertiesImpl(ITKTransportRoute.HTTP_WS);
232
233 try {
234
235
236
237 String transportTo = XPaths.WSA_TO_XPATH.evaluate(doc);
238 if (transportTo.length()==0) {
239 Logger.warn("SOAP To Element not populated - message will be rejected");
240 throw new ITKMessagingException(ITKMessagingException.INVALID_MESSAGE_CODE,
241 "SOAP To Element not populated - message will be rejected" );
242 }
243
244
245 if (transportTo.toUpperCase().contains("INVALID")) {
246 Logger.warn("SOAP To Element is invalid - message will be rejected");
247 throw new ITKMessagingException(ITKMessagingException.INVALID_MESSAGE_CODE,
248 "SOAP To Element is invalid - message will be rejected" );
249 }
250
251
252 String transportAction = XPaths.WSA_ACTION_XPATH.evaluate(doc);
253 if (transportAction.length()==0) {
254 Logger.warn("SOAP Action Element not populated - message will be rejected");
255 throw new ITKMessagingException(ITKMessagingException.INVALID_MESSAGE_CODE,
256 "SOAP Action Element not populated - message will be rejected" );
257 }
258
259 String transportMessageId = XPaths.WSA_MSGID_XPATH.evaluate(doc);
260 String transportReplyTo = XPaths.WSA_REPLY_TO_XPATH.evaluate(doc);
261 String transportFaultTo = XPaths.WSA_FAULT_TO_XPATH.evaluate(doc);
262 String transportFrom = XPaths.WSA_FROM_XPATH.evaluate(doc);
263
264
265
266 String timestamp = XPaths.WSA_SECURITY_TIMESTAMP_XPATH.evaluate(doc);
267 if (timestamp.length()==0){
268 Logger.warn("SOAP Timestamp Element missing - message will be rejected");
269 throw new ITKMessagingException(ITKMessagingException.INVALID_MESSAGE_CODE,
270 "SOAP Timestamp Element missing - message will be rejected" );
271 }
272
273
274
275
276
277
278
279 String username = XPaths.WSA_SECURITY_USERNAME_XPATH.evaluate(doc);
280 if (username.length()==0){
281 Logger.warn("SOAP Username Element missing - message will be rejected");
282 throw new ITKMessagingException(ITKMessagingException.ACCESS_DENIED_CODE,
283 "SOAP Username Element missing - message will be rejected" );
284 }
285
286
287
288
289
290
291
292
293
294
295 if (username.toUpperCase().contains("IINVALID")){
296 Logger.warn("SOAP Username is invalid - message will be rejected");
297 throw new ITKMessagingException(ITKMessagingException.ACCESS_DENIED_CODE,
298 "SOAP Username is invalid - message will be rejected" );
299 }
300
301
302
303
304
305
306
307 itkTransportProperties.setTransportMessageId(transportMessageId);
308 itkTransportProperties.setTransportAction(transportAction);
309 itkTransportProperties.setTransportFrom(transportFrom);
310 itkTransportProperties.setTransportReplyTo(transportReplyTo);
311 itkTransportProperties.setTransportFaultTo(transportFaultTo);
312 itkTransportProperties.setTransportTo(transportTo);
313
314 Logger.debug(itkTransportProperties.toString());
315
316 return itkTransportProperties;
317
318 } catch (XPathExpressionException e) {
319 throw new ITKMessagingException(ITKMessagingException.PROCESSING_ERROR_NOT_RETRYABLE_CODE, "Could not extract values from request", e);
320 }
321 }
322
323
324
325
326 @Override
327 public String toString() {
328 return "[" + this.getClass().getCanonicalName() + "]"
329 + "\n\tMessage transport id " + this.getTransportMessageId()
330 + "\n\tMessage transport action " + this.getTransportAction()
331 + "\n\tMessage transport from " + this.getTransportFrom()
332 + "\n\tMessage transport to " + this.getTransportTo()
333 + "\n\tMessage transport replyTo " + this.getTransportReplyTo()
334 + "\n\tMessage transport faultTo " + this.getTransportFaultTo();
335 }
336 }