Package com.dropbox.core
Class DbxRequestUtil
- java.lang.Object
-
- com.dropbox.core.DbxRequestUtil
-
public final class DbxRequestUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DbxRequestUtil.RequestMaker<T,E extends java.lang.Throwable>
static class
DbxRequestUtil.ResponseHandler<T>
-
Field Summary
Fields Modifier and Type Field Description static DbxGlobalCallbackFactory
sharedCallbackFactory
-
Constructor Summary
Constructors Constructor Description DbxRequestUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<HttpRequestor.Header>
addAuthHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String accessToken)
static java.util.List<HttpRequestor.Header>
addBasicAuthHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String username, java.lang.String password)
static java.util.List<HttpRequestor.Header>
addPathRootHeader(java.util.List<HttpRequestor.Header> headers, PathRoot pathRoot)
static java.util.List<HttpRequestor.Header>
addSelectAdminHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String adminId)
static java.util.List<HttpRequestor.Header>
addSelectUserHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String memberId)
static java.util.List<HttpRequestor.Header>
addUserAgentHeader(java.util.List<HttpRequestor.Header> headers, DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier)
static java.util.List<HttpRequestor.Header>
addUserLocaleHeader(java.util.List<HttpRequestor.Header> headers, DbxRequestConfig requestConfig)
static java.lang.String
buildUri(java.lang.String host, java.lang.String path)
static java.lang.String
buildUrlWithParams(java.lang.String userLocale, java.lang.String host, java.lang.String path, java.lang.String[] params)
static HttpRequestor.Header
buildUserAgentHeader(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier)
static <T> T
doGet(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler)
static <T> T
doPost(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler)
static <T> T
doPostNoAuth(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler)
static java.lang.String
encodeUrlParam(java.lang.String s)
static <T> T
finishResponse(HttpRequestor.Response response, DbxRequestUtil.ResponseHandler<T> handler)
static java.lang.String
getContentType(HttpRequestor.Response response)
static java.lang.String
getFirstHeader(HttpRequestor.Response response, java.lang.String name)
static java.lang.String
getFirstHeaderMaybe(HttpRequestor.Response response, java.lang.String name)
static java.lang.String
getRequestId(HttpRequestor.Response response)
static byte[]
loadErrorBody(HttpRequestor.Response response)
static java.lang.String
parseErrorBody(java.lang.String requestId, int statusCode, byte[] body)
static <T> T
readJsonFromErrorMessage(StoneSerializer<T> serializer, java.lang.String message, java.lang.String requestId)
static <T> T
readJsonFromResponse(JsonReader<T> reader, HttpRequestor.Response response)
static java.util.List<HttpRequestor.Header>
removeAuthHeader(java.util.List<HttpRequestor.Header> headers)
static <T,E extends java.lang.Throwable>
TrunAndRetry(int maxRetries, DbxRequestUtil.RequestMaker<T,E> requestMaker)
static HttpRequestor.Response
startGet(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers)
Convenience function for making HTTP GET requests.static HttpRequestor.Response
startPostNoAuth(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers)
Convenience function for making HTTP POST requests.static HttpRequestor.Response
startPostRaw(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, byte[] body, java.util.List<HttpRequestor.Header> headers)
Convenience function for making HTTP POST requests.static HttpRequestor.Uploader
startPut(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers)
Convenience function for making HTTP PUT requests.static java.lang.String[]
toParamsArray(java.util.Map<java.lang.String,java.lang.String> params)
static DbxException
unexpectedStatus(HttpRequestor.Response response)
static DbxException
unexpectedStatus(HttpRequestor.Response response, java.lang.String userId)
-
-
-
Field Detail
-
sharedCallbackFactory
public static DbxGlobalCallbackFactory sharedCallbackFactory
-
-
Method Detail
-
encodeUrlParam
public static java.lang.String encodeUrlParam(java.lang.String s)
-
buildUrlWithParams
public static java.lang.String buildUrlWithParams(java.lang.String userLocale, java.lang.String host, java.lang.String path, java.lang.String[] params)
-
toParamsArray
public static java.lang.String[] toParamsArray(java.util.Map<java.lang.String,java.lang.String> params)
-
buildUri
public static java.lang.String buildUri(java.lang.String host, java.lang.String path)
-
addAuthHeader
public static java.util.List<HttpRequestor.Header> addAuthHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String accessToken)
-
addSelectUserHeader
public static java.util.List<HttpRequestor.Header> addSelectUserHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String memberId)
-
addSelectAdminHeader
public static java.util.List<HttpRequestor.Header> addSelectAdminHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String adminId)
-
addBasicAuthHeader
public static java.util.List<HttpRequestor.Header> addBasicAuthHeader(java.util.List<HttpRequestor.Header> headers, java.lang.String username, java.lang.String password)
-
addUserAgentHeader
public static java.util.List<HttpRequestor.Header> addUserAgentHeader(java.util.List<HttpRequestor.Header> headers, DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier)
-
addUserLocaleHeader
public static java.util.List<HttpRequestor.Header> addUserLocaleHeader(java.util.List<HttpRequestor.Header> headers, DbxRequestConfig requestConfig)
-
buildUserAgentHeader
public static HttpRequestor.Header buildUserAgentHeader(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier)
-
addPathRootHeader
public static java.util.List<HttpRequestor.Header> addPathRootHeader(java.util.List<HttpRequestor.Header> headers, PathRoot pathRoot)
-
removeAuthHeader
public static java.util.List<HttpRequestor.Header> removeAuthHeader(java.util.List<HttpRequestor.Header> headers)
-
startGet
public static HttpRequestor.Response startGet(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers) throws NetworkIOException
Convenience function for making HTTP GET requests.- Throws:
NetworkIOException
-
startPut
public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers) throws NetworkIOException
Convenience function for making HTTP PUT requests.- Throws:
NetworkIOException
-
startPostNoAuth
public static HttpRequestor.Response startPostNoAuth(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers) throws NetworkIOException
Convenience function for making HTTP POST requests.- Throws:
NetworkIOException
-
startPostRaw
public static HttpRequestor.Response startPostRaw(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, byte[] body, java.util.List<HttpRequestor.Header> headers) throws NetworkIOException
Convenience function for making HTTP POST requests. Like startPostNoAuth but takes byte[] instead of params.- Throws:
NetworkIOException
-
loadErrorBody
public static byte[] loadErrorBody(HttpRequestor.Response response) throws NetworkIOException
- Throws:
NetworkIOException
-
parseErrorBody
public static java.lang.String parseErrorBody(java.lang.String requestId, int statusCode, byte[] body) throws BadResponseException
- Throws:
BadResponseException
-
unexpectedStatus
public static DbxException unexpectedStatus(HttpRequestor.Response response) throws NetworkIOException, BadResponseException
-
unexpectedStatus
public static DbxException unexpectedStatus(HttpRequestor.Response response, java.lang.String userId) throws NetworkIOException, BadResponseException
-
readJsonFromResponse
public static <T> T readJsonFromResponse(JsonReader<T> reader, HttpRequestor.Response response) throws BadResponseException, NetworkIOException
-
readJsonFromErrorMessage
public static <T> T readJsonFromErrorMessage(StoneSerializer<T> serializer, java.lang.String message, java.lang.String requestId) throws com.fasterxml.jackson.core.JsonParseException
- Throws:
com.fasterxml.jackson.core.JsonParseException
-
doGet
public static <T> T doGet(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler) throws DbxException
- Throws:
DbxException
-
doPost
public static <T> T doPost(DbxRequestConfig requestConfig, java.lang.String accessToken, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler) throws DbxException
- Throws:
DbxException
-
doPostNoAuth
public static <T> T doPostNoAuth(DbxRequestConfig requestConfig, java.lang.String sdkUserAgentIdentifier, java.lang.String host, java.lang.String path, java.lang.String[] params, java.util.List<HttpRequestor.Header> headers, DbxRequestUtil.ResponseHandler<T> handler) throws DbxException
- Throws:
DbxException
-
finishResponse
public static <T> T finishResponse(HttpRequestor.Response response, DbxRequestUtil.ResponseHandler<T> handler) throws DbxException
- Throws:
DbxException
-
getFirstHeader
public static java.lang.String getFirstHeader(HttpRequestor.Response response, java.lang.String name) throws BadResponseException
- Throws:
BadResponseException
-
getFirstHeaderMaybe
public static java.lang.String getFirstHeaderMaybe(HttpRequestor.Response response, java.lang.String name)
-
getRequestId
public static java.lang.String getRequestId(HttpRequestor.Response response)
-
getContentType
public static java.lang.String getContentType(HttpRequestor.Response response)
-
runAndRetry
public static <T,E extends java.lang.Throwable> T runAndRetry(int maxRetries, DbxRequestUtil.RequestMaker<T,E> requestMaker) throws DbxException, E extends java.lang.Throwable
- Throws:
DbxException
E extends java.lang.Throwable
-
-