Package com.vonage.client
Class AbstractMethod<RequestT,ResultT>
java.lang.Object
com.vonage.client.AbstractMethod<RequestT,ResultT>
- Type Parameters:
RequestT- The type of the method-specific request object that will be used to construct an HTTP requestResultT- The type of method-specific response object which will be constructed from the returned HTTP response
- All Implemented Interfaces:
Method<RequestT,ResultT>
- Direct Known Subclasses:
Psd2Method,SearchRejectedMessagesEndpoint,SmsSearchEndpoint,SmsSingleSearchEndpoint
public abstract class AbstractMethod<RequestT,ResultT> extends java.lang.Object implements Method<RequestT,ResultT>
Abstract class to assist in implementing a call against a REST endpoint.
Concrete implementations must implement makeRequest(Object) to construct a RequestBuilder from the
provided parameterized request object, and parseResponse(HttpResponse) to construct the parameterized HttpResponse object.
The REST call is executed by calling execute(Object).
-
Field Summary
Fields Modifier and Type Field Description protected HttpWrapperhttpWrapper -
Constructor Summary
Constructors Constructor Description AbstractMethod(HttpWrapper httpWrapper) -
Method Summary
Modifier and Type Method Description protected org.apache.http.client.methods.RequestBuilderapplyAuth(org.apache.http.client.methods.RequestBuilder request)Apply an appropriate authentication method (specified bygetAcceptableAuthMethods()to the providedRequestBuilder, and return the result.ResultTexecute(RequestT request)Execute the REST call represented by this method object.protected abstract java.lang.Class[]getAcceptableAuthMethods()protected AuthMethodgetAuthMethod(java.lang.Class[] acceptableAuthMethods)Utility method for obtaining an appropriateAuthMethodfor this call.abstract org.apache.http.client.methods.RequestBuildermakeRequest(RequestT request)Construct and return a RequestBuilder instance from the provided request.abstract ResultTparseResponse(org.apache.http.HttpResponse response)Construct a ResultT representing the contents of the HTTP response returned from the Vonage Voice API.voidsetHttpClient(org.apache.http.client.HttpClient client)
-
Field Details
-
Constructor Details
-
Method Details
-
execute
public ResultT execute(RequestT request) throws VonageResponseParseException, VonageClientExceptionExecute the REST call represented by this method object.- Specified by:
executein interfaceMethod<RequestT,ResultT>- Parameters:
request- A RequestT representing input to the REST call to be made- Returns:
- A ResultT representing the response from the executed REST call
- Throws:
VonageClientException- if there is a problem parsing the HTTP responseVonageResponseParseException
-
applyAuth
protected org.apache.http.client.methods.RequestBuilder applyAuth(org.apache.http.client.methods.RequestBuilder request) throws VonageClientExceptionApply an appropriate authentication method (specified bygetAcceptableAuthMethods()to the providedRequestBuilder, and return the result.- Parameters:
request- A RequestBuilder which has not yet had authentication information applied- Returns:
- A RequestBuilder with appropriate authentication information applied (may or not be the same instance as
request
) - Throws:
VonageClientException- If no appropriateAuthMethodis available
-
getAuthMethod
protected AuthMethod getAuthMethod(java.lang.Class[] acceptableAuthMethods) throws VonageClientExceptionUtility method for obtaining an appropriateAuthMethodfor this call.- Parameters:
acceptableAuthMethods- an array of classes, representing authentication methods that are acceptable for this endpoint- Returns:
- An AuthMethod created from one of the provided acceptableAuthMethods.
- Throws:
VonageClientException- If no AuthMethod is available from the provided array of acceptableAuthMethods.
-
setHttpClient
-
getAcceptableAuthMethods
-
makeRequest
public abstract org.apache.http.client.methods.RequestBuilder makeRequest(RequestT request) throws java.io.UnsupportedEncodingExceptionConstruct and return a RequestBuilder instance from the provided request.- Parameters:
request- A RequestT representing input to the REST call to be made- Returns:
- A ResultT representing the response from the executed REST call
- Throws:
java.io.UnsupportedEncodingException- if UTF-8 encoding is not supported by the JVM
-
parseResponse
public abstract ResultT parseResponse(org.apache.http.HttpResponse response) throws java.io.IOExceptionConstruct a ResultT representing the contents of the HTTP response returned from the Vonage Voice API.- Parameters:
response- An HttpResponse returned from the Vonage Voice API- Returns:
- A ResultT type representing the result of the REST call
- Throws:
java.io.IOException- if a problem occurs parsing the response
-