Package com.bandwidth.controllers
Class BaseController
- java.lang.Object
-
- com.bandwidth.controllers.BaseController
-
- Direct Known Subclasses:
APIController
,APIController
,APIController
,APIController
,MFAController
public abstract class BaseController extends 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 Map<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 String
userAgent
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseController(Configuration config, HttpClient httpClient, Map<String,AuthManager> authManagers)
protected
BaseController(Configuration config, HttpClient httpClient, Map<String,AuthManager> authManagers, HttpCallback httpCallback)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpClient
getClientInstance()
Shared instance of the Http client.HttpCallback
getHttpCallback()
Get httpCallback associated with this controller.<T> 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 Detail
-
userAgent
protected static final String userAgent
- See Also:
- Constant Field Values
-
config
protected final Configuration config
Protected variables to hold an instance of Configuration.
-
httpCallback
protected final HttpCallback httpCallback
Protected variable to hold an instance of HttpCallback if the user provides it.
-
authManagers
protected Map<String,AuthManager> authManagers
-
-
Constructor Detail
-
BaseController
protected BaseController(Configuration config, HttpClient httpClient, Map<String,AuthManager> authManagers)
-
BaseController
protected BaseController(Configuration config, HttpClient httpClient, Map<String,AuthManager> authManagers, HttpCallback httpCallback)
-
-
Method Detail
-
getHttpCallback
public HttpCallback getHttpCallback()
Get httpCallback associated with this controller.- Returns:
- HttpCallback
-
getClientInstance
public HttpClient getClientInstance()
Shared instance of the Http client.- Returns:
- The shared instance of the http client
-
validateResponse
protected void validateResponse(HttpResponse response, HttpContext context) throws ApiException
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> 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
-
-