Class HTTPUtils

java.lang.Object
co.ecg.alpaca.core.framework.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 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    HTTPUtils(AlpacaProperties alpacaProperties)
    Constructor for HTTPUtils.
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.hc.client5.http.impl.classic.CloseableHttpClient
    Creates a CloseableHttpClient for the given address with attached credentials.
    static org.apache.hc.core5.http.ClassicHttpResponse
    delete(URI address)
    delete.
    Utility Method to Get the InputStream From the given URL
    Utility Method to Get the InputStream From the given URL
    static org.apache.hc.core5.http.ClassicHttpResponse
    Utility method to get the HTTP Response from a URL.
    static org.apache.hc.core5.http.ClassicHttpResponse
    Utility method to get the HTTP Response from a URL.
    static String
    Utility Method to Download a File as String from the given URL
    static org.apache.hc.core5.http.ClassicHttpResponse
    Utility method to get the header of the HTTP Response from a URL.
    static org.apache.hc.core5.http.ClassicHttpResponse
    Utility method to get the header of the HTTP Response from a URL.
    static org.apache.hc.core5.http.ClassicHttpResponse
    putEntityToURL(URI address, org.apache.hc.core5.http.io.entity.AbstractHttpEntity entity)
    Utility method to send a entity to the given HTTP address via HTTP PUT
    static org.apache.hc.core5.http.ClassicHttpResponse
    putStringToURL(String address, String string)
    Utility method to send a String to the given HTTP address via HTTP PUT
    static org.apache.hc.core5.http.ClassicHttpResponse
    putStringToURL(URI address, String string)
    Utility method to send a String to the given HTTP address via HTTP PUT

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • createHttpClientFromURL

      public static org.apache.hc.client5.http.impl.classic.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.hc.core5.http.ClassicHttpResponse 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 ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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 ClassicHttpResponse 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.hc.core5.http.ClassicHttpResponse 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 ClassicHttpResponse from the given address
      Throws:
      HTTPException - Thrown if an error occurs during PUT.
    • putEntityToURL

      public static org.apache.hc.core5.http.ClassicHttpResponse putEntityToURL(URI address, org.apache.hc.core5.http.io.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 ClassicHttpResponse from the given address
      Throws:
      HTTPException - Thrown if an error occurs during PUT.
    • headStringToURL

      public static org.apache.hc.core5.http.ClassicHttpResponse 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 ClassicHttpResponse from the given address
      Throws:
      HTTPException - Thrown if an error occurs while retrieving response.
      URISyntaxException - if any.
    • headStringToURL

      public static org.apache.hc.core5.http.ClassicHttpResponse 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 ClassicHttpResponse from the given address
      Throws:
      HTTPException - Thrown if an error occurs while retrieving response.
    • delete

      public static org.apache.hc.core5.http.ClassicHttpResponse delete(URI address) throws HTTPException

      delete.

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