Package org.azd.utils
Class BaseRestClient
java.lang.Object
org.azd.utils.BaseRestClient
- Direct Known Subclasses:
RestClientProvider
Deprecated.
BaseRestClient that encapsulates the logic for managing request and response for REST API.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CompletableFuture<HttpResponse<T>>
delete
(String requestUrl, String token, HttpResponse.BodyHandler<T> handler) Deprecated.Sends a DELETE request to REST API with basic authenticationstatic <T> CompletableFuture<HttpResponse<T>>
get
(String requestUrl, String token, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) Deprecated.Sends a GET request to REST API with basic authenticationprotected static HttpRequest.Builder
getBuilder
(String requestUrl, String token) Deprecated.Helper method to create the request with request url and access token.static HttpClient.Redirect
Deprecated.Get the current redirect policy.protected static <T> CompletableFuture<HttpResponse<T>>
getResponse
(HttpRequest r, HttpResponse.BodyHandler<T> handler, boolean callback) Deprecated.Helper method to get the response based on built http request.static <T> CompletableFuture<HttpResponse<T>>
patch
(String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) Deprecated.Sends a PATCH request to REST API with basic authentication and request bodystatic <T> CompletableFuture<HttpResponse<T>>
post
(String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) Deprecated.Sends a POST request to REST API with oauth authentication, content length of the request and request bodystatic <T> CompletableFuture<HttpResponse<T>>
put
(String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) Deprecated.Sends a PUT request to REST API with basic authentication and request bodystatic <T> CompletableFuture<HttpResponse<T>>
response
(RequestMethod requestMethod, String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) Deprecated.Manages the request method and response from REST API.static void
setRedirectPolicy
(HttpClient.Redirect redirectPolicy) Deprecated.Set the current redirect policy.
-
Constructor Details
-
BaseRestClient
public BaseRestClient()Deprecated.
-
-
Method Details
-
getRedirectPolicy
Deprecated.Get the current redirect policy.- Returns:
- HttpClient.Redirect policy.
-
setRedirectPolicy
Deprecated.Set the current redirect policy.- Parameters:
redirectPolicy
- HttpClient.Redirect policy.
-
get
public static <T> CompletableFuture<HttpResponse<T>> get(String requestUrl, String token, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) Deprecated.Sends a GET request to REST API with basic authentication- Parameters:
requestUrl
- pass the request urltoken
- pass the personal access tokenhandler
- HttpResponse body handlercontentType
- specify the content typecallback
- If true client will be built with redirect policy- Returns:
- response string from the API
-
post
public static <T> CompletableFuture<HttpResponse<T>> post(String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) throws AzDException Deprecated.Sends a POST request to REST API with oauth authentication, content length of the request and request body- Parameters:
requestUrl
- pass the request urltoken
- pass the personal access tokenpublisher
- BodyPublisher with request bodyhandler
- HttpResponse body handlerscontentType
- Content type for setting headerscallback
- If true client will be built with redirect policy- Returns:
- response string from the API if any
- Throws:
AzDException
- throws user friendly error message with error code from API
-
patch
public static <T> CompletableFuture<HttpResponse<T>> patch(String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) throws AzDException Deprecated.Sends a PATCH request to REST API with basic authentication and request body- Parameters:
requestUrl
- pass the request urltoken
- pass the personal access tokenpublisher
- BodyPublisher with request bodyhandler
- HttpResponse body handlerscontentType
- Content type for setting headerscallback
- If true client will be built with redirect policy- Returns:
- response string from the API if any
- Throws:
AzDException
- throws user friendly error message with error code from API
-
put
public static <T> CompletableFuture<HttpResponse<T>> put(String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) throws AzDException Deprecated.Sends a PUT request to REST API with basic authentication and request body- Parameters:
requestUrl
- pass the request urltoken
- pass the personal access tokenpublisher
- BodyPublisher with request bodyhandler
- HttpResponse body handlerscontentType
- Content type for setting headerscallback
- If true client will be built with redirect policy- Returns:
- response string from the API if any
- Throws:
AzDException
- throws user friendly error message with error code from API
-
delete
public static <T> CompletableFuture<HttpResponse<T>> delete(String requestUrl, String token, HttpResponse.BodyHandler<T> handler) Deprecated.Sends a DELETE request to REST API with basic authentication- Parameters:
requestUrl
- pass the request urltoken
- pass the personal access token- Returns:
- response string from the API if any
-
response
public static <T> CompletableFuture<HttpResponse<T>> response(RequestMethod requestMethod, String requestUrl, String token, HttpRequest.BodyPublisher publisher, HttpResponse.BodyHandler<T> handler, CustomHeader contentType, boolean callback) throws AzDException Deprecated.Manages the request method and response from REST API.- Parameters:
requestMethod
- Type of request to send. Such as GET, POST, PUT, PATCH and DELETE.requestUrl
- Request url to call the Api.token
- Personal access token.publisher
- HttpRequest body publisher typehandler
- HttpResponse body typecontentType
- Custom headers for sending the requestcallback
- If true default redirect policy will be applied- Returns:
- Completable future object.
- Throws:
AzDException
- Default Api exception handler.
-
getBuilder
Deprecated.Helper method to create the request with request url and access token.- Parameters:
requestUrl
- Pass the request url.token
- Pass the access token. Base64 encoding will be taken care when building the request.- Returns:
- HttpRequest builder object.
-
getResponse
protected static <T> CompletableFuture<HttpResponse<T>> getResponse(HttpRequest r, HttpResponse.BodyHandler<T> handler, boolean callback) Deprecated.Helper method to get the response based on built http request.- Type Parameters:
T
- Generic response type object.- Parameters:
r
- Http request object.handler
- Handlers for accepting the response content as. Example string or input stream etc.callback
- If true follows redirects.- Returns:
- generic type of future of http response.
-