1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support.wsa;
14
15 import java.io.IOException;
16 import java.util.ArrayList;
17 import java.util.UUID;
18
19 import javax.xml.namespace.QName;
20
21 import org.apache.xmlbeans.XmlException;
22 import org.apache.xmlbeans.XmlObject;
23 import org.w3c.dom.DOMException;
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27 import org.w3c.dom.NodeList;
28 import org.w3c.dom.Text;
29
30 import com.eviware.soapui.SoapUI;
31 import com.eviware.soapui.config.AnonymousTypeConfig;
32 import com.eviware.soapui.config.MustUnderstandTypeConfig;
33 import com.eviware.soapui.config.WsaVersionTypeConfig;
34 import com.eviware.soapui.impl.wsdl.WsdlOperation;
35 import com.eviware.soapui.impl.wsdl.mock.WsdlMockRequest;
36 import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
37 import com.eviware.soapui.impl.wsdl.submit.transports.http.ExtendedHttpMethod;
38 import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils;
39 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
40 import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
41 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
42 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
43 import com.eviware.soapui.settings.WsaSettings;
44 import com.eviware.soapui.support.StringUtils;
45 import com.eviware.soapui.support.xml.XmlUtils;
46
47 /***
48 * WS Addressing-related utility-methods..
49 *
50 * @author dragica.soldo
51 */
52
53 public class WsaUtils {
54 public static final String WS_A_VERSION_200508 = "http://www.w3.org/2005/08/addressing";
55 public static final String WS_A_VERSION_200408 = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
56 public static final String WSAM_NAMESPACE = "http://www.w3.org/2007/05/addressing/metadata";
57
58 SoapVersion soapVersion;
59 WsdlOperation operation;
60 WsaBuilder builder;
61 XmlObject xmlContentObject;
62
63 Element envelopeElement;
64 String wsaVersionNameSpace;
65
66 String wsaPrefix = null;
67 String wsaVersionNamespaceOld = null;
68
69 String anonymousType;
70 String anonymousAddress;
71 String noneAddress;
72 String relationshipTypeReply;
73
74 String unspecifiedMessage;
75 String content;
76
77 XmlObject xmlHeaderObject;
78 ArrayList<Node> headerWsaElementList;
79 private final PropertyExpansionContext context;
80
81 public WsaUtils(String content, SoapVersion soapVersion,
82 WsdlOperation operation, PropertyExpansionContext context) {
83 this.soapVersion = soapVersion;
84 this.operation = operation;
85 this.content = content;
86 this.context = context;
87 try {
88 xmlContentObject = XmlObject.Factory.parse(content);
89 } catch (Exception e) {
90 SoapUI.logError(e);
91 }
92 }
93
94 private Element getHeader(WsaContainer wsaContainer) throws XmlException {
95
96
97 wsaVersionNameSpace = WS_A_VERSION_200508;
98 if (wsaContainer.getWsaConfig().getVersion().equals(
99 WsaVersionTypeConfig.X_200408.toString())) {
100 wsaVersionNameSpace = WS_A_VERSION_200408;
101 }
102 anonymousAddress = wsaVersionNameSpace + "/anonymous";
103 noneAddress = wsaVersionNameSpace + "/none";
104 relationshipTypeReply = wsaVersionNameSpace + "/reply";
105 unspecifiedMessage = wsaVersionNameSpace + "/unspecified";
106
107 anonymousType = wsaContainer.getOperation().getAnonymous();
108
109
110
111 if (anonymousType.equals(AnonymousTypeConfig.OPTIONAL.toString())) {
112 anonymousType = wsaContainer.getOperation().getInterface()
113 .getAnonymous();
114 }
115
116 Element header = (Element) SoapUtils.getHeaderElement(xmlContentObject,
117 soapVersion, true).getDomNode();
118
119 wsaPrefix = XmlUtils.findPrefixForNamespace(header,
120 WsaUtils.WS_A_VERSION_200508);
121 if (wsaPrefix != null) {
122 wsaVersionNamespaceOld = WsaUtils.WS_A_VERSION_200508;
123 } else {
124 wsaPrefix = XmlUtils.findPrefixForNamespace(header,
125 WsaUtils.WS_A_VERSION_200408);
126 if (wsaPrefix != null) {
127 wsaVersionNamespaceOld = WsaUtils.WS_A_VERSION_200408;
128 } else {
129 wsaPrefix = XmlUtils.findPrefixForNamespace(header,
130 WsaUtils.WS_A_VERSION_200508);
131 if (wsaPrefix != null) {
132 wsaVersionNamespaceOld = WsaUtils.WS_A_VERSION_200508;
133 } else {
134 wsaPrefix = XmlUtils.findPrefixForNamespace(header,
135 WsaUtils.WS_A_VERSION_200408);
136 if (wsaPrefix != null) {
137 wsaVersionNamespaceOld = WsaUtils.WS_A_VERSION_200408;
138 } else {
139 wsaPrefix = "wsa";
140 }
141 }
142 }
143 }
144 XmlObject[] envelope = xmlContentObject.selectChildren(soapVersion
145 .getEnvelopeQName());
146 envelopeElement = (Element) envelope[0].getDomNode();
147
148 Boolean mustUnderstand = null;
149 if (wsaContainer.getWsaConfig().getMustUnderstand().equals(
150 MustUnderstandTypeConfig.FALSE.toString())) {
151 mustUnderstand = false;
152 } else if (wsaContainer.getWsaConfig().getMustUnderstand().equals(
153 MustUnderstandTypeConfig.TRUE.toString())) {
154 mustUnderstand = true;
155 }
156
157 builder = new WsaBuilder(wsaVersionNameSpace, mustUnderstand);
158
159 return header;
160
161 }
162
163 private Node getWsaProperty(Element header, String elementLocalName) {
164 NodeList elmList = header.getElementsByTagName(elementLocalName);
165
166
167 Node elm = null;
168 if (elmList.getLength() > 0) {
169 elm = elmList.item(0);
170 }
171 return elm;
172
173 }
174
175 private Element removeWsaProperty(boolean overrideExisting, Element header,
176 String elementLocalName) {
177 if (overrideExisting) {
178 NodeList elmList = header.getElementsByTagName(elementLocalName);
179 Node elm = null;
180 if (elmList.getLength() > 0) {
181 elm = elmList.item(0);
182 }
183 if (elm != null) {
184 header.removeChild(elm);
185 }
186 }
187 return header;
188 }
189
190 /***
191 * Processing ws-a property
192 *
193 * @param header -
194 * header element to add wsa to
195 * @param override -
196 * indicates if existing parameters should be overriden with new
197 * values
198 * @param elementLocalName -
199 * property string to add, for instance: any:Action, or
200 * any:ReplyTo
201 * @param wsaPropValue -
202 * wsa property value, inserted in input box, or default
203 * generated
204 * @param address -
205 * indicates if property is an endpoint reference, i.e. if it has
206 * <address> tag inside itself
207 * @param refParamsContent -
208 * the content of ReferenceParameters for specific endpoint
209 * reference, null if property is an absolute IRI
210 */
211 private Element processWsaProperty(Element header, boolean override,
212 String elementLocalName, String wsaPropValue, boolean address,
213 String refParamsContent) {
214 boolean existsWsa = getWsaProperty(header, elementLocalName) != null ? true
215 : false;
216 if (override) {
217 if (existsWsa) {
218 header = removeWsaProperty(override, header, elementLocalName);
219 }
220 if (address) {
221 header.appendChild(builder.createWsaAddressChildElement(
222 elementLocalName, envelopeElement, wsaPropValue,
223 refParamsContent));
224 } else {
225 header.appendChild(builder.createWsaChildElement(
226 elementLocalName, envelopeElement, wsaPropValue));
227 }
228
229 } else if (!existsWsa) {
230 if (address) {
231 header.appendChild(builder.createWsaAddressChildElement(
232 elementLocalName, envelopeElement, wsaPropValue,
233 refParamsContent));
234 } else {
235 header.appendChild(builder.createWsaChildElement(
236 elementLocalName, envelopeElement, wsaPropValue));
237 }
238 }
239 return header;
240 }
241
242 private Element processWsaProperty(Element header, boolean override,
243 String elementLocalName, String wsaPropValue, boolean address) {
244 return processWsaProperty(header, override, elementLocalName,
245 wsaPropValue, address, null);
246 }
247
248 private Element processWsaRelatesToProperty(Element header,
249 boolean override, String elementLocalName, String relationshipType,
250 String relatesTo) {
251 boolean existsWsa = getWsaProperty(header, elementLocalName) != null ? true
252 : false;
253 if (override) {
254 if (existsWsa) {
255 header = removeWsaProperty(override, header, elementLocalName);
256 }
257 header.appendChild(builder.createRelatesToElement(wsaPrefix
258 + ":RelatesTo", envelopeElement, relationshipType,
259 relatesTo));
260 } else if (!existsWsa) {
261 header.appendChild(builder.createRelatesToElement(wsaPrefix
262 + ":RelatesTo", envelopeElement, relationshipType,
263 relatesTo));
264 }
265 return header;
266 }
267
268 public String removeWSAddressing(WsaContainer wsaContainer) {
269 try {
270 Element header = getHeader(wsaContainer);
271 NodeList headerProps = XmlUtils.getChildElements(header);
272 for (int i = 0; i < headerProps.getLength(); i++) {
273 Node headerChild = headerProps.item(i);
274 if (headerChild.getNamespaceURI().equals(wsaVersionNameSpace)) {
275 header.removeChild(headerChild);
276 }
277 }
278 content = xmlContentObject.xmlText();
279 } catch (XmlException e) {
280 SoapUI.logError(e);
281 }
282 return content;
283 }
284
285 public String addWSAddressingRequest(WsaContainer wsaContainer) {
286 return addWSAddressingRequest(wsaContainer, null);
287 }
288
289 public String addWSAddressingRequest(WsaContainer wsaContainer,
290 ExtendedHttpMethod httpMethod) {
291 return createNewWSAddressingRequest(wsaContainer, httpMethod, SoapUI
292 .getSettings()
293 .getBoolean(WsaSettings.OVERRIDE_EXISTING_HEADERS));
294 }
295
296 private String createNewWSAddressingRequest(WsaContainer wsaContainer,
297 ExtendedHttpMethod httpMethod, boolean override) {
298 try {
299 Element header = getHeader(wsaContainer);
300
301 if (override || wsaVersionNamespaceOld == null) {
302 header.setAttribute("xmlns:" + wsaPrefix, wsaVersionNameSpace);
303 }
304
305 String action = null;
306 if (wsaContainer.getWsaConfig().isAddDefaultAction()) {
307 action = WsdlUtils.getDefaultWsaAction(wsaContainer
308 .getOperation(), false);
309 } else {
310 action = PropertyExpansionUtils.expandProperties(context,
311 wsaContainer.getWsaConfig().getAction());
312 }
313 if (!StringUtils.isNullOrEmpty(action)) {
314 header = processWsaProperty(header, override, wsaPrefix
315 + ":Action", action, false);
316 }
317
318 String replyTo = PropertyExpansionUtils.expandProperties(context,
319 wsaContainer.getWsaConfig().getReplyTo());
320 String replyToRefParams = PropertyExpansionUtils.expandProperties(
321 context, wsaContainer.getWsaConfig().getReplyToRefParams());
322 if (AnonymousTypeConfig.REQUIRED.toString().equals(anonymousType))
323
324
325
326
327
328 {
329 header = processWsaProperty(header, override, wsaPrefix
330 + ":ReplyTo", anonymousAddress, true, replyToRefParams);
331 } else if (!StringUtils.isNullOrEmpty(replyTo)) {
332 if (!(AnonymousTypeConfig.PROHIBITED.toString().equals(
333 anonymousType) && isAnonymousAddress(replyTo,
334 wsaVersionNameSpace))) {
335 header = processWsaProperty(header, override, wsaPrefix
336 + ":ReplyTo", replyTo, true, replyToRefParams);
337 }
338 }
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357 String from = PropertyExpansionUtils.expandProperties(context,
358 wsaContainer.getWsaConfig().getFrom());
359 if (!StringUtils.isNullOrEmpty(from)) {
360 header = processWsaProperty(header, override, wsaPrefix
361 + ":From", from, true);
362 }
363 String faultTo = PropertyExpansionUtils.expandProperties(context,
364 wsaContainer.getWsaConfig().getFaultTo());
365 String faultToRefParams = PropertyExpansionUtils.expandProperties(
366 context, wsaContainer.getWsaConfig().getFaultToRefParams());
367 if (!StringUtils.isNullOrEmpty(faultTo)) {
368 header = processWsaProperty(header, override, wsaPrefix
369 + ":FaultTo", faultTo, true, faultToRefParams);
370 }
371
372 String relatesTo = PropertyExpansionUtils.expandProperties(context,
373 wsaContainer.getWsaConfig().getRelatesTo());
374 String relationshipType = PropertyExpansionUtils.expandProperties(
375 context, wsaContainer.getWsaConfig().getRelationshipType());
376 if (!StringUtils.isNullOrEmpty(relationshipType)
377 && !StringUtils.isNullOrEmpty(relatesTo)) {
378 header = processWsaRelatesToProperty(header, override,
379 wsaPrefix + ":RelatesTo", relationshipType, relatesTo);
380 }
381
382 if (wsaContainer.getWsaConfig().isGenerateMessageId()) {
383 String generatedMessageId = UUID.randomUUID().toString();
384 header = processWsaProperty(header, override, wsaPrefix
385 + ":MessageID", generatedMessageId, false);
386 } else {
387 String msgId = PropertyExpansionUtils.expandProperties(context,
388 wsaContainer.getWsaConfig().getMessageID());
389 if (!StringUtils.isNullOrEmpty(msgId)) {
390 header = processWsaProperty(header, override, wsaPrefix
391 + ":MessageID", msgId, false);
392 }
393 }
394
395 if (httpMethod != null
396 && wsaContainer.getWsaConfig().isAddDefaultTo()) {
397 String defaultTo = httpMethod.getURI().toString();
398 header = processWsaProperty(header, override,
399 wsaPrefix + ":To", defaultTo, false);
400 } else {
401 String to = PropertyExpansionUtils.expandProperties(context,
402 wsaContainer.getWsaConfig().getTo());
403 if (!StringUtils.isNullOrEmpty(to)) {
404 header = processWsaProperty(header, override, wsaPrefix
405 + ":To", to, false);
406 }
407 }
408 content = xmlContentObject.xmlText();
409 } catch (Exception e) {
410 SoapUI.logError(e);
411 }
412
413 return content;
414 }
415
416 /***
417 * Adds ws-a headers to mock response from editor-menu in this case there is
418 * no request included and only values from ws-a inspector, if any, are used
419 *
420 * @param wsaContainer
421 * @return
422 */
423 public String addWSAddressingMockResponse(WsaContainer wsaContainer) {
424 return addWSAddressingMockResponse(wsaContainer, null);
425 }
426
427 public String addWSAddressingMockResponse(WsaContainer wsaContainer,
428 WsdlMockRequest request) {
429 return createWSAddressingMockResponse(wsaContainer, request, SoapUI
430 .getSettings()
431 .getBoolean(WsaSettings.OVERRIDE_EXISTING_HEADERS));
432 }
433
434 private String createWSAddressingMockResponse(WsaContainer wsaContainer,
435 WsdlMockRequest request, boolean override) {
436 try {
437 Element header = getHeader(wsaContainer);
438
439 if (override || wsaVersionNamespaceOld == null) {
440 header.setAttribute("xmlns:" + wsaPrefix, wsaVersionNameSpace);
441 }
442
443 String action = null;
444 if (wsaContainer.getWsaConfig().isAddDefaultAction()) {
445 action = WsdlUtils.getDefaultWsaAction(wsaContainer
446 .getOperation(), true);
447 } else {
448 action = PropertyExpansionUtils.expandProperties(context,
449 wsaContainer.getWsaConfig().getAction());
450 }
451 if (!StringUtils.isNullOrEmpty(action)) {
452 header = processWsaProperty(header, override, wsaPrefix
453 + ":Action", action, false);
454 }
455
456 if (AnonymousTypeConfig.REQUIRED.toString().equals(anonymousType)) {
457 header = processWsaProperty(header, override, wsaPrefix
458 + ":ReplyTo", anonymousAddress, true);
459 } else {
460 String replyTo = PropertyExpansionUtils.expandProperties(
461 context, wsaContainer.getWsaConfig().getReplyTo());
462 String replyToRefParams = PropertyExpansionUtils
463 .expandProperties(context, wsaContainer.getWsaConfig()
464 .getReplyToRefParams());
465 if (!StringUtils.isNullOrEmpty(replyTo)) {
466 header = processWsaProperty(header, override, wsaPrefix
467 + ":ReplyTo", replyTo, true, replyToRefParams);
468 }
469 }
470
471 Element requestHeader = null;
472 if (request != null) {
473 XmlObject requestXmlObject = request.getRequestXmlObject();
474
475 String requestWsaVersionNameSpace = WsaValidator.getWsaVersion(
476 requestXmlObject, request.getSoapVersion());
477
478 requestHeader = (Element) SoapUtils.getHeaderElement(
479 requestXmlObject, request.getSoapVersion(), true)
480 .getDomNode();
481
482
483 Element msgNode = XmlUtils.getFirstChildElementNS(
484 requestHeader, requestWsaVersionNameSpace, "MessageID");
485 String requestMessageId = null;
486 if (msgNode != null) {
487 requestMessageId = XmlUtils.getElementText(msgNode);
488 }
489
490 String from = PropertyExpansionUtils.expandProperties(context,
491 wsaContainer.getWsaConfig().getFrom());
492 if (!StringUtils.isNullOrEmpty(from)) {
493 header = processWsaProperty(header, override, wsaPrefix
494 + ":From", from, true);
495 }
496 String faultTo = PropertyExpansionUtils.expandProperties(
497 context, wsaContainer.getWsaConfig().getFaultTo());
498 String faultToRefParams = PropertyExpansionUtils
499 .expandProperties(context, wsaContainer.getWsaConfig()
500 .getFaultToRefParams());
501 if (!StringUtils.isNullOrEmpty(faultTo)) {
502 header = processWsaProperty(header, override, wsaPrefix
503 + ":FaultTo", faultTo, true, faultToRefParams);
504 }
505
506 String relationshipType = PropertyExpansionUtils
507 .expandProperties(context, wsaContainer.getWsaConfig()
508 .getRelationshipType());
509 if (!StringUtils.isNullOrEmpty(relationshipType)) {
510 if (!StringUtils.isNullOrEmpty(requestMessageId)) {
511 header = processWsaRelatesToProperty(header, override,
512 wsaPrefix + ":RelatesTo", relationshipType,
513 requestMessageId);
514 } else if (SoapUI.getSettings().getBoolean(
515 WsaSettings.USE_DEFAULT_RELATES_TO)) {
516
517
518 header = processWsaRelatesToProperty(header, override,
519 wsaPrefix + ":RelatesTo", relationshipType,
520 unspecifiedMessage);
521 }
522 } else if (wsaContainer instanceof WsdlMockResponse) {
523 if (SoapUI.getSettings().getBoolean(
524 WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE)) {
525 if (!StringUtils.isNullOrEmpty(requestMessageId)) {
526 header = processWsaRelatesToProperty(header,
527 override, wsaPrefix + ":RelatesTo",
528 relationshipTypeReply, requestMessageId);
529 } else if (SoapUI.getSettings().getBoolean(
530 WsaSettings.USE_DEFAULT_RELATES_TO)) {
531
532
533 header = processWsaRelatesToProperty(header,
534 override, wsaPrefix + ":RelatesTo",
535 relationshipTypeReply, unspecifiedMessage);
536 }
537 }
538 }
539
540
541 Element replyToNode = XmlUtils.getFirstChildElementNS(
542 requestHeader, requestWsaVersionNameSpace, "ReplyTo");
543 String requestReplyToValue = null;
544 if (replyToNode != null) {
545 Element replyToAddresseNode = XmlUtils
546 .getFirstChildElementNS(replyToNode,
547 requestWsaVersionNameSpace, "Address");
548 if (replyToAddresseNode != null) {
549 requestReplyToValue = XmlUtils
550 .getElementText(replyToAddresseNode);
551 }
552 }
553
554 String to = PropertyExpansionUtils.expandProperties(context,
555 wsaContainer.getWsaConfig().getTo());
556 if (!StringUtils.isNullOrEmpty(to)) {
557 if (!(AnonymousTypeConfig.PROHIBITED.toString().equals(
558 anonymousType) && isAnonymousAddress(to,
559 wsaVersionNameSpace))) {
560 header = processWsaProperty(header, override, wsaPrefix
561 + ":To", to, false);
562 }
563 } else {
564
565
566 if (!StringUtils.isNullOrEmpty(requestReplyToValue)) {
567
568
569
570 if (!(AnonymousTypeConfig.PROHIBITED.toString().equals(
571 anonymousType) && isAnonymousAddress(
572 requestReplyToValue, wsaVersionNameSpace))) {
573 header = processWsaProperty(header, override,
574 wsaPrefix + ":To", requestReplyToValue,
575 false);
576 }
577 }
578 }
579 } else {
580 String to = PropertyExpansionUtils.expandProperties(context,
581 wsaContainer.getWsaConfig().getTo());
582 if (!StringUtils.isNullOrEmpty(to)) {
583
584
585
586
587 header = processWsaProperty(header, override, wsaPrefix
588 + ":To", to, false);
589 }
590
591 String relationshipType = PropertyExpansionUtils
592 .expandProperties(context, wsaContainer.getWsaConfig()
593 .getRelationshipType());
594 String relatesTo = PropertyExpansionUtils.expandProperties(
595 context, wsaContainer.getWsaConfig().getRelatesTo());
596 if (!StringUtils.isNullOrEmpty(relationshipType)
597 && !StringUtils.isNullOrEmpty(relatesTo)) {
598 header = processWsaRelatesToProperty(header, override,
599 wsaPrefix + ":RelatesTo", relationshipType,
600 relatesTo);
601 } else if (wsaContainer instanceof WsdlMockResponse) {
602 if (SoapUI.getSettings().getBoolean(
603 WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE)) {
604 if (!StringUtils.isNullOrEmpty(relatesTo)) {
605 header = processWsaRelatesToProperty(header,
606 override, wsaPrefix + ":RelatesTo",
607 relationshipTypeReply, relatesTo);
608 } else if (SoapUI.getSettings().getBoolean(
609 WsaSettings.USE_DEFAULT_RELATES_TO)) {
610 header = processWsaRelatesToProperty(header,
611 override, wsaPrefix + ":RelatesTo",
612 relationshipTypeReply, unspecifiedMessage);
613 }
614 }
615 }
616
617 }
618
619 if (wsaContainer.getWsaConfig().isGenerateMessageId()) {
620 String generatedMessageId = UUID.randomUUID().toString();
621 header = processWsaProperty(header, override, wsaPrefix
622 + ":MessageID", generatedMessageId, false);
623 } else {
624 String msgId = PropertyExpansionUtils.expandProperties(context,
625 wsaContainer.getWsaConfig().getMessageID());
626 if (!StringUtils.isNullOrEmpty(msgId)) {
627 header = processWsaProperty(header, override, wsaPrefix
628 + ":MessageID", msgId, false);
629 }
630 }
631
632 content = xmlContentObject.xmlText();
633 } catch (XmlException e) {
634 SoapUI.logError(e);
635 }
636
637 return content;
638 }
639
640 public class WsaBuilder {
641 private final String wsaVersionNameSpace;
642 private final Boolean mustUnderstand;
643
644 public WsaBuilder(String wsaVersionNameSpace, Boolean mustUnderstand) {
645
646 this.wsaVersionNameSpace = wsaVersionNameSpace;
647 this.mustUnderstand = mustUnderstand;
648 }
649
650 public Element createWsaChildElement(String elementName,
651 Element addToElement, String wsaProperty) {
652 Element wsaElm = addToElement.getOwnerDocument().createElementNS(
653 wsaVersionNameSpace, elementName);
654 Text txtElm = addToElement.getOwnerDocument().createTextNode(
655 wsaProperty);
656 if (mustUnderstand != null) {
657 wsaElm.setAttributeNS(soapVersion.getEnvelopeNamespace(),
658 "mustUnderstand", mustUnderstand ? "1" : "0");
659 }
660 wsaElm.appendChild(txtElm);
661 return wsaElm;
662 }
663
664 public Element createWsaAddressChildElement(String elementName,
665 Element addToElement, String wsaProperty,
666 String refParamsContent) {
667 Document document = addToElement.getOwnerDocument();
668 Element wsAddressElm = document.createElementNS(
669 wsaVersionNameSpace, wsaPrefix + ":Address");
670 Element wsaElm = document.createElementNS(wsaVersionNameSpace,
671 elementName);
672 Text propertyContent = document.createTextNode(wsaProperty);
673 if (mustUnderstand != null) {
674 wsaElm.setAttributeNS(soapVersion.getEnvelopeNamespace(),
675 "mustUnderstand", mustUnderstand ? "1" : "0");
676 }
677 wsAddressElm.appendChild(propertyContent);
678 wsaElm.appendChild(wsAddressElm);
679
680 try {
681 if (refParamsContent != null) {
682
683
684 Element refParamsElm = document.createElementNS(
685 wsaVersionNameSpace, wsaPrefix
686 + ":ReferenceParameters");
687 refParamsContent = "<dummy>" + refParamsContent
688 + "</dummy>";
689 Node xx = document.importNode(XmlUtils.parseXml(
690 refParamsContent).getDocumentElement(), true);
691 NodeList xxList = xx.getChildNodes();
692
693
694 for (int i = 0; i < xxList.getLength(); i++) {
695 refParamsElm.appendChild(xxList.item(i));
696 }
697 wsaElm.appendChild(refParamsElm);
698 }
699 } catch (DOMException e) {
700
701 e.printStackTrace();
702 } catch (IOException e) {
703
704 e.printStackTrace();
705 }
706 return wsaElm;
707 }
708
709 public Element createRelatesToElement(String elementName,
710 Element addToElement, String relationshipType, String relatesTo) {
711 Element wsaElm = addToElement.getOwnerDocument().createElementNS(
712 wsaVersionNameSpace, elementName);
713 wsaElm.setAttribute("RelationshipType", relationshipType);
714 Text txtElm = addToElement.getOwnerDocument().createTextNode(
715 relatesTo);
716 if (mustUnderstand != null) {
717 wsaElm.setAttributeNS(soapVersion.getEnvelopeNamespace(),
718 "mustUnderstand", mustUnderstand ? "1" : "0");
719 }
720 wsaElm.appendChild(txtElm);
721 return wsaElm;
722 }
723 }
724
725 public static boolean isAnonymousAddress(String address,
726 String wsaVersionNamespace) {
727 return (address.equals(wsaVersionNamespace + "/anonymous")) ? true
728 : false;
729 }
730
731 public static boolean isNoneAddress(String address,
732 String wsaVersionNamespace) {
733 return (address.equals(wsaVersionNamespace + "/none")) ? true : false;
734 }
735
736 }