Apache JMeter

org.apache.jmeter.protocol.http.util
Class ConversionUtils

java.lang.Object
  extended by org.apache.jmeter.protocol.http.util.ConversionUtils

public class ConversionUtils
extends Object

General purpose conversion utilities related to HTTP/HTML


Constructor Summary
ConversionUtils()
           
 
Method Summary
static String buildFullUrlFromRelative(URL lastUrl, String redirectLocation)
          Builds Full url (containing scheme, host,port) from relative URL as per RFC http://tools.ietf.org/html/rfc3986#section-4.2
static String escapeIllegalURLCharacters(String url)
           
static String getEncodingFromContentType(String contentType)
          Extract the encoding (charset) from the Content-Type, e.g.
static URL makeRelativeURL(URL baseURL, String location)
          Generate a relative URL, allowing for extraneous leading "../" segments.
static String removeSlashDotDot(String url)
          collapses absolute or relative URLs containing '/..' converting http://host/path1/..
static URI sanitizeUrl(URL url)
          Escapes reserved chars in a non-encoded URL or partially encoded one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConversionUtils

public ConversionUtils()
Method Detail

getEncodingFromContentType

public static String getEncodingFromContentType(String contentType)
Extract the encoding (charset) from the Content-Type, e.g. "text/html; charset=utf-8".

Parameters:
contentType -
Returns:
the charset encoding - or null, if none was found or the charset is not supported
Throws:
IllegalCharsetNameException

makeRelativeURL

public static URL makeRelativeURL(URL baseURL,
                                  String location)
                           throws MalformedURLException
Generate a relative URL, allowing for extraneous leading "../" segments. The Java URL.URL(URL, String) constructor does not remove these.

Parameters:
baseURL -
location - relative location, possibly with extraneous leading "../"
Returns:
URL with extraneous ../ removed
Throws:
MalformedURLException

escapeIllegalURLCharacters

public static String escapeIllegalURLCharacters(String url)
                                         throws Exception
Parameters:
url - String Url to escape
Returns:
String cleaned up url
Throws:
Exception

sanitizeUrl

public static final URI sanitizeUrl(URL url)
                             throws URISyntaxException,
                                    UnsupportedEncodingException
Escapes reserved chars in a non-encoded URL or partially encoded one. Warning: it won't work on all unencoded URLs. For example, the unencoded URL http://localhost/% will cause an Exception. Any instances of % must have been encoded as %25 within the path portion.

Parameters:
url - non-encoded or partially encoded URL
Returns:
URI which has been encoded as necessary
Throws:
URISyntaxException
UnsupportedEncodingException

removeSlashDotDot

public static String removeSlashDotDot(String url)
collapses absolute or relative URLs containing '/..' converting http://host/path1/../path2 to http://host/path2 or /one/two/../three to /one/three

Parameters:
url -
Returns:
collapsed URL

buildFullUrlFromRelative

public static final String buildFullUrlFromRelative(URL lastUrl,
                                                    String redirectLocation)
Builds Full url (containing scheme, host,port) from relative URL as per RFC http://tools.ietf.org/html/rfc3986#section-4.2

Parameters:
lastUrl - URL
redirectLocation - absolute URL
Returns:
Full URL

Apache JMeter

Copyright © 1998-2013 Apache Software Foundation. All Rights Reserved.