Package com.bandwidth.controllers
Class BaseController
java.lang.Object
com.bandwidth.controllers.BaseController
- Direct Known Subclasses:
APIController
,APIController
,APIController
,MFAController
public abstract class BaseController
extends java.lang.Object
Base class for all Controllers.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
BaseController.RequestExecutor
RequestExecutor.protected static interface
BaseController.RequestSupplier
RequestSupplier.protected static interface
BaseController.ResponseHandler<T>
ResponseHandler. -
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,AuthManager>
authManagers
protected Configuration
config
Protected variables to hold an instance of Configuration.protected HttpCallback
httpCallback
Protected variable to hold an instance of HttpCallback if the user provides it.protected static java.lang.String
userAgent
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseController(Configuration config, HttpClient httpClient, java.util.Map<java.lang.String,AuthManager> authManagers)
protected
BaseController(Configuration config, HttpClient httpClient, java.util.Map<java.lang.String,AuthManager> authManagers, HttpCallback httpCallback)
-
Method Summary
Modifier and Type Method Description HttpClient
getClientInstance()
Shared instance of the Http client.HttpCallback
getHttpCallback()
Get httpCallback associated with this controller.<T> java.util.concurrent.CompletableFuture<ApiResponse<T>>
makeHttpCallAsync(BaseController.RequestSupplier requestSupplier, BaseController.RequestExecutor requestExecutor, BaseController.ResponseHandler<T> responseHandler)
Make an asynchronous HTTP endpoint call.protected void
validateResponse(HttpResponse response, HttpContext context)
Validates the response against HTTP errors defined at the API level.
-
Field Details
-
userAgent
protected static final java.lang.String userAgent- See Also:
- Constant Field Values
-
config
Protected variables to hold an instance of Configuration. -
httpCallback
Protected variable to hold an instance of HttpCallback if the user provides it. -
authManagers
-
-
Constructor Details
-
BaseController
protected BaseController(Configuration config, HttpClient httpClient, java.util.Map<java.lang.String,AuthManager> authManagers) -
BaseController
protected BaseController(Configuration config, HttpClient httpClient, java.util.Map<java.lang.String,AuthManager> authManagers, HttpCallback httpCallback)
-
-
Method Details
-
getHttpCallback
Get httpCallback associated with this controller.- Returns:
- HttpCallback
-
getClientInstance
Shared instance of the Http client.- Returns:
- The shared instance of the http client
-
validateResponse
Validates the response against HTTP errors defined at the API level.- Parameters:
response
- The response recievedcontext
- Context of the request and the recieved response- Throws:
ApiException
- Represents error response from the server.
-
makeHttpCallAsync
public <T> java.util.concurrent.CompletableFuture<ApiResponse<T>> makeHttpCallAsync(BaseController.RequestSupplier requestSupplier, BaseController.RequestExecutor requestExecutor, BaseController.ResponseHandler<T> responseHandler)Make an asynchronous HTTP endpoint call.- Type Parameters:
T
- The type of the object for response- Parameters:
requestSupplier
- An object of RequestSupplier to supply an instance of HttpRequestrequestExecutor
- An object of RequestExecutor to execute the given requestresponseHandler
- An object of ResponseHandler to handle the endpoint response- Returns:
- An object of type CompletableFuture of T
-