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 responsepublic abstract class AbstractMethod<RequestT,ResultT> extends java.lang.Object implements Method<RequestT,ResultT>
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).
| Constructor and Description |
|---|
AbstractMethod(HttpWrapper httpWrapper) |
| Modifier and Type | Method and Description |
|---|---|
protected org.apache.http.client.methods.RequestBuilder |
applyAuth(org.apache.http.client.methods.RequestBuilder request)
Apply an appropriate authentication method (specified by
getAcceptableAuthMethods() to the provided
RequestBuilder, and return the result. |
ResultT |
execute(RequestT request)
Execute the REST call represented by this method object.
|
protected abstract java.lang.Class[] |
getAcceptableAuthMethods() |
protected AuthMethod |
getAuthMethod(java.lang.Class[] acceptableAuthMethods)
Utility method for obtaining an appropriate
AuthMethod for this call. |
abstract org.apache.http.client.methods.RequestBuilder |
makeRequest(RequestT request)
Construct and return a RequestBuilder instance from the provided request.
|
abstract ResultT |
parseResponse(org.apache.http.HttpResponse response)
Construct a ResultT representing the contents of the HTTP response returned from the Nexmo Voice API.
|
void |
setHttpClient(org.apache.http.client.HttpClient client) |
public AbstractMethod(HttpWrapper httpWrapper)
public ResultT execute(RequestT request) throws java.io.IOException, NexmoClientException
execute in interface Method<RequestT,ResultT>request - A RequestT representing input to the REST call to be madejava.io.IOException - if an exception occurs making the REST callNexmoClientException - if there is a problem parsing the HTTP responseprotected org.apache.http.client.methods.RequestBuilder applyAuth(org.apache.http.client.methods.RequestBuilder request) throws NexmoClientException
getAcceptableAuthMethods() to the provided
RequestBuilder, and return the result.request - A RequestBuilder which has not yet had authentication information appliedrequest)
NexmoClientException - If no appropriate AuthMethod is availableprotected AuthMethod getAuthMethod(java.lang.Class[] acceptableAuthMethods) throws NexmoClientException
AuthMethod for this call.acceptableAuthMethods - an array of classes, representing authentication methods that are acceptable for
this endpointNexmoClientException - If no AuthMethod is available from the provided array of acceptableAuthMethods.public void setHttpClient(org.apache.http.client.HttpClient client)
protected abstract java.lang.Class[] getAcceptableAuthMethods()
public abstract org.apache.http.client.methods.RequestBuilder makeRequest(RequestT request) throws NexmoClientException, java.io.UnsupportedEncodingException
request - A RequestT representing input to the REST call to be madeNexmoClientException - if a problem is encountered constructing the request or response.java.io.UnsupportedEncodingException - if UTF-8 encoding is not supported by the JVMpublic abstract ResultT parseResponse(org.apache.http.HttpResponse response) throws java.io.IOException, NexmoClientException
response - An HttpResponse returned from the Nexmo Voice APIjava.io.IOException - if a problem occurs parsing the responseNexmoClientException