org.jclouds.http
Class HttpUtils
java.lang.Object
org.jclouds.http.HttpUtils
@Singleton
public class HttpUtils
- extends Object
- Author:
- Adrian Cole
Constructor Summary |
HttpUtils(int connectionTimeout,
int soTimeout,
int globalMaxConnections,
int globalMaxConnectionsPerHost)
|
Method Summary |
static Long |
attemptToParseSizeAndRangeFromHeaders(HttpMessage from)
|
static void |
checkRequestHasContentLengthOrChunkedEncoding(HttpMessage request,
String message)
|
void |
checkRequestHasRequiredProperties(HttpRequest message)
|
static byte[] |
closeClientButKeepContentStream(PayloadEnclosing response)
Content stream may need to be read. |
static void |
copy(ContentMetadata fromMd,
MutableContentMetadata toMd)
|
static URI |
createBaseEndpointFor(URI endpoint)
keys to the map are only used for socket information, not path. |
static URI |
createUri(String uriPath)
Used to extract the URI and authentication data from a String. |
int |
getConnectionTimeout()
|
static com.google.common.collect.Multimap<String,String> |
getContentHeadersFromMetadata(ContentMetadata md)
|
int |
getMaxConnections()
|
int |
getMaxConnectionsPerHost()
|
String |
getProxyHost()
|
String |
getProxyPassword()
|
Integer |
getProxyPort()
|
String |
getProxyUser()
|
int |
getSocketOpenTimeout()
|
void |
logRequest(Logger logger,
HttpRequest request,
String prefix)
|
void |
logResponse(Logger logger,
HttpResponse response,
String prefix)
|
static URI |
parseEndPoint(String hostHeader)
|
boolean |
relaxHostname()
|
static void |
releasePayload(HttpMessage from)
|
static URI |
replaceHostInEndPoint(URI endPoint,
String host)
|
static
|
returnValueOnCodeOrNull(Exception from,
T value,
com.google.common.base.Predicate<Integer> codePredicate)
|
static String |
sortAndConcatHeadersIntoString(com.google.common.collect.Multimap<String,String> headers)
|
static byte[] |
toByteArrayOrNull(PayloadEnclosing response)
|
boolean |
trustAllCerts()
|
boolean |
useSystemProxies()
|
String |
valueOrEmpty(byte[] md5)
|
String |
valueOrEmpty(Collection<String> collection)
|
String |
valueOrEmpty(String in)
|
static void |
wirePayloadIfEnabled(Wire wire,
HttpMessage request)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
HttpUtils
@Inject
public HttpUtils(@Named(value="jclouds.connection-timeout")
int connectionTimeout,
@Named(value="jclouds.so-timeout")
int soTimeout,
@Named(value="jclouds.max-connections-per-context")
int globalMaxConnections,
@Named(value="jclouds.max-connections-per-host")
int globalMaxConnectionsPerHost)
getProxyHost
public String getProxyHost()
- See Also:
org.jclouds.Constants.PROPERTY_PROXY_HOST
getProxyPort
public Integer getProxyPort()
- See Also:
org.jclouds.Constants.PROPERTY_PROXY_PORT
getProxyUser
public String getProxyUser()
- See Also:
org.jclouds.Constants.PROPERTY_PROXY_USER
getProxyPassword
public String getProxyPassword()
- See Also:
org.jclouds.Constants.PROPERTY_PROXY_PASSWORD
getSocketOpenTimeout
public int getSocketOpenTimeout()
getConnectionTimeout
public int getConnectionTimeout()
relaxHostname
public boolean relaxHostname()
trustAllCerts
public boolean trustAllCerts()
useSystemProxies
public boolean useSystemProxies()
getMaxConnections
public int getMaxConnections()
getMaxConnectionsPerHost
public int getMaxConnectionsPerHost()
createBaseEndpointFor
public static URI createBaseEndpointFor(URI endpoint)
- keys to the map are only used for socket information, not path. In this case, you should
remove any path or query details from the URI.
getContentHeadersFromMetadata
public static com.google.common.collect.Multimap<String,String> getContentHeadersFromMetadata(ContentMetadata md)
toByteArrayOrNull
public static byte[] toByteArrayOrNull(PayloadEnclosing response)
closeClientButKeepContentStream
public static byte[] closeClientButKeepContentStream(PayloadEnclosing response)
- Content stream may need to be read. However, we should always close the http stream.
- Throws:
IOException
copy
public static void copy(ContentMetadata fromMd,
MutableContentMetadata toMd)
parseEndPoint
public static URI parseEndPoint(String hostHeader)
replaceHostInEndPoint
public static URI replaceHostInEndPoint(URI endPoint,
String host)
createUri
public static URI createUri(String uriPath)
- Used to extract the URI and authentication data from a String. Note that the java URI class
breaks, if there are special characters like '/' present. Otherwise, we wouldn't need this
class, and we could simply use URI.create("uri").getUserData(); Also, URI breaks if there are
curly braces.
logRequest
public void logRequest(Logger logger,
HttpRequest request,
String prefix)
logResponse
public void logResponse(Logger logger,
HttpResponse response,
String prefix)
sortAndConcatHeadersIntoString
public static String sortAndConcatHeadersIntoString(com.google.common.collect.Multimap<String,String> headers)
checkRequestHasRequiredProperties
public void checkRequestHasRequiredProperties(HttpRequest message)
releasePayload
public static void releasePayload(HttpMessage from)
valueOrEmpty
public String valueOrEmpty(String in)
valueOrEmpty
public String valueOrEmpty(byte[] md5)
valueOrEmpty
public String valueOrEmpty(Collection<String> collection)
attemptToParseSizeAndRangeFromHeaders
public static Long attemptToParseSizeAndRangeFromHeaders(HttpMessage from)
throws HttpException
- Throws:
HttpException
checkRequestHasContentLengthOrChunkedEncoding
public static void checkRequestHasContentLengthOrChunkedEncoding(HttpMessage request,
String message)
wirePayloadIfEnabled
public static void wirePayloadIfEnabled(Wire wire,
HttpMessage request)
returnValueOnCodeOrNull
public static <T> T returnValueOnCodeOrNull(Exception from,
T value,
com.google.common.base.Predicate<Integer> codePredicate)
Copyright © 2009-2011 jclouds. All Rights Reserved.