View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.support;
14  
15  import com.eviware.soapui.support.StringUtils;
16  
17  public class HttpUtils
18  {
19  	public static boolean isErrorStatus( int statusCode )
20  	{
21  		return statusCode >= 400;
22  	}
23  
24  	public static String extractHttpHeaderParameter( String headerString, String parameterName )
25  	{
26  		if( !StringUtils.hasContent( headerString ) || !StringUtils.hasContent( parameterName ) )
27  			return null;
28  
29  		int ix = headerString.indexOf( parameterName + "=\"" );
30  		if( ix > 0 )
31  		{
32  			int ix2 = headerString.indexOf( '"', ix + parameterName.length() + 2 );
33  			if( ix2 > ix )
34  				return headerString.substring( ix + parameterName.length() + 2, ix2 );
35  		}
36  
37  		return null;
38  	}
39  
40  	public static String ensureEndpointStartsWithProtocol( String endpoint )
41  	{
42  		if( StringUtils.isNullOrEmpty( endpoint ) )
43  			return endpoint;
44  
45  		String ep = endpoint.toLowerCase().trim();
46  		if( !ep.startsWith( "http://" ) && !ep.startsWith( "https://" ) && !ep.startsWith( "$" ) )
47  			return "http://" + endpoint;
48  
49  		return endpoint;
50  	}
51  }