Class HttpRequestGet

java.lang.Object
nzilbb.labbcat.http.HttpRequestGet

public class HttpRequestGet extends Object
GET HTTP request, using ordinary default request encoding, and encoding all arguments in the URL string
Author:
Robert Fromont robert@fromont.net.nz
  • Constructor Details

    • HttpRequestGet

      public HttpRequestGet(URL baseUrl)
      Constructor.
      Parameters:
      baseUrl - URL for LaBB-CAT server.
    • HttpRequestGet

      public HttpRequestGet(String baseUrl) throws MalformedURLException
      Constructor.
      Parameters:
      baseUrl - Base URL of the LaBB-CAT server.
      Throws:
      MalformedURLException - If the URL is invalid.
    • HttpRequestGet

      public HttpRequestGet(URL baseUrl, String authorization)
      Constructor.
      Parameters:
      baseUrl - Base URL of the LaBB-CAT server.
      authorization - Authorization string if any - e.g. value for "Authorization" header.
    • HttpRequestGet

      public HttpRequestGet(String baseUrl, String authorization) throws MalformedURLException
      Constructor.
      Parameters:
      baseUrl - Base URL of the LaBB-CAT server.
      authorization - Authorization string if any - e.g. value for "Authorization" header.
      Throws:
      MalformedURLException - If the URL is invalid.
  • Method Details

    • getBaseUrl

      public URL getBaseUrl()
      Getter for urlBaseUrl: Base URL for the request
      Returns:
      Base URL for the request
    • setBaseUrl

      public HttpRequestGet setBaseUrl(URL urlNewBaseUrl)
      Setter for urlBaseUrl: Base URL for the request
      Parameters:
      urlNewBaseUrl - Base URL for the request
      Returns:
      A reference to this object, so that setters can be chained.
    • getParameters

      public HashMap<String,Object> getParameters()
      Getter for mParameters: Resuest parameters
      Returns:
      Resuest parameters
    • setParameters

      public HttpRequestGet setParameters(HashMap<String,Object> mNewParameters)
      Setter for mParameters: Resuest parameters
      Parameters:
      mNewParameters - Resuest parameters
      Returns:
      A reference to this object, so that setters can be chained.
    • getHeaders

      public HashMap<String,String> getHeaders()
      Getter for mHeaders: HTTP request headers.
      Returns:
      HTTP request headers.
    • setHeaders

      public HttpRequestGet setHeaders(HashMap<String,String> mNewHeaders)
      Setter for mHeaders: HTTP request headers.
      Parameters:
      mNewHeaders - HTTP request headers.
      Returns:
      A reference to this object, so that setters can be chained.
    • getAuthorization

      public String getAuthorization()
      Getter for sAuthorization: The HTTP authorization string, or null if not required.
      Returns:
      The HTTP authorization string, or null if not required.
    • setAuthorization

      public HttpRequestGet setAuthorization(String sNewAuthorization)
      Setter for sAuthorization: The HTTP authorization string, or null if not required.
      Parameters:
      sNewAuthorization - The HTTP authorization string, or null if not required.
      Returns:
      A reference to this object, so that setters can be chained.
    • getMethod

      public String getMethod()
      Getter for method: HTTP method.
      Returns:
      HTTP method.
    • setMethod

      public HttpRequestGet setMethod(String newMethod)
      Setter for method: HTTP method.
      Parameters:
      newMethod - HTTP method.
      Returns:
      A reference to this object, so that setters can be chained.
    • setUserAgent

      public HttpRequestGet setUserAgent()
      Sets the user-agent header to indicate the name/version of the library.
      Returns:
      A reference to this object, so that setters can be chained.
    • setLanguage

      public HttpRequestGet setLanguage(String language)
      Set the Accept-Language header with the given language code, if any.,
      Parameters:
      language - The language code, e.g. "es-AR", or null.
      Returns:
      A reference to this object.
    • setParameter

      public HttpRequestGet setParameter(String sParameter, Object oValue)
      Sets a request parameter value
      Parameters:
      sParameter - Parameter name.
      oValue - Paremeter value.
      Returns:
      A reference to this object, so that setters can be chained.
    • setHeader

      public HttpRequestGet setHeader(String sKey, String sValue)
      Sets a request parameter value
      Parameters:
      sKey - Header name.
      sValue - header value.
      Returns:
      A reference to this object, so that setters can be chained.
    • getConnection

      public HttpURLConnection getConnection() throws IOException, MalformedURLException
      Fetches the request response
      Returns:
      Connection for the response
      Throws:
      IOException - If an IO error occurs.
      MalformedURLException - If the URL is invalid.
    • getQueryString

      public String getQueryString() throws UnsupportedEncodingException
      Generates the query string.
      Returns:
      The query string.
      Throws:
      UnsupportedEncodingException - If an encoding error occurs.
    • get

      Fetches the request response
      Returns:
      Input stream of the response
      Throws:
      IOException - If an IO error occurs.
      MalformedURLException - If the URL is invalid.
    • toString

      public String toString()
      String representation of the request, for logging.
      Overrides:
      toString in class Object
      Returns:
      A String representation of the request, for logging.