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 request
ResultT - 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 HttpWrapper httpWrapper  
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractMethod​(HttpWrapper httpWrapper)  
  • Method Summary

    Modifier and Type Method 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 Vonage Voice API.
    void setHttpClient​(org.apache.http.client.HttpClient client)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • execute

      Execute the REST call represented by this method object.
      Specified by:
      execute in interface Method<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 response
      VonageResponseParseException
    • applyAuth

      protected org.apache.http.client.methods.RequestBuilder applyAuth​(org.apache.http.client.methods.RequestBuilder request) throws VonageClientException
      Apply an appropriate authentication method (specified by getAcceptableAuthMethods() to the provided RequestBuilder, 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 appropriate AuthMethod is available
    • getAuthMethod

      protected AuthMethod getAuthMethod​(java.lang.Class[] acceptableAuthMethods) throws VonageClientException
      Utility method for obtaining an appropriate AuthMethod for 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

      public void setHttpClient​(org.apache.http.client.HttpClient client)
    • getAcceptableAuthMethods

      protected abstract java.lang.Class[] getAcceptableAuthMethods()
    • makeRequest

      public abstract org.apache.http.client.methods.RequestBuilder makeRequest​(RequestT request) throws java.io.UnsupportedEncodingException
      Construct 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.IOException
      Construct 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