View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.soap;
14  
15  import org.apache.xmlbeans.XmlException;
16  import org.apache.xmlbeans.XmlObject;
17  
18  import com.eviware.soapui.support.StringUtils;
19  
20  /***
21   * SOAP-related utility-methods..
22   * 
23   * @author ole.matzura
24   */
25  
26  public class SoapUtils
27  {
28  	public static boolean isSoapFault( String responseContent, SoapVersion soapVersion ) throws XmlException
29  	{
30  		if( StringUtils.isNullOrEmpty( responseContent ))
31  			return false;
32  		
33  		// check manually before resource intensive xpath
34  		if( responseContent.indexOf( ":Fault" ) > 0 || responseContent.indexOf( "<Fault" ) > 0 )
35  		{
36  		   XmlObject xml = XmlObject.Factory.parse( responseContent );
37  		   XmlObject[] paths = xml.selectPath( "declare namespace env='" + soapVersion.getEnvelopeNamespace() + "';" + 
38  		         "//env:Fault");
39  		   if( paths.length > 0 )
40  		      return true;
41  		}
42  		
43  		return false;
44  	}
45  }