Package co.ecg.alpaca.core.framework
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 classHTTPUtils.HttpMkCol
-
Constructor Summary
Constructors Constructor Description HTTPUtils(AlpacaProperties alpacaConfig)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.apache.http.impl.client.CloseableHttpClientcreateHttpClientFromURL(URL url)Creates a CloseableHttpClient for the given address with attached credentials.static org.apache.http.client.methods.CloseableHttpResponsedelete(URI address)delete.static InputStreamgetInputStreamFromURL(String address)Utility Method to Get the InputStream From the given URLstatic InputStreamgetInputStreamFromURL(URI address)Utility Method to Get the InputStream From the given URLstatic org.apache.http.client.methods.CloseableHttpResponsegetResponseFromURL(String address)Utility method to get the HTTP Response from a URL.static org.apache.http.client.methods.CloseableHttpResponsegetResponseFromURL(URI address)Utility method to get the HTTP Response from a URL.static StringgetStringFromURL(String address)Utility Method to Download a File as String from the given URLstatic org.apache.http.client.methods.CloseableHttpResponseheadStringToURL(String address)Utility method to get the header of the HTTP Response from a URL.static org.apache.http.client.methods.CloseableHttpResponseheadStringToURL(URI address)Utility method to get the header of the HTTP Response from a URL.static org.apache.http.client.methods.CloseableHttpResponseputEntityToURL(URI address, org.apache.http.entity.AbstractHttpEntity entity)Utility method to send a entity to the given HTTP address via HTTP PUTstatic org.apache.http.client.methods.CloseableHttpResponseputStringToURL(String address, String string)Utility method to send a String to the given HTTP address via HTTP PUTstatic org.apache.http.client.methods.CloseableHttpResponseputStringToURL(URI address, String string)Utility method to send a String to the given HTTP address via HTTP PUT
-
-
-
Constructor Detail
-
HTTPUtils
@Autowired public HTTPUtils(AlpacaProperties alpacaConfig)
-
-
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 retrievestring- 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 retrievestring- 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 retrieveentity- 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- aURIobject.- Returns:
- a
CloseableHttpResponseobject. - Throws:
HTTPException- if any.
-
-