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.wsdl;
14  
15  import java.io.StringWriter;
16  import java.io.UnsupportedEncodingException;
17  import java.net.URLDecoder;
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.wsdl.Binding;
24  import javax.wsdl.BindingFault;
25  import javax.wsdl.BindingInput;
26  import javax.wsdl.BindingOperation;
27  import javax.wsdl.BindingOutput;
28  import javax.wsdl.Definition;
29  import javax.wsdl.Fault;
30  import javax.wsdl.Input;
31  import javax.wsdl.Message;
32  import javax.wsdl.Operation;
33  import javax.wsdl.Output;
34  import javax.wsdl.Part;
35  import javax.wsdl.Port;
36  import javax.wsdl.Service;
37  import javax.wsdl.WSDLException;
38  import javax.wsdl.extensions.AttributeExtensible;
39  import javax.wsdl.extensions.ElementExtensible;
40  import javax.wsdl.extensions.ExtensibilityElement;
41  import javax.wsdl.extensions.ExtensionDeserializer;
42  import javax.wsdl.extensions.ExtensionRegistry;
43  import javax.wsdl.extensions.UnknownExtensibilityElement;
44  import javax.wsdl.extensions.mime.MIMEContent;
45  import javax.wsdl.extensions.mime.MIMEMultipartRelated;
46  import javax.wsdl.extensions.mime.MIMEPart;
47  import javax.wsdl.extensions.soap.SOAPAddress;
48  import javax.wsdl.extensions.soap.SOAPBinding;
49  import javax.wsdl.extensions.soap.SOAPBody;
50  import javax.wsdl.extensions.soap.SOAPFault;
51  import javax.wsdl.extensions.soap.SOAPHeader;
52  import javax.wsdl.extensions.soap.SOAPOperation;
53  import javax.wsdl.extensions.soap12.SOAP12Address;
54  import javax.wsdl.extensions.soap12.SOAP12Binding;
55  import javax.wsdl.extensions.soap12.SOAP12Body;
56  import javax.wsdl.extensions.soap12.SOAP12Fault;
57  import javax.wsdl.extensions.soap12.SOAP12Header;
58  import javax.wsdl.extensions.soap12.SOAP12Operation;
59  import javax.wsdl.factory.WSDLFactory;
60  import javax.wsdl.xml.WSDLReader;
61  import javax.xml.namespace.QName;
62  
63  import org.apache.log4j.Logger;
64  import org.apache.xmlbeans.SchemaGlobalElement;
65  import org.apache.xmlbeans.SchemaType;
66  import org.apache.xmlbeans.XmlException;
67  import org.apache.xmlbeans.XmlObject;
68  import org.w3.x2007.x05.addressing.metadata.AddressingDocument.Addressing;
69  import org.w3.x2007.x05.addressing.metadata.AnonymousResponsesDocument.AnonymousResponses;
70  import org.w3c.dom.Document;
71  import org.w3c.dom.DocumentFragment;
72  import org.w3c.dom.Element;
73  import org.w3c.dom.Node;
74  import org.w3c.dom.NodeList;
75  import org.xml.sax.InputSource;
76  import org.xmlsoap.schemas.ws.x2004.x09.policy.OptionalType;
77  import org.xmlsoap.schemas.ws.x2004.x09.policy.Policy;
78  import org.xmlsoap.schemas.ws.x2004.x09.policy.PolicyDocument;
79  
80  import com.eviware.soapui.SoapUI;
81  import com.eviware.soapui.config.AnonymousTypeConfig;
82  import com.eviware.soapui.config.DefinitionCacheConfig;
83  import com.eviware.soapui.config.DefinitionCacheTypeConfig;
84  import com.eviware.soapui.config.DefintionPartConfig;
85  import com.eviware.soapui.config.WsaVersionTypeConfig;
86  import com.eviware.soapui.impl.support.definition.DefinitionLoader;
87  import com.eviware.soapui.impl.wsdl.WsdlInterface;
88  import com.eviware.soapui.impl.wsdl.WsdlOperation;
89  import com.eviware.soapui.impl.wsdl.WsdlRequest;
90  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
91  import com.eviware.soapui.impl.wsdl.support.Constants;
92  import com.eviware.soapui.impl.wsdl.support.policy.PolicyUtils;
93  import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils;
94  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
95  import com.eviware.soapui.impl.wsdl.support.wsa.WsaConfig;
96  import com.eviware.soapui.impl.wsdl.support.wsa.WsaUtils;
97  import com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils;
98  import com.eviware.soapui.settings.WsaSettings;
99  import com.eviware.soapui.support.StringUtils;
100 import com.eviware.soapui.support.types.StringList;
101 import com.eviware.soapui.support.xml.XmlUtils;
102 import com.ibm.wsdl.util.xml.QNameUtils;
103 import com.ibm.wsdl.xml.WSDLReaderImpl;
104 import com.ibm.wsdl.xml.WSDLWriterImpl;
105 
106 /***
107  * Wsdl-related tools
108  * 
109  * @author Ole.Matzura
110  */
111 
112 public class WsdlUtils
113 {
114 	private final static Logger log = Logger.getLogger(WsdlUtils.class);
115 	private static WSDLReader wsdlReader;
116 	private final static String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
117 	private final static String WSU_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
118 
119 	public static <T extends ExtensibilityElement> T getExtensiblityElement(List<?> list, Class<T> clazz)
120 	{
121 		List<T> elements = getExtensiblityElements(list, clazz);
122 		return elements.isEmpty() ? null : elements.get(0);
123 	}
124 
125 	public static <T extends ExtensibilityElement> List<T> getExtensiblityElements(List list, Class<T> clazz)
126 	{
127 		List<T> result = new ArrayList<T>();
128 
129 		for (Iterator<T> i = list.iterator(); i.hasNext();)
130 		{
131 			T elm = i.next();
132 			if (clazz.isAssignableFrom(elm.getClass()))
133 			{
134 				result.add(elm);
135 			}
136 		}
137 
138 		return result;
139 	}
140 
141 	public static Element[] getExentsibilityElements(ElementExtensible item, QName qname)
142 	{
143 		List<Element> result = new ArrayList<Element>();
144 
145 		List list = item.getExtensibilityElements();
146 		for (Iterator<?> i = list.iterator(); i.hasNext();)
147 		{
148 			ExtensibilityElement elm = (ExtensibilityElement) i.next();
149 			if (elm.getElementType().equals(qname) && elm instanceof UnknownExtensibilityElement)
150 			{
151 				result.add(((UnknownExtensibilityElement) elm).getElement());
152 			}
153 		}
154 
155 		return result.toArray(new Element[result.size()]);
156 	}
157 
158 	public static String[] getExentsibilityAttributes(AttributeExtensible item, QName qname)
159 	{
160 		StringList result = new StringList();
161 
162 		Map map = item.getExtensionAttributes();
163 
164 		for (Iterator<?> i = map.keySet().iterator(); i.hasNext();)
165 		{
166 			QName name = (QName) i.next();
167 			if (name.equals(qname))
168 			{
169 				result.add(map.get(name).toString());
170 			}
171 		}
172 
173 		return result.toStringArray();
174 	}
175 
176 	public static String getSoapAction(BindingOperation operation)
177 	{
178 		List list = operation.getExtensibilityElements();
179 		SOAPOperation soapOperation = WsdlUtils.getExtensiblityElement(list, SOAPOperation.class);
180 		if (soapOperation != null)
181 			return soapOperation.getSoapActionURI();
182 
183 		SOAP12Operation soap12Operation = WsdlUtils.getExtensiblityElement(list, SOAP12Operation.class);
184 		if (soap12Operation != null)
185 			return soap12Operation.getSoapActionURI();
186 
187 		return null;
188 	}
189 
190 	public static String[] getEndpointsForBinding(Definition definition, Binding binding)
191 	{
192 		List<String> result = new ArrayList<String>();
193 		Map map = definition.getAllServices();
194 		for (Iterator i = map.values().iterator(); i.hasNext();)
195 		{
196 			Service service = (Service) i.next();
197 			Map portMap = service.getPorts();
198 			for (Iterator i2 = portMap.values().iterator(); i2.hasNext();)
199 			{
200 				Port port = (Port) i2.next();
201 				if (port.getBinding() == binding)
202 				{
203 					String endpoint = WsdlUtils.getSoapEndpoint(port);
204 					if (endpoint != null)
205 						result.add(endpoint);
206 				}
207 			}
208 		}
209 
210 		return result.toArray(new String[result.size()]);
211 	}
212 
213 	public static Binding findBindingForOperation(Definition definition, BindingOperation bindingOperation)
214 	{
215 		Map services = definition.getAllServices();
216 		Iterator<Service> s = services.values().iterator();
217 
218 		while (s.hasNext())
219 		{
220 			Map ports = s.next().getPorts();
221 			Iterator<Port> p = ports.values().iterator();
222 			while (p.hasNext())
223 			{
224 				Binding binding = p.next().getBinding();
225 				List bindingOperations = binding.getBindingOperations();
226 				for (Iterator iter = bindingOperations.iterator(); iter.hasNext();)
227 				{
228 					BindingOperation op = (BindingOperation) iter.next();
229 					if (op.getName().equals(bindingOperation.getName()))
230 						return binding;
231 				}
232 			}
233 		}
234 
235 		Map bindings = definition.getAllBindings();
236 		Iterator<QName> names = bindings.keySet().iterator();
237 		while (names.hasNext())
238 		{
239 			Binding binding = definition.getBinding(names.next());
240 			List bindingOperations = binding.getBindingOperations();
241 			for (Iterator iter = bindingOperations.iterator(); iter.hasNext();)
242 			{
243 				BindingOperation op = (BindingOperation) iter.next();
244 				if (op.getName().equals(bindingOperation.getName()))
245 					return binding;
246 			}
247 		}
248 
249 		return null;
250 	}
251 
252 	public static BindingOperation findBindingOperation(Definition definition, String operationName)
253 	{
254 		Map services = definition.getAllServices();
255 		for (Iterator i = services.keySet().iterator(); i.hasNext();)
256 		{
257 			QName qName = (QName) i.next();
258 			Service service = definition.getService(qName);
259 			Map ports = service.getPorts();
260 
261 			for (Iterator iterator = ports.keySet().iterator(); iterator.hasNext();)
262 			{
263 				String key = (String) iterator.next();
264 				Port port = service.getPort(key);
265 				BindingOperation bindingOperation = port.getBinding().getBindingOperation(operationName, null, null);
266 				if (bindingOperation != null)
267 					return bindingOperation;
268 			}
269 		}
270 
271 		Map bindings = definition.getAllBindings();
272 		for (Iterator i = bindings.keySet().iterator(); i.hasNext();)
273 		{
274 			Object key = i.next();
275 			Binding binding = (Binding) bindings.get(key);
276 			BindingOperation bindingOperation = binding.getBindingOperation(operationName, null, null);
277 			if (bindingOperation != null)
278 				return bindingOperation;
279 		}
280 
281 		return null;
282 	}
283 
284 	public static boolean isInputSoapEncoded(BindingOperation bindingOperation)
285 	{
286 		if (bindingOperation == null)
287 			return false;
288 
289 		BindingInput bindingInput = bindingOperation.getBindingInput();
290 		if (bindingInput == null)
291 			return false;
292 
293 		SOAPBody soapBody = WsdlUtils.getExtensiblityElement(bindingInput.getExtensibilityElements(), SOAPBody.class);
294 
295 		if (soapBody != null)
296 		{
297 			return soapBody.getUse() != null
298 					&& soapBody.getUse().equalsIgnoreCase("encoded")
299 					&& (soapBody.getEncodingStyles() == null || soapBody.getEncodingStyles().contains(
300 							"http://schemas.xmlsoap.org/soap/encoding/"));
301 		}
302 
303 		SOAP12Body soap12Body = WsdlUtils.getExtensiblityElement(bindingInput.getExtensibilityElements(),
304 				SOAP12Body.class);
305 
306 		if (soap12Body != null)
307 		{
308 			return soap12Body.getUse() != null
309 					&& soap12Body.getUse().equalsIgnoreCase("encoded")
310 					&& (soap12Body.getEncodingStyle() == null || soap12Body.getEncodingStyle().equals(
311 							"http://schemas.xmlsoap.org/soap/encoding/"));
312 		}
313 
314 		return false;
315 	}
316 
317 	public static boolean isOutputSoapEncoded(BindingOperation bindingOperation)
318 	{
319 		if (bindingOperation == null)
320 			return false;
321 
322 		BindingOutput bindingOutput = bindingOperation.getBindingOutput();
323 		if (bindingOutput == null)
324 			return false;
325 
326 		SOAPBody soapBody = WsdlUtils.getExtensiblityElement(bindingOutput.getExtensibilityElements(), SOAPBody.class);
327 
328 		if (soapBody != null)
329 		{
330 			return soapBody.getUse() != null
331 					&& soapBody.getUse().equalsIgnoreCase("encoded")
332 					&& (soapBody.getEncodingStyles() == null || soapBody.getEncodingStyles().contains(
333 							"http://schemas.xmlsoap.org/soap/encoding/"));
334 		}
335 
336 		SOAP12Body soap12Body = WsdlUtils.getExtensiblityElement(bindingOutput.getExtensibilityElements(),
337 				SOAP12Body.class);
338 
339 		if (soap12Body != null)
340 		{
341 			return soap12Body.getUse() != null
342 					&& soap12Body.getUse().equalsIgnoreCase("encoded")
343 					&& (soap12Body.getEncodingStyle() == null || soap12Body.getEncodingStyle().equals(
344 							"http://schemas.xmlsoap.org/soap/encoding/"));
345 		}
346 
347 		return false;
348 	}
349 
350 	public static boolean isRpc(Definition definition, BindingOperation bindingOperation)
351 	{
352 		SOAPOperation soapOperation = WsdlUtils.getExtensiblityElement(bindingOperation.getExtensibilityElements(),
353 				SOAPOperation.class);
354 
355 		if (soapOperation != null && soapOperation.getStyle() != null)
356 			return soapOperation.getStyle().equalsIgnoreCase("rpc");
357 
358 		SOAP12Operation soap12Operation = WsdlUtils.getExtensiblityElement(bindingOperation.getExtensibilityElements(),
359 				SOAP12Operation.class);
360 
361 		if (soap12Operation != null && soap12Operation.getStyle() != null)
362 			return soap12Operation.getStyle().equalsIgnoreCase("rpc");
363 
364 		Binding binding = findBindingForOperation(definition, bindingOperation);
365 		if (binding == null)
366 		{
367 			log.error("Failed to find binding for operation [" + bindingOperation.getName() + "] in definition ["
368 					+ definition.getDocumentBaseURI() + "]");
369 			return false;
370 		}
371 
372 		return isRpc(binding);
373 	}
374 
375 	public static boolean isRpc(Binding binding)
376 	{
377 		SOAPBinding soapBinding = WsdlUtils.getExtensiblityElement(binding.getExtensibilityElements(), SOAPBinding.class);
378 
379 		if (soapBinding != null)
380 			return "rpc".equalsIgnoreCase(soapBinding.getStyle());
381 
382 		SOAP12Binding soap12Binding = WsdlUtils.getExtensiblityElement(binding.getExtensibilityElements(),
383 				SOAP12Binding.class);
384 
385 		if (soap12Binding != null)
386 			return "rpc".equalsIgnoreCase(soap12Binding.getStyle());
387 
388 		return false;
389 	}
390 
391 	/***
392 	 * Returns a list of parts for the specifed operation, either as specified in
393 	 * body or all
394 	 */
395 
396 	public static Part[] getInputParts(BindingOperation operation)
397 	{
398 		List<Part> result = new ArrayList<Part>();
399 		Input input = operation.getOperation().getInput();
400 		if (input == null)
401 			return new Part[0];
402 
403 		Message msg = input.getMessage();
404 
405 		if (msg != null)
406 		{
407 			SOAPBody soapBody = WsdlUtils.getExtensiblityElement(operation.getBindingInput().getExtensibilityElements(),
408 					SOAPBody.class);
409 
410 			if (soapBody == null || soapBody.getParts() == null)
411 			{
412 				SOAP12Body soap12Body = WsdlUtils.getExtensiblityElement(operation.getBindingInput()
413 						.getExtensibilityElements(), SOAP12Body.class);
414 
415 				if (soap12Body == null || soap12Body.getParts() == null)
416 				{
417 					if (msg != null)
418 						result.addAll(msg.getOrderedParts(null));
419 				}
420 				else
421 				{
422 					Iterator i = soap12Body.getParts().iterator();
423 					while (i.hasNext())
424 					{
425 						String partName = (String) i.next();
426 						Part part = msg.getPart(partName);
427 
428 						result.add(part);
429 					}
430 				}
431 			}
432 			else
433 			{
434 				Iterator i = soapBody.getParts().iterator();
435 				while (i.hasNext())
436 				{
437 					String partName = (String) i.next();
438 					Part part = msg.getPart(partName);
439 
440 					result.add(part);
441 				}
442 			}
443 		}
444 		else
445 		{
446 		}
447 
448 		return result.toArray(new Part[result.size()]);
449 	}
450 
451 	public static boolean isAttachmentInputPart(Part part, BindingOperation operation)
452 	{
453 		return getInputMultipartContent(part, operation).length > 0;
454 	}
455 
456 	public static boolean isAttachmentOutputPart(Part part, BindingOperation operation)
457 	{
458 		return getOutputMultipartContent(part, operation).length > 0;
459 	}
460 
461 	public static MIMEContent[] getOutputMultipartContent(Part part, BindingOperation operation)
462 	{
463 		MIMEMultipartRelated multipartOutput = WsdlUtils.getExtensiblityElement(operation.getBindingOutput()
464 				.getExtensibilityElements(), MIMEMultipartRelated.class);
465 
466 		return getContentParts(part, multipartOutput);
467 	}
468 
469 	public static MIMEContent[] getInputMultipartContent(Part part, BindingOperation operation)
470 	{
471 		MIMEMultipartRelated multipartInput = WsdlUtils.getExtensiblityElement(operation.getBindingInput()
472 				.getExtensibilityElements(), MIMEMultipartRelated.class);
473 
474 		return getContentParts(part, multipartInput);
475 	}
476 
477 	public static MIMEContent[] getContentParts(Part part, MIMEMultipartRelated multipart)
478 	{
479 		List<MIMEContent> result = new ArrayList<MIMEContent>();
480 
481 		if (multipart != null)
482 		{
483 			List<MIMEPart> parts = multipart.getMIMEParts();
484 
485 			for (int c = 0; c < parts.size(); c++)
486 			{
487 				List<MIMEContent> contentParts = WsdlUtils.getExtensiblityElements(parts.get(c).getExtensibilityElements(),
488 						MIMEContent.class);
489 
490 				for (MIMEContent content : contentParts)
491 				{
492 					if (content.getPart().equals(part.getName()))
493 						result.add(content);
494 				}
495 			}
496 		}
497 
498 		return result.toArray(new MIMEContent[result.size()]);
499 	}
500 
501 	public static Part[] getFaultParts(BindingOperation bindingOperation, String faultName) throws Exception
502 	{
503 		List<Part> result = new ArrayList<Part>();
504 
505 		BindingFault bindingFault = bindingOperation.getBindingFault(faultName);
506 		SOAPFault soapFault = WsdlUtils.getExtensiblityElement(bindingFault.getExtensibilityElements(), SOAPFault.class);
507 
508 		Operation operation = bindingOperation.getOperation();
509 		if (soapFault != null && soapFault.getName() != null)
510 		{
511 			Fault fault = operation.getFault(soapFault.getName());
512 			if (fault == null)
513 				throw new Exception("Missing Fault [" + soapFault.getName() + "] in operation [" + operation.getName()
514 						+ "]");
515 			result.addAll(fault.getMessage().getOrderedParts(null));
516 		}
517 		else
518 		{
519 			SOAP12Fault soap12Fault = WsdlUtils.getExtensiblityElement(bindingFault.getExtensibilityElements(),
520 					SOAP12Fault.class);
521 
522 			if (soap12Fault != null && soap12Fault.getName() != null)
523 			{
524 				result.addAll(operation.getFault(soap12Fault.getName()).getMessage().getOrderedParts(null));
525 			}
526 			else
527 			{
528 				result.addAll(operation.getFault(faultName).getMessage().getOrderedParts(null));
529 			}
530 		}
531 
532 		return result.toArray(new Part[result.size()]);
533 	}
534 
535 	public static String findSoapFaultPartName(SoapVersion soapVersion, BindingOperation bindingOperation, String message)
536 			throws Exception
537 	{
538 		if (WsdlUtils.isOutputSoapEncoded(bindingOperation))
539 			throw new Exception("SOAP-Encoded messages not supported");
540 
541 		XmlObject xml = XmlObject.Factory.parse(message);
542 		XmlObject[] msgPaths = xml.selectPath("declare namespace env='" + soapVersion.getEnvelopeNamespace() + "';"
543 				+ "$this/env:Envelope/env:Body/env:Fault");
544 		if (msgPaths.length == 0)
545 			return null;
546 
547 		XmlObject msgXml = msgPaths[0];
548 
549 		Map faults = bindingOperation.getBindingFaults();
550 		for (Iterator<BindingFault> i = faults.values().iterator(); i.hasNext();)
551 		{
552 			BindingFault bindingFault = i.next();
553 			String faultName = bindingFault.getName();
554 			Part[] faultParts = WsdlUtils.getFaultParts(bindingOperation, faultName);
555 			Part part = faultParts[0];
556 
557 			QName elementName = part.getElementName();
558 			if (elementName != null)
559 			{
560 				XmlObject[] faultPaths = msgXml.selectPath("declare namespace env='" + soapVersion.getEnvelopeNamespace()
561 						+ "';" + "declare namespace ns='" + elementName.getNamespaceURI() + "';" + "//env:Fault/detail/ns:"
562 						+ elementName.getLocalPart());
563 
564 				if (faultPaths.length == 1)
565 					return faultName;
566 			}
567 			// this is not allowed by Basic Profile.. remove?
568 			else if (part.getTypeName() != null)
569 			{
570 				QName typeName = part.getTypeName();
571 				XmlObject[] faultPaths = msgXml.selectPath("declare namespace env='" + soapVersion.getEnvelopeNamespace()
572 						+ "';" + "declare namespace ns='" + typeName.getNamespaceURI() + "';" + "//env:Fault/detail/ns:"
573 						+ part.getName());
574 
575 				if (faultPaths.length == 1)
576 					return faultName;
577 			}
578 		}
579 
580 		return null;
581 	}
582 
583 	public static Part[] getOutputParts(BindingOperation operation)
584 	{
585 		BindingOutput bindingOutput = operation.getBindingOutput();
586 		if (bindingOutput == null)
587 			return new Part[0];
588 
589 		List<Part> result = new ArrayList<Part>();
590 		Output output = operation.getOperation().getOutput();
591 		if (output == null)
592 			return new Part[0];
593 
594 		Message msg = output.getMessage();
595 		if (msg != null)
596 		{
597 			SOAPBody soapBody = WsdlUtils.getExtensiblityElement(bindingOutput.getExtensibilityElements(), SOAPBody.class);
598 
599 			if (soapBody == null || soapBody.getParts() == null)
600 			{
601 				SOAP12Body soap12Body = WsdlUtils.getExtensiblityElement(bindingOutput.getExtensibilityElements(),
602 						SOAP12Body.class);
603 
604 				if (soap12Body == null || soap12Body.getParts() == null)
605 				{
606 					result.addAll(msg.getOrderedParts(null));
607 				}
608 				else
609 				{
610 					Iterator i = soap12Body.getParts().iterator();
611 					while (i.hasNext())
612 					{
613 						String partName = (String) i.next();
614 						Part part = msg.getPart(partName);
615 
616 						result.add(part);
617 					}
618 				}
619 			}
620 			else
621 			{
622 				Iterator i = soapBody.getParts().iterator();
623 				while (i.hasNext())
624 				{
625 					String partName = (String) i.next();
626 					Part part = msg.getPart(partName);
627 
628 					result.add(part);
629 				}
630 			}
631 		}
632 		else
633 		{
634 			log.warn("Missing output message for binding operation [" + operation.getName() + "]");
635 		}
636 
637 		return result.toArray(new Part[result.size()]);
638 	}
639 
640 	public static boolean isMultipartRequest(Definition definition, BindingOperation bindingOperation)
641 	{
642 		return WsdlUtils.getExtensiblityElement(bindingOperation.getBindingInput().getExtensibilityElements(),
643 				MIMEMultipartRelated.class) != null;
644 	}
645 
646 	public static String getUsingAddressing(ElementExtensible item)
647 	{
648 		String version = WsaVersionTypeConfig.NONE.toString();
649 
650 		Element[] usingAddressingElements = WsdlUtils.getExentsibilityElements(item, new QName(
651 				"http://www.w3.org/2006/05/addressing/wsdl", "UsingAddressing"));
652 		if (usingAddressingElements.length == 0)
653 		{
654 			usingAddressingElements = WsdlUtils.getExentsibilityElements(item, new QName(
655 					"http://www.w3.org/2006/02/addressing/wsdl", "UsingAddressing"));
656 		}
657 
658 		if (usingAddressingElements.length != 0)
659 		{
660 			// this should resolve wsdl version, not addressing version??? what is
661 			// the connection?
662 			String addressingVersion = usingAddressingElements[0].getAttributeNS(WSDL_NAMESPACE, "required");
663 			if (addressingVersion != null && addressingVersion.equals("true"))
664 			{
665 				version = WsaVersionTypeConfig.X_200508.toString();
666 			}
667 
668 		}
669 		return version;
670 	}
671 
672 	public static Policy getAttachedPolicy(ElementExtensible item, Definition def)
673 	{
674 
675 		Policy rtnPolicy = null;
676 		Element[] policyReferences = WsdlUtils.getExentsibilityElements(item, new QName(PolicyUtils.WS_POLICY_NAMESPACE,
677 				"PolicyReference"));
678 		if (policyReferences.length > 0)
679 		{
680 			String policyId = policyReferences[0].getAttribute("URI");
681 			if (!StringUtils.isNullOrEmpty(policyId))
682 			{
683 				Element[] policies = WsdlUtils.getExentsibilityElements(def, new QName(PolicyUtils.WS_POLICY_NAMESPACE,
684 						"Policy"));
685 				Element policy = null;
686 				for (int i = 0; i < policies.length; i++)
687 				{
688 					policy = policies[i];
689 					String policyIdx = policy.getAttributeNS(WSU_NAMESPACE, "Id");
690 					if (policyId.equals("#" + policyIdx))
691 					{
692 						rtnPolicy = getPolicy(policy);
693 						continue;
694 					}
695 
696 				}
697 			}
698 		}
699 		else
700 		{
701 			// get policies of item itself
702 			Element[] itemPolicies = WsdlUtils.getExentsibilityElements(item, new QName(PolicyUtils.WS_POLICY_NAMESPACE,
703 					"Policy"));
704 			if (itemPolicies.length > 0)
705 			{
706 				for (int i = 0; i < itemPolicies.length; i++)
707 				{
708 					Element policy = itemPolicies[i];
709 					rtnPolicy = getPolicy(policy);
710 
711 				}
712 			}
713 		}
714 		return rtnPolicy;
715 	}
716 
717 	public static Policy getPolicy(Element policy)
718 	{
719 		// policy = PolicyUtils.normalize(policy);
720 
721 		// check if found reference is addressing policy
722 		Element wsAddressing = XmlUtils.getFirstChildElementNS(policy, WsaUtils.WSAM_NAMESPACE, "Addressing");
723 		Element addressingPolicy = null;
724 		Policy newPolicy = PolicyDocument.Factory.newInstance().addNewPolicy();
725 		Addressing newAddressing = null;
726 		if (wsAddressing != null)
727 		{
728 			addressingPolicy = XmlUtils.getFirstChildElementNS(wsAddressing, PolicyUtils.WS_POLICY_NAMESPACE, "Policy");
729 			if (addressingPolicy != null)
730 			{
731 				newAddressing = newPolicy.addNewAddressing();
732 				String optional = wsAddressing.getAttributeNS(PolicyUtils.WS_POLICY_NAMESPACE, "Optional");
733 				if (!StringUtils.isNullOrEmpty(optional) && optional.equals(OptionalType.TRUE.toString()))
734 				{
735 					newAddressing.setOptional(OptionalType.TRUE);
736 				}
737 				else
738 				{
739 					newAddressing.setOptional(OptionalType.FALSE);
740 				}
741 				Policy innerPolicy = newAddressing.addNewPolicy();
742 				// check if policy has Anonymous
743 				Element anonymousElm = XmlUtils.getFirstChildElementNS(addressingPolicy, new QName(WsaUtils.WSAM_NAMESPACE,
744 						"AnonymousResponses"));
745 				if (anonymousElm != null)
746 				{
747 					AnonymousResponses anr = innerPolicy.addNewAnonymousResponses();
748 				}
749 				else
750 				{
751 					Element nonAnonymousElement = XmlUtils.getFirstChildElementNS(addressingPolicy, new QName(
752 							WsaUtils.WSAM_NAMESPACE, "NonAnonymousResponses"));
753 					if (nonAnonymousElement != null)
754 					{
755 						innerPolicy.addNewNonAnonymousResponses();
756 					}
757 				}
758 			}
759 		}
760 		return newPolicy;
761 	}
762 
763 	private static String checkIfWsaPolicy(String version, Element policy)
764 	{
765 		// Policy builtPolicy = new
766 		// WsaPolicy().buildPolicy(policy.getTextContent());
767 		// policy = WsaPolicy.normalize(policy);
768 
769 		// check if found reference is addressing policy
770 		// Element wsAddressing = XmlUtils.getFirstChildElementNS(policy,
771 		// WsaUtils.WSAM_NAMESPACE, "Addressing");
772 		// Element addressingPolicy = null;
773 		// if (wsAddressing != null)
774 		// {
775 		// String optional =
776 		// wsAddressing.getAttributeNS(WsaPolicy.WS_POLICY_NAMESPACE, "Optional");
777 		// addressingPolicy = XmlUtils.getFirstChildElementNS(wsAddressing,
778 		// WsaPolicy.WS_POLICY_NAMESPACE, "Policy");
779 		// if (addressingPolicy != null)
780 		// {
781 		// if (StringUtils.isNullOrEmpty(optional) || optional.equals("false") ||
782 		// (optional.equals("true") &&
783 		// SoapUI.getSettings().getBoolean(WsaSettings.ENABLE_FOR_OPTIONAL)) )
784 		// {
785 		// version = WsaVersionTypeConfig.X_200508.toString();
786 		// }
787 		// //check if policy has Anonymous
788 		// Element anonymousElm =
789 		// XmlUtils.getFirstChildElementNS(addressingPolicy, new
790 		// QName(WsaPolicy.WSAM_NAMESPACE,"AnonymousResponses"));
791 		// if (anonymousElm != null)
792 		// {
793 		// //TODO anonymous = required
794 		// } else {
795 		// Element nonAnonymousElement =
796 		// XmlUtils.getFirstChildElementNS(addressingPolicy, new
797 		// QName(WsaPolicy.WSAM_NAMESPACE,"NonAnonymousResponses"));
798 		// if (nonAnonymousElement != null)
799 		// {
800 		// //TODO anonymous = prohibited
801 		// }
802 		// }
803 		// }
804 		// }
805 		return version;
806 	}
807 
808 	public static String getWsaPolicyAnonymous(Element policy)
809 	{
810 		String version = WsaVersionTypeConfig.NONE.toString();
811 		String anonymous = AnonymousTypeConfig.OPTIONAL.toString();
812 		// check if found reference is addressing policy
813 		Element wsAddressing = XmlUtils.getFirstChildElementNS(policy, WsaUtils.WSAM_NAMESPACE, "Addressing");
814 		Element addressingPolicy = null;
815 		if (wsAddressing != null)
816 		{
817 			String optional = wsAddressing.getAttributeNS(PolicyUtils.WS_POLICY_NAMESPACE, "Optional");
818 			addressingPolicy = XmlUtils.getFirstChildElementNS(wsAddressing, PolicyUtils.WS_POLICY_NAMESPACE, "Policy");
819 			if (addressingPolicy != null)
820 			{
821 				if (StringUtils.isNullOrEmpty(optional) || optional.equals("false")
822 						|| (optional.equals("true") && SoapUI.getSettings().getBoolean(WsaSettings.ENABLE_FOR_OPTIONAL)))
823 				{
824 					version = WsaVersionTypeConfig.X_200508.toString();
825 				}
826 				// check if policy has Anonymous
827 				Element anonymousElm = XmlUtils.getFirstChildElementNS(addressingPolicy, new QName(WsaUtils.WSAM_NAMESPACE,
828 						"AnonymousResponses"));
829 				if (anonymousElm != null)
830 				{
831 					anonymous = AnonymousTypeConfig.REQUIRED.toString();
832 				}
833 				else
834 				{
835 					Element nonAnonymousElement = XmlUtils.getFirstChildElementNS(addressingPolicy, new QName(
836 							WsaUtils.WSAM_NAMESPACE, "NonAnonymousResponses"));
837 					if (nonAnonymousElement != null)
838 					{
839 						anonymous = AnonymousTypeConfig.PROHIBITED.toString();
840 					}
841 				}
842 			}
843 		}
844 		return anonymous;
845 	}
846 
847 	public static String getSoapEndpoint(Port port)
848 	{
849 		SOAPAddress soapAddress = WsdlUtils.getExtensiblityElement(port.getExtensibilityElements(), SOAPAddress.class);
850 		if (soapAddress != null)
851 			try
852 			{
853 				return URLDecoder.decode(soapAddress.getLocationURI(), "UTF-8");
854 			}
855 			catch (UnsupportedEncodingException e)
856 			{
857 				e.printStackTrace();
858 				return soapAddress.getLocationURI();
859 			}
860 
861 		SOAP12Address soap12Address = WsdlUtils.getExtensiblityElement(port.getExtensibilityElements(),
862 				SOAP12Address.class);
863 		if (soap12Address != null)
864 			try
865 			{
866 				return URLDecoder.decode(soap12Address.getLocationURI(), "UTF-8");
867 			}
868 			catch (UnsupportedEncodingException e)
869 			{
870 				e.printStackTrace();
871 				return soap12Address.getLocationURI();
872 			}
873 
874 		return null;
875 	}
876 
877 	public static boolean replaceSoapEndpoint(Port port, String endpoint)
878 	{
879 		SOAPAddress soapAddress = WsdlUtils.getExtensiblityElement(port.getExtensibilityElements(), SOAPAddress.class);
880 		if (soapAddress != null)
881 		{
882 			soapAddress.setLocationURI(endpoint);
883 			return true;
884 		}
885 
886 		SOAP12Address soap12Address = WsdlUtils.getExtensiblityElement(port.getExtensibilityElements(),
887 				SOAP12Address.class);
888 		if (soap12Address != null)
889 		{
890 			soap12Address.setLocationURI(endpoint);
891 			return true;
892 		}
893 
894 		return false;
895 	}
896 
897 	public static String getSoapBodyNamespace(List list)
898 	{
899 		SOAPBody soapBody = WsdlUtils.getExtensiblityElement(list, SOAPBody.class);
900 		if (soapBody != null)
901 			return soapBody.getNamespaceURI();
902 
903 		SOAP12Body soap12Body = WsdlUtils.getExtensiblityElement(list, SOAP12Body.class);
904 		if (soap12Body != null)
905 			return soap12Body.getNamespaceURI();
906 
907 		return null;
908 	}
909 
910 	public static final class NonSchemaImportingWsdlReaderImpl extends WSDLReaderImpl
911 	{
912 		@SuppressWarnings("unchecked")
913 		@Override
914 		protected ExtensibilityElement parseSchema(Class parentType, Element el, Definition def, ExtensionRegistry extReg)
915 				throws WSDLException
916 		{
917 			QName elementType = QNameUtils.newQName(el);
918 
919 			ExtensionDeserializer exDS = extReg.queryDeserializer(parentType, elementType);
920 
921 			// Now unmarshall the DOM element.
922 			ExtensibilityElement ee = exDS.unmarshall(parentType, elementType, el, def, extReg);
923 
924 			return ee;
925 		}
926 
927 	}
928 
929 	/***
930 	 * A SOAP-Header wrapper
931 	 * 
932 	 * @author ole.matzura
933 	 */
934 
935 	public interface SoapHeader
936 	{
937 		public QName getMessage();
938 
939 		public String getPart();
940 	}
941 
942 	/***
943 	 * SOAP 1.1 Header implementation
944 	 * 
945 	 * @author ole.matzura
946 	 */
947 
948 	public static class Soap11Header implements SoapHeader
949 	{
950 		private final SOAPHeader soapHeader;
951 
952 		public Soap11Header(SOAPHeader soapHeader)
953 		{
954 			this.soapHeader = soapHeader;
955 		}
956 
957 		public QName getMessage()
958 		{
959 			return soapHeader.getMessage();
960 		}
961 
962 		public String getPart()
963 		{
964 			return soapHeader.getPart();
965 		}
966 	}
967 
968 	/***
969 	 * SOAP 1.2 Header implementation
970 	 * 
971 	 * @author ole.matzura
972 	 */
973 
974 	public static class Soap12Header implements SoapHeader
975 	{
976 		private final SOAP12Header soapHeader;
977 
978 		public Soap12Header(SOAP12Header soapHeader)
979 		{
980 			this.soapHeader = soapHeader;
981 		}
982 
983 		public QName getMessage()
984 		{
985 			return soapHeader.getMessage();
986 		}
987 
988 		public String getPart()
989 		{
990 			return soapHeader.getPart();
991 		}
992 	}
993 
994 	public static List<SoapHeader> getSoapHeaders(List list)
995 	{
996 		List<SoapHeader> result = new ArrayList<SoapHeader>();
997 
998 		List<SOAPHeader> soapHeaders = WsdlUtils.getExtensiblityElements(list, SOAPHeader.class);
999 		if (soapHeaders != null && !soapHeaders.isEmpty())
1000 		{
1001 			for (SOAPHeader header : soapHeaders)
1002 				result.add(new Soap11Header(header));
1003 		}
1004 		else
1005 		{
1006 			List<SOAP12Header> soap12Headers = WsdlUtils.getExtensiblityElements(list, SOAP12Header.class);
1007 			if (soap12Headers != null && !soap12Headers.isEmpty())
1008 			{
1009 				for (SOAP12Header header : soap12Headers)
1010 					result.add(new Soap12Header(header));
1011 			}
1012 		}
1013 
1014 		return result;
1015 	}
1016 
1017 	public static synchronized Definition readDefinition(String wsdlUrl) throws Exception
1018 	{
1019 		if (wsdlReader == null)
1020 		{
1021 			WSDLFactory factory = WSDLFactory.newInstance();
1022 			wsdlReader = factory.newWSDLReader();
1023 			wsdlReader.setFeature("javax.wsdl.verbose", true);
1024 			wsdlReader.setFeature("javax.wsdl.importDocuments", true);
1025 		}
1026 
1027 		return wsdlReader.readWSDL(new UrlWsdlLoader(wsdlUrl));
1028 	}
1029 
1030 	public static SchemaType getSchemaTypeForPart(WsdlContext wsdlContext, javax.wsdl.Part part) throws Exception
1031 	{
1032 		SchemaType schemaType = null;
1033 		QName elementName = part.getElementName();
1034 
1035 		if (elementName != null)
1036 		{
1037 			SchemaGlobalElement elm = wsdlContext.getSchemaTypeLoader().findElement(elementName);
1038 			if (elm != null)
1039 			{
1040 				schemaType = elm.getType();
1041 			}
1042 			else
1043 				WsdlRequest.log.error("Could not find element [" + elementName + "] specified in part [" + part.getName()
1044 						+ "]");
1045 		}
1046 		else
1047 		{
1048 			QName typeName = part.getTypeName();
1049 
1050 			if (typeName != null)
1051 			{
1052 				schemaType = wsdlContext.getSchemaTypeLoader().findType(typeName);
1053 
1054 				if (schemaType == null)
1055 				{
1056 					WsdlRequest.log.error("Could not find type [" + typeName + "] specified in part [" + part.getName()
1057 							+ "]");
1058 				}
1059 			}
1060 		}
1061 		return schemaType;
1062 	}
1063 
1064 	public static SchemaGlobalElement getSchemaElementForPart(WsdlContext wsdlContext, javax.wsdl.Part part)
1065 			throws Exception
1066 	{
1067 		QName elementName = part.getElementName();
1068 
1069 		if (elementName != null)
1070 		{
1071 			return wsdlContext.getSchemaTypeLoader().findElement(elementName);
1072 		}
1073 
1074 		return null;
1075 	}
1076 
1077 	public static String replacePortEndpoint(WsdlInterface iface, InputSource inputSource, String endpoint)
1078 			throws WSDLException
1079 	{
1080 		WSDLReader wsdlReader = new NonSchemaImportingWsdlReaderImpl();
1081 
1082 		wsdlReader.setFeature("javax.wsdl.verbose", true);
1083 		wsdlReader.setFeature("javax.wsdl.importDocuments", false);
1084 
1085 		Definition definition = wsdlReader.readWSDL(null, inputSource);
1086 
1087 		boolean updated = false;
1088 		Map map = definition.getServices();
1089 		for (Iterator i = map.values().iterator(); i.hasNext();)
1090 		{
1091 			Service service = (Service) i.next();
1092 			Map portMap = service.getPorts();
1093 			for (Iterator i2 = portMap.values().iterator(); i2.hasNext();)
1094 			{
1095 				Port port = (Port) i2.next();
1096 				if (port.getBinding().getQName().equals(iface.getBindingName()))
1097 				{
1098 					if (replaceSoapEndpoint(port, endpoint))
1099 						updated = true;
1100 				}
1101 			}
1102 		}
1103 
1104 		if (updated)
1105 		{
1106 			StringWriter writer = new StringWriter();
1107 
1108 			Map nsMap = definition.getNamespaces();
1109 			if (!nsMap.values().contains(Constants.SOAP_HTTP_BINDING_NS))
1110 				definition.addNamespace("soaphttp", Constants.SOAP_HTTP_BINDING_NS);
1111 
1112 			new WSDLWriterImpl().writeWSDL(definition, writer);
1113 			return writer.toString();
1114 		}
1115 
1116 		return null;
1117 	}
1118 
1119 	public static BindingOperation findBindingOperation(Binding binding, String bindingOperationName, String inputName,
1120 			String outputName)
1121 	{
1122 		if (binding == null)
1123 			return null;
1124 
1125 		if (inputName == null)
1126 			inputName = ":none";
1127 
1128 		if (outputName == null)
1129 			outputName = ":none";
1130 
1131 		BindingOperation result = binding.getBindingOperation(bindingOperationName, inputName, outputName);
1132 
1133 		if (result == null && (inputName.equals(":none") || outputName.equals(":none")))
1134 		{
1135 			// fall back to this behaviour for WSDL4j 1.5.0 compatibility
1136 			result = binding.getBindingOperation(bindingOperationName, inputName.equals(":none") ? null : inputName,
1137 					outputName.equals(":none") ? null : outputName);
1138 		}
1139 		return result;
1140 	}
1141 
1142 	public static boolean isHeaderInputPart(Part part, Message message, BindingOperation bindingOperation)
1143 	{
1144 		List<SOAPHeader> headers = WsdlUtils.getExtensiblityElements(bindingOperation.getBindingInput()
1145 				.getExtensibilityElements(), SOAPHeader.class);
1146 
1147 		if (headers == null || headers.isEmpty())
1148 			return false;
1149 
1150 		for (SOAPHeader header : headers)
1151 		{
1152 			if (message.getQName().equals(header.getMessage()) && part.getName().equals(header.getPart()))
1153 				return true;
1154 		}
1155 
1156 		return false;
1157 	}
1158 
1159 	public static boolean isHeaderOutputPart(Part part, Message message, BindingOperation bindingOperation)
1160 	{
1161 		List<SOAPHeader> headers = WsdlUtils.getExtensiblityElements(bindingOperation.getBindingOutput()
1162 				.getExtensibilityElements(), SOAPHeader.class);
1163 
1164 		if (headers == null || headers.isEmpty())
1165 			return false;
1166 
1167 		for (SOAPHeader header : headers)
1168 		{
1169 			if (message.getQName().equals(header.getMessage()) && part.getName().equals(header.getPart()))
1170 				return true;
1171 		}
1172 
1173 		return false;
1174 	}
1175 
1176 	public static DefinitionCacheConfig cacheWsdl(DefinitionLoader loader) throws Exception
1177 	{
1178 		DefinitionCacheConfig definitionCache = DefinitionCacheConfig.Factory.newInstance();
1179 		definitionCache.setRootPart(loader.getBaseURI());
1180 		definitionCache.setType(DefinitionCacheTypeConfig.TEXT);
1181 
1182 		Map<String, XmlObject> urls = SchemaUtils.getDefinitionParts(loader);
1183 
1184 		for (Iterator<String> i = urls.keySet().iterator(); i.hasNext();)
1185 		{
1186 			DefintionPartConfig definitionPart = definitionCache.addNewPart();
1187 			String url = i.next();
1188 			definitionPart.setUrl(url);
1189 			XmlObject xmlObject = urls.get(url);
1190 			Node domNode = xmlObject.getDomNode();
1191 
1192 			if (domNode.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE)
1193 			{
1194 				Node node = ((DocumentFragment) domNode).getFirstChild();
1195 				if (node.getNodeType() == Node.TEXT_NODE)
1196 				{
1197 					domNode = XmlUtils.parseXml(node.getNodeValue());
1198 					xmlObject = XmlObject.Factory.parse(domNode);
1199 				}
1200 			}
1201 
1202 			Element contentElement = ((Document) domNode).getDocumentElement();
1203 
1204 			Node newDomNode = definitionPart.addNewContent().getDomNode();
1205 			newDomNode.appendChild(newDomNode.getOwnerDocument().createTextNode(xmlObject.toString()));
1206 			definitionPart.setType(contentElement.getNamespaceURI());
1207 		}
1208 
1209 		return definitionCache;
1210 	}
1211 
1212 	public static void getAnonymous(WsdlOperation wsdlOperation)
1213 	{
1214 		String anonymous = "";
1215 
1216 		Element[] anonymousElements = WsdlUtils.getExentsibilityElements(wsdlOperation.getBindingOperation(), new QName(
1217 				"http://www.w3.org/2006/05/addressing/wsdl", "Anonymous"));
1218 		if (anonymousElements.length == 0)
1219 		{
1220 			anonymousElements = WsdlUtils.getExentsibilityElements(wsdlOperation.getBindingOperation(), new QName(
1221 					"http://www.w3.org/2006/02/addressing/wsdl", "Anonymous"));
1222 		}
1223 
1224 		if (anonymousElements != null && anonymousElements.length > 0)
1225 		{
1226 			anonymous = XmlUtils.getElementText(anonymousElements[0]);
1227 		}
1228 		wsdlOperation.setAnonymous(anonymous);
1229 	}
1230 
1231 	public static String getDefaultWsaAction(WsdlOperation operation, boolean output)
1232 	{
1233 		// SOAP 1.1 specific handling
1234 		if (operation.getInterface().getSoapVersion() == SoapVersion.Soap11
1235 				&& StringUtils.hasContent(operation.getAction()) && SoapUI.getSettings().getBoolean(WsaSettings.SOAP_ACTION_OVERRIDES_WSA_ACTION))
1236 			return operation.getAction();
1237 
1238 		try
1239 		{
1240 			AttributeExtensible attributeExtensible = output ? operation.getBindingOperation().getOperation().getOutput()
1241 					: operation.getBindingOperation().getOperation().getInput();
1242 
1243 			if (attributeExtensible == null)
1244 				return null;
1245 
1246 			String[] attrs = WsdlUtils.getExentsibilityAttributes(attributeExtensible, new QName(
1247 					WsaUtils.WS_A_VERSION_200408, "Action"));
1248 			if (attrs == null || attrs.length == 0)
1249 				attrs = WsdlUtils.getExentsibilityAttributes(attributeExtensible, new QName(WsaUtils.WS_A_VERSION_200508,
1250 						"Action"));
1251 			if (attrs != null && attrs.length > 0)
1252 			{
1253 				return attrs[0];
1254 			}
1255 
1256 			WsdlInterface iface = operation.getInterface();
1257 
1258 			Definition definition = iface.getWsdlContext().getDefinition();
1259 			String targetNamespace = definition.getTargetNamespace();
1260 			String portTypeName = iface.getBinding().getPortType().getQName().getLocalPart();
1261 			String operationName = operation.getName();
1262 			if (!StringUtils.isNullOrEmpty(operationName))
1263 			{
1264 				Operation op = iface.getBinding().getPortType().getOperation(operationName, null, null);
1265 				if (op != null)
1266 				{
1267 					attributeExtensible = output ? op.getOutput() : op.getInput();
1268 					attrs = WsdlUtils.getExentsibilityAttributes(attributeExtensible, new QName(WsaUtils.WSAM_NAMESPACE,
1269 							"Action"));
1270 					if (attrs != null && attrs.length > 0)
1271 					{
1272 						return attrs[0];
1273 					}
1274 				}
1275 			}
1276 			String operationInOutName = output ? operation.getOutputName() : operation.getInputName();
1277 			if (operationInOutName == null)
1278 				operationInOutName = operation.getName() + (output ? "Response" : "Request");
1279 
1280 			StringBuffer result = new StringBuffer(targetNamespace);
1281 			if (targetNamespace.charAt(targetNamespace.length() - 1) != '/' && portTypeName.charAt(0) != '/')
1282 				result.append('/');
1283 			result.append(portTypeName);
1284 			if (portTypeName.charAt(portTypeName.length() - 1) != '/' && operationInOutName.charAt(0) != '/')
1285 				result.append('/');
1286 			result.append(operationInOutName);
1287 
1288 			return result.toString();
1289 		}
1290 		catch (Exception e)
1291 		{
1292 			e.printStackTrace();
1293 			log.warn(e.toString());
1294 			return null;
1295 		}
1296 	}
1297 
1298 	public static void setDefaultWsaAction(WsaConfig wsaConfig, boolean b)
1299 	{
1300 		String defaultAction = getDefaultWsaAction(wsaConfig.getWsaContainer().getOperation(), b);
1301 		if (StringUtils.hasContent(defaultAction))
1302 			wsaConfig.setAction(defaultAction);
1303 	}
1304 	public static String getRequestWsaMessageId(WsdlMessageExchange messageExchange, String wsaVersionNameSpace) {
1305 		String requestMessageId = null;
1306 		try
1307 		{
1308 			XmlObject xmlObject = XmlObject.Factory.parse( messageExchange.getRequestContent() );
1309 			SoapVersion soapVersion = messageExchange.getOperation().getInterface()
1310 				.getSoapVersion();
1311 
1312 			Element header = (Element) SoapUtils.getHeaderElement( xmlObject, soapVersion, true ).getDomNode();
1313 			Element msgNode = XmlUtils.getFirstChildElementNS(header, wsaVersionNameSpace, "MessageID");
1314 			if (msgNode != null)
1315 			{
1316 				requestMessageId = XmlUtils.getElementText(msgNode);
1317 			}
1318 		}
1319 		catch (XmlException e)
1320 		{
1321 			e.printStackTrace();
1322 			log.warn(e.toString());
1323 			return null;
1324 		}
1325 		return requestMessageId;
1326 	}
1327 
1328 	public static NodeList getRequestReplyToRefProps(WsdlMessageExchange messageExchange, String wsaVersionNameSpace) {
1329 		try
1330 		{
1331 			XmlObject xmlObject = XmlObject.Factory.parse( messageExchange.getRequestContent() );
1332 			SoapVersion soapVersion = messageExchange.getOperation().getInterface()
1333 				.getSoapVersion();
1334 
1335 			Element header = (Element) SoapUtils.getHeaderElement( xmlObject, soapVersion, true ).getDomNode();
1336 			Element replyToNode = XmlUtils.getFirstChildElementNS(header, wsaVersionNameSpace, "ReplyTo");
1337 			Element replyRefParamsNode = XmlUtils.getFirstChildElementNS(replyToNode, wsaVersionNameSpace, "ReferenceParameters");
1338 			if (replyRefParamsNode != null)
1339 			{
1340 				return XmlUtils.getChildElements(replyRefParamsNode);
1341 			}
1342 		}
1343 		catch (XmlException e)
1344 		{
1345 			e.printStackTrace();
1346 			log.warn(e.toString());
1347 		}
1348 		return null;
1349 	}
1350 	public static NodeList getRequestFaultToRefProps(WsdlMessageExchange messageExchange, String wsaVersionNameSpace) {
1351 		try
1352 		{
1353 			XmlObject xmlObject = XmlObject.Factory.parse( messageExchange.getRequestContent() );
1354 			SoapVersion soapVersion = messageExchange.getOperation().getInterface()
1355 				.getSoapVersion();
1356 
1357 			Element header = (Element) SoapUtils.getHeaderElement( xmlObject, soapVersion, true ).getDomNode();
1358 			Element faultToNode = XmlUtils.getFirstChildElementNS(header, wsaVersionNameSpace, "FaultTo");
1359 			Element faultRefParamsNode = XmlUtils.getFirstChildElementNS(faultToNode, wsaVersionNameSpace, "ReferenceParameters");
1360 			if (faultRefParamsNode != null)
1361 			{
1362 				return XmlUtils.getChildElements(faultRefParamsNode);
1363 			}
1364 		}
1365 		catch (XmlException e)
1366 		{
1367 			e.printStackTrace();
1368 			log.warn(e.toString());
1369 		}
1370 		return null;
1371 	}
1372 	public static String getFaultCode(WsdlMessageExchange messageExchange) {
1373 		try
1374 		{
1375 			XmlObject xmlObject = XmlObject.Factory.parse( messageExchange.getResponseContent() );
1376 			SoapVersion soapVersion = messageExchange.getOperation().getInterface()
1377 				.getSoapVersion();
1378 
1379 			Element body = (Element) SoapUtils.getBodyElement(xmlObject, soapVersion).getDomNode();
1380 			Element soapenvFault = XmlUtils.getFirstChildElementNS(body, "http://schemas.xmlsoap.org/soap/envelope/", "Fault");
1381 			Element faultCode = XmlUtils.getFirstChildElement(soapenvFault, "faultcode");
1382 			if (faultCode != null)
1383 			{
1384 				return XmlUtils.getElementText(faultCode);
1385 			}
1386 		}
1387 		catch (XmlException e)
1388 		{
1389 			e.printStackTrace();
1390 			log.warn(e.toString());
1391 		}
1392 		return null;
1393 	}
1394 }