Class HttpUtil


  • public class HttpUtil
    extends Object
    Some common methods to be used in both HTTP-In-Binding and HTTP-Out-Binding
    Author:
    Thomas Eichstaedt-Engelen - Initial contribution, Kai Kreuzer - Initial contribution
    • Constructor Detail

      • HttpUtil

        public HttpUtil()
    • Method Detail

      • executeUrl

        public static String executeUrl​(String httpMethod,
                                        String url,
                                        int timeout)
        Executes the given url with the given httpMethod. Furthermore the http.proxyXXX System variables are read and set into the HttpClient.
        Parameters:
        httpMethod - the HTTP method to use
        url - the url to execute (in milliseconds)
        timeout - the socket timeout to wait for data
        Returns:
        the response body or NULL when the request went wrong
      • executeUrl

        public static String executeUrl​(String httpMethod,
                                        String url,
                                        InputStream content,
                                        String contentType,
                                        int timeout)
        Executes the given url with the given httpMethod. Furthermore the http.proxyXXX System variables are read and set into the HttpClient.
        Parameters:
        httpMethod - the HTTP method to use
        url - the url to execute (in milliseconds)
        content - the content to be send to the given url or null if no content should be send.
        contentType - the content type of the given content
        timeout - the socket timeout to wait for data
        Returns:
        the response body or NULL when the request went wrong
      • executeUrl

        public static String executeUrl​(String httpMethod,
                                        String url,
                                        Properties httpHeaders,
                                        InputStream content,
                                        String contentType,
                                        int timeout)
        Executes the given url with the given httpMethod. Furthermore the http.proxyXXX System variables are read and set into the HttpClient.
        Parameters:
        httpMethod - the HTTP method to use
        url - the url to execute (in milliseconds)
        httpHeaders - optional http request headers which has to be sent within request
        content - the content to be send to the given url or null if no content should be send.
        contentType - the content type of the given content
        timeout - the socket timeout to wait for data
        Returns:
        the response body or NULL when the request went wrong
      • executeUrl

        public static String executeUrl​(String httpMethod,
                                        String url,
                                        Properties httpHeaders,
                                        InputStream content,
                                        String contentType,
                                        int timeout,
                                        String proxyHost,
                                        Integer proxyPort,
                                        String proxyUser,
                                        String proxyPassword,
                                        String nonProxyHosts)
        Executes the given url with the given httpMethod
        Parameters:
        httpMethod - the HTTP method to use
        url - the url to execute (in milliseconds)
        httpHeaders - optional HTTP headers which has to be set on request
        content - the content to be send to the given url or null if no content should be send.
        contentType - the content type of the given content
        timeout - the socket timeout to wait for data
        proxyHost - the hostname of the proxy
        proxyPort - the port of the proxy
        proxyUser - the username to authenticate with the proxy
        proxyPassword - the password to authenticate with the proxy
        nonProxyHosts - the hosts that won't be routed through the proxy
        Returns:
        the response body or NULL when the request went wrong
      • extractCredentials

        protected static org.apache.commons.httpclient.Credentials extractCredentials​(String url)
        Extracts username and password from the given url. A valid url to extract Credentials from looks like:
         http://username:[email protected]
         
        Parameters:
        url - the URL to extract Credentials from
        Returns:
        the exracted Credentials or null if the given url does not contain credentials
      • createHttpMethod

        public static org.apache.commons.httpclient.HttpMethod createHttpMethod​(String httpMethodString,
                                                                                String url)
        Factory method to create a HttpMethod-object according to the given String httpMethod
        Parameters:
        httpMethodString - the name of the HttpMethod to create
        url -
        Returns:
        an object of type GetMethod, PutMethod, PostMethod or DeleteMethod
        Throws:
        IllegalArgumentException - if httpMethod is none of GET, PUT, POST or DELETE