Class HTTPUtils


  • @Component
    public class HTTPUtils
    extends Object
    HTTP Utility Methods to aid in standard RESTful tasks
    Version:
    $Id: $Id
    Author:
    Matthew Keathley on 6/15/15
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  HTTPUtils.HttpMkCol  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.apache.http.impl.client.CloseableHttpClient createHttpClientFromURL​(URL url)
      Creates a CloseableHttpClient for the given address with attached credentials.
      static org.apache.http.client.methods.CloseableHttpResponse delete​(URI address)
      delete.
      static InputStream getInputStreamFromURL​(String address)
      Utility Method to Get the InputStream From the given URL
      static InputStream getInputStreamFromURL​(URI address)
      Utility Method to Get the InputStream From the given URL
      static org.apache.http.client.methods.CloseableHttpResponse getResponseFromURL​(String address)
      Utility method to get the HTTP Response from a URL.
      static org.apache.http.client.methods.CloseableHttpResponse getResponseFromURL​(URI address)
      Utility method to get the HTTP Response from a URL.
      static String getStringFromURL​(String address)
      Utility Method to Download a File as String from the given URL
      static org.apache.http.client.methods.CloseableHttpResponse headStringToURL​(String address)
      Utility method to get the header of the HTTP Response from a URL.
      static org.apache.http.client.methods.CloseableHttpResponse headStringToURL​(URI address)
      Utility method to get the header of the HTTP Response from a URL.
      static org.apache.http.client.methods.CloseableHttpResponse putEntityToURL​(URI address, org.apache.http.entity.AbstractHttpEntity entity)
      Utility method to send a entity to the given HTTP address via HTTP PUT
      static org.apache.http.client.methods.CloseableHttpResponse putStringToURL​(String address, String string)
      Utility method to send a String to the given HTTP address via HTTP PUT
      static org.apache.http.client.methods.CloseableHttpResponse putStringToURL​(URI address, String string)
      Utility method to send a String to the given HTTP address via HTTP PUT
    • Constructor Detail

    • Method Detail

      • createHttpClientFromURL

        public static org.apache.http.impl.client.CloseableHttpClient createHttpClientFromURL​(URL url)
                                                                                       throws HTTPException
        Creates a CloseableHttpClient for the given address with attached credentials.
        Parameters:
        url - The URL create the client
        Returns:
        CloseableHttpClient
        Throws:
        HTTPException - Thrown if an error occurs while retrieving the client.
      • getInputStreamFromURL

        public static InputStream getInputStreamFromURL​(String address)
                                                 throws URISyntaxException,
                                                        HTTPException
        Utility Method to Get the InputStream From the given URL
        Parameters:
        address - The String form of the URL.
        Returns:
        The file as String
        Throws:
        HTTPException - Thrown if an error occurs while retrieving the input stream.
        URISyntaxException - Thrown if the URI is malformed.
      • getInputStreamFromURL

        public static InputStream getInputStreamFromURL​(URI address)
                                                 throws HTTPException
        Utility Method to Get the InputStream From the given URL
        Parameters:
        address - The URL to download
        Returns:
        The file as String
        Throws:
        HTTPException - Thrown if an error occurs while retrieving the input stream.
      • getResponseFromURL

        public static org.apache.http.client.methods.CloseableHttpResponse getResponseFromURL​(String address)
                                                                                       throws URISyntaxException,
                                                                                              HTTPException
        Utility method to get the HTTP Response from a URL.
        Parameters:
        address - The String address to retrieve
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs while retrieving response.
        URISyntaxException - Thrown if the URI is malformed.
      • getResponseFromURL

        public static org.apache.http.client.methods.CloseableHttpResponse getResponseFromURL​(URI address)
                                                                                       throws HTTPException
        Utility method to get the HTTP Response from a URL.
        Parameters:
        address - The address to retrieve
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs while retrieving response.
      • getStringFromURL

        public static String getStringFromURL​(String address)
                                       throws HTTPException
        Utility Method to Download a File as String from the given URL
        Parameters:
        address - The URL to download
        Returns:
        The file as String
        Throws:
        HTTPException - Thrown if an error occurs while retrieving the URL.
      • putStringToURL

        public static org.apache.http.client.methods.CloseableHttpResponse putStringToURL​(String address,
                                                                                          String string)
                                                                                   throws URISyntaxException,
                                                                                          HTTPException
        Utility method to send a String to the given HTTP address via HTTP PUT
        Parameters:
        address - The String form of the address to retrieve
        string - The string to send
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs during PUT.
        URISyntaxException - Thrown if the URI is malformed.
      • putStringToURL

        public static org.apache.http.client.methods.CloseableHttpResponse putStringToURL​(URI address,
                                                                                          String string)
                                                                                   throws HTTPException
        Utility method to send a String to the given HTTP address via HTTP PUT
        Parameters:
        address - The address to retrieve
        string - The string to send
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs during PUT.
      • putEntityToURL

        public static org.apache.http.client.methods.CloseableHttpResponse putEntityToURL​(URI address,
                                                                                          org.apache.http.entity.AbstractHttpEntity entity)
                                                                                   throws HTTPException
        Utility method to send a entity to the given HTTP address via HTTP PUT
        Parameters:
        address - The address to retrieve
        entity - The entity to send
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs during PUT.
      • headStringToURL

        public static org.apache.http.client.methods.CloseableHttpResponse headStringToURL​(String address)
                                                                                    throws HTTPException,
                                                                                           URISyntaxException
        Utility method to get the header of the HTTP Response from a URL.
        Parameters:
        address - The String address to retrieve
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs while retrieving response.
        URISyntaxException - if any.
      • headStringToURL

        public static org.apache.http.client.methods.CloseableHttpResponse headStringToURL​(URI address)
                                                                                    throws HTTPException
        Utility method to get the header of the HTTP Response from a URL.
        Parameters:
        address - The address to retrieve
        Returns:
        The CloseableHttpResponse from the given address
        Throws:
        HTTPException - Thrown if an error occurs while retrieving response.
      • delete

        public static org.apache.http.client.methods.CloseableHttpResponse delete​(URI address)
                                                                           throws HTTPException

        delete.

        Parameters:
        address - a URI object.
        Returns:
        a CloseableHttpResponse object.
        Throws:
        HTTPException - if any.