Package org.jets3t.service.utils
Class RestUtils
- java.lang.Object
-
- org.jets3t.service.utils.RestUtils
-
public class RestUtils extends Object
Utilities useful for REST/HTTP S3Service implementations.- Author:
- James Murty
-
-
Field Summary
Fields Modifier and Type Field Description static List<String>HTTP_HEADER_METADATA_NAMESA list of HTTP-specific header names, that may be present in S3Objects as metadata but which should be treated as plain HTTP headers during transmission (ie not converted into S3 Object metadata items).
-
Constructor Summary
Constructors Constructor Description RestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,String>convertHeadersToMap(org.apache.commons.httpclient.Header[] headers)static StringencodeUrlPath(String path, String delimiter)Encodes a URL string but leaves a delimiter string unencoded.static StringencodeUrlString(String path)Encodes a URL string, and ensures that spaces are encoded as "%20" instead of "+" to keep fussy web browsers happier.static longgetAWSTimeAdjustment()Calculates a time offset value to reflect the time difference between your computer's clock and the current time according to an AWS server, and returns the calculated time difference.static HttpClientAndConnectionManagerinitHttpConnection(AWSRequestAuthorizer awsRequestAuthorizer, org.apache.commons.httpclient.HostConfiguration hostConfig, Jets3tProperties jets3tProperties, String userAgentDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)Initialises, or re-initialises, the underlying HttpConnectionManager and HttpClient objects a service will use to communicate with an AWS service.static voidinitHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, String proxyHostAddress, int proxyPort, Jets3tProperties jets3tProperties)Initialises this service's HTTP proxy with the given proxy settings.static voidinitHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties)Initialises this service's HTTP proxy by auto-detecting the proxy settings.static voidinitHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, boolean proxyAutodetect, String proxyHostAddress, int proxyPort, String proxyUser, String proxyPassword, String proxyDomain)static voidinitHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, boolean proxyAutodetect, String proxyHostAddress, int proxyPort, String proxyUser, String proxyPassword, String proxyDomain, String endpoint)static voidinitHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, String endpoint)Initialises this service's HTTP proxy by auto-detecting the proxy settings using the given endpoint.static voidinitHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, String proxyHostAddress, int proxyPort, String proxyUser, String proxyPassword, String proxyDomain)Initialises this service's HTTP proxy for authentication using the given proxy settings.static StringmakeServiceCanonicalString(String method, String resource, Map<String,Object> headersMap, String expires, String headerPrefix, List<String> serviceResourceParameterNames)Calculate the canonical string for a REST/HTTP request to a storage service.
-
-
-
Field Detail
-
HTTP_HEADER_METADATA_NAMES
public static final List<String> HTTP_HEADER_METADATA_NAMES
A list of HTTP-specific header names, that may be present in S3Objects as metadata but which should be treated as plain HTTP headers during transmission (ie not converted into S3 Object metadata items). All items in this list are in lower case.This list includes the items:
Unchanged metadata names content-type content-md5 content-length content-language expires cache-control content-disposition content-encoding
-
-
Method Detail
-
encodeUrlString
public static String encodeUrlString(String path) throws ServiceException
Encodes a URL string, and ensures that spaces are encoded as "%20" instead of "+" to keep fussy web browsers happier.- Parameters:
path-- Returns:
- encoded URL.
- Throws:
ServiceException
-
encodeUrlPath
public static String encodeUrlPath(String path, String delimiter) throws ServiceException
Encodes a URL string but leaves a delimiter string unencoded. Spaces are encoded as "%20" instead of "+".- Parameters:
path-delimiter-- Returns:
- encoded URL string.
- Throws:
ServiceException
-
makeServiceCanonicalString
public static String makeServiceCanonicalString(String method, String resource, Map<String,Object> headersMap, String expires, String headerPrefix, List<String> serviceResourceParameterNames) throws UnsupportedEncodingException
Calculate the canonical string for a REST/HTTP request to a storage service. When expires is non-null, it will be used instead of the Date header.- Throws:
UnsupportedEncodingException
-
initHttpConnection
public static HttpClientAndConnectionManager initHttpConnection(AWSRequestAuthorizer awsRequestAuthorizer, org.apache.commons.httpclient.HostConfiguration hostConfig, Jets3tProperties jets3tProperties, String userAgentDescription, org.apache.commons.httpclient.auth.CredentialsProvider credentialsProvider)
Initialises, or re-initialises, the underlying HttpConnectionManager and HttpClient objects a service will use to communicate with an AWS service. If proxy settings are specified in this service'sJets3tPropertiesobject, these settings will also be passed on to the underlying objects.- Parameters:
hostConfig- Custom HTTP host configuration; e.g to register a custom Protocol Socket Factory. This parameter may be null, in which case a default host configuration will be used.
-
initHttpProxy
public static void initHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties)Initialises this service's HTTP proxy by auto-detecting the proxy settings.
-
initHttpProxy
public static void initHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, String endpoint)Initialises this service's HTTP proxy by auto-detecting the proxy settings using the given endpoint.
-
initHttpProxy
public static void initHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, String proxyHostAddress, int proxyPort, Jets3tProperties jets3tProperties)Initialises this service's HTTP proxy with the given proxy settings.- Parameters:
proxyHostAddress-proxyPort-
-
initHttpProxy
public static void initHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, String proxyHostAddress, int proxyPort, String proxyUser, String proxyPassword, String proxyDomain)Initialises this service's HTTP proxy for authentication using the given proxy settings.- Parameters:
proxyHostAddress-proxyPort-proxyUser-proxyPassword-proxyDomain- if a proxy domain is provided, anNTCredentialscredential provider will be used. If the proxy domain is null, aUsernamePasswordCredentialscredentials provider will be used.
-
initHttpProxy
public static void initHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, boolean proxyAutodetect, String proxyHostAddress, int proxyPort, String proxyUser, String proxyPassword, String proxyDomain)- Parameters:
httpClient-proxyAutodetect-proxyHostAddress-proxyPort-proxyUser-proxyPassword-proxyDomain-
-
initHttpProxy
public static void initHttpProxy(org.apache.commons.httpclient.HttpClient httpClient, Jets3tProperties jets3tProperties, boolean proxyAutodetect, String proxyHostAddress, int proxyPort, String proxyUser, String proxyPassword, String proxyDomain, String endpoint)- Parameters:
httpClient-proxyAutodetect-proxyHostAddress-proxyPort-proxyUser-proxyPassword-proxyDomain-endpoint-
-
getAWSTimeAdjustment
public static long getAWSTimeAdjustment() throws ExceptionCalculates a time offset value to reflect the time difference between your computer's clock and the current time according to an AWS server, and returns the calculated time difference. Ideally you should not rely on this method to overcome clock-related disagreements between your computer and AWS. If you computer is set to update its clock periodically and has the correct timezone setting you should never have to resort to this work-around.- Throws:
Exception
-
-