Package nzilbb.labbcat.http
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 Summary
Constructors Constructor Description HttpRequestGet(String baseUrl)Constructor.HttpRequestGet(String baseUrl, String authorization)Constructor.HttpRequestGet(URL baseUrl)Constructor.HttpRequestGet(URL baseUrl, String authorization)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpURLConnectionget()Fetches the request responseStringgetAuthorization()Getter forsAuthorization: The HTTP authorization string, or null if not required.URLgetBaseUrl()Getter forurlBaseUrl: Base URL for the requestHttpURLConnectiongetConnection()Fetches the request responseHashMap<String,String>getHeaders()Getter formHeaders: HTTP request headers.StringgetMethod()Getter formethod: HTTP method.HashMap<String,Object>getParameters()Getter formParameters: Resuest parametersStringgetQueryString()Generates the query string.HttpRequestGetsetAuthorization(String sNewAuthorization)Setter forsAuthorization: The HTTP authorization string, or null if not required.HttpRequestGetsetBaseUrl(URL urlNewBaseUrl)Setter forurlBaseUrl: Base URL for the requestHttpRequestGetsetHeader(String sKey, String sValue)Sets a request parameter valueHttpRequestGetsetHeaders(HashMap<String,String> mNewHeaders)Setter formHeaders: HTTP request headers.HttpRequestGetsetLanguage(String language)Set the Accept-Language header with the given language code, if any.,HttpRequestGetsetMethod(String newMethod)Setter formethod: HTTP method.HttpRequestGetsetParameter(String sParameter, Object oValue)Sets a request parameter valueHttpRequestGetsetParameters(HashMap<String,Object> mNewParameters)Setter formParameters: Resuest parametersHttpRequestGetsetUserAgent()Sets the user-agent header to indicate the name/version of the library.StringtoString()String representation of the request, for logging.
-
-
-
Constructor Detail
-
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 Detail
-
getBaseUrl
public URL getBaseUrl()
Getter forurlBaseUrl: Base URL for the request- Returns:
- Base URL for the request
-
setBaseUrl
public HttpRequestGet setBaseUrl(URL urlNewBaseUrl)
Setter forurlBaseUrl: 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 formParameters: Resuest parameters- Returns:
- Resuest parameters
-
setParameters
public HttpRequestGet setParameters(HashMap<String,Object> mNewParameters)
Setter formParameters: 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 formHeaders: HTTP request headers.- Returns:
- HTTP request headers.
-
setHeaders
public HttpRequestGet setHeaders(HashMap<String,String> mNewHeaders)
Setter formHeaders: 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 forsAuthorization: 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 forsAuthorization: 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 formethod: HTTP method.- Returns:
- HTTP method.
-
setMethod
public HttpRequestGet setMethod(String newMethod)
Setter formethod: 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
public HttpURLConnection get() throws IOException, MalformedURLException
Fetches the request response- Returns:
- Input stream of the response
- Throws:
IOException- If an IO error occurs.MalformedURLException- If the URL is invalid.
-
-