View Javadoc

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