Package com.restfb

Class DefaultWebRequestor

java.lang.Object
com.restfb.DefaultWebRequestor
All Implemented Interfaces:
WebRequestor
Direct Known Subclasses:
ETagWebRequestor

public class DefaultWebRequestor extends Object implements WebRequestor
Default implementation of a service that sends HTTP requests to the Facebook API endpoint.
Author:
Mark Allen
  • Constructor Details

  • Method Details

    • executeGet

      public WebRequestor.Response executeGet(String url, String headerAccessToken) throws IOException
      Description copied from interface: WebRequestor
      Given a Facebook API endpoint URL, execute a GET against it.
      Specified by:
      executeGet in interface WebRequestor
      Parameters:
      url - The URL to make a GET request for, including URL parameters.
      headerAccessToken - access token used in the header. May be null, if access token is already part of the query string
      Returns:
      HTTP response data.
      Throws:
      IOException - If an error occurs while performing the GET operation.
    • executeGet

      Description copied from interface: WebRequestor
      Given a Facebook API endpoint URL, execute a GET against it.
      Specified by:
      executeGet in interface WebRequestor
      Parameters:
      url - The URL to make a GET request for, including URL parameters.
      Returns:
      HTTP response data.
      Throws:
      IOException - If an error occurs while performing the GET operation.
    • executePost

      public WebRequestor.Response executePost(String url, String parameters, String headerAccessToken) throws IOException
      Description copied from interface: WebRequestor
      Given a Facebook API endpoint URL and parameter string, execute a POST to the endpoint URL.
      Specified by:
      executePost in interface WebRequestor
      Parameters:
      url - The URL to POST to.
      parameters - The parameters to be POSTed.
      headerAccessToken - access token used in the header. May be null, if access token is already part of the query string
      Returns:
      HTTP response data.
      Throws:
      IOException - If an error occurs while performing the POST.
    • executePost

      public WebRequestor.Response executePost(String url, String parameters, List<BinaryAttachment> binaryAttachments, String headerAccessToken) throws IOException
      Description copied from interface: WebRequestor
      Given a Facebook API endpoint URL and parameter string, execute a POST to the endpoint URL.
      Specified by:
      executePost in interface WebRequestor
      Parameters:
      url - The URL to POST to.
      parameters - The parameters to be POSTed.
      binaryAttachments - Optional binary attachments to be included in the POST body (e.g. photos and videos).
      headerAccessToken - access token used in the header. May be null, if access token is already part of the query string
      Returns:
      HTTP response data.
      Throws:
      IOException - If an error occurs while performing the POST.
    • initHeaderAccessToken

      protected void initHeaderAccessToken(HttpURLConnection httpUrlConnection, String headerAccessToken)
    • openConnection

      protected HttpURLConnection openConnection(URL url) throws IOException
      Given a url, opens and returns a connection to it.

      If you'd like to pipe your connection through a proxy, this is the place to do so.

      Parameters:
      url - The URL to connect to.
      Returns:
      A connection to the URL.
      Throws:
      IOException - If an error occurs while establishing the connection.
      Since:
      1.6.3
    • customizeConnection

      protected void customizeConnection(HttpURLConnection connection)
      Hook method which allows subclasses to easily customize the connections created by executeGet(String) and executePost(String, String, String) - for example, setting a custom read timeout or request header.

      This implementation is a no-op.

      Parameters:
      connection - The connection to customize.
    • closeQuietly

      protected void closeQuietly(Closeable closeable)
      Attempts to cleanly close a resource, swallowing any exceptions that might occur since there's no way to recover anyway.

      It's OK to pass null in, this method will no-op in that case.

      Parameters:
      closeable - The resource to close.
    • closeQuietly

      protected void closeQuietly(HttpURLConnection httpUrlConnection)
      Attempts to cleanly close an HttpURLConnection, swallowing any exceptions that might occur since there's no way to recover anyway.

      It's OK to pass null in, this method will no-op in that case.

      Parameters:
      httpUrlConnection - The connection to close.
    • write

      protected void write(InputStream source, OutputStream destination, int bufferSize) throws IOException
      Writes the contents of the source stream to the destination stream using the given bufferSize.
      Parameters:
      source - The source stream to copy from.
      destination - The destination stream to copy to.
      bufferSize - The size of the buffer to use during the copy operation.
      Throws:
      IOException - If an error occurs when reading from source or writing to destination.
      NullPointerException - If either source or @{code destination} is null.
    • createFormFieldName

      protected String createFormFieldName(BinaryAttachment binaryAttachment)
      Creates the form field name for the binary attachment filename by stripping off the file extension - for example, the filename "test.png" would return "test".
      Parameters:
      binaryAttachment - The binary attachment for which to create the form field name.
      Returns:
      The form field name for the given binary attachment.
    • isAutocloseBinaryAttachmentStream

      returns if the binary attachment stream is closed automatically
      Returns:
      true if the binary stream should be closed automatically, false otherwise
      Since:
      1.7.0
    • setAutocloseBinaryAttachmentStream

      public void setAutocloseBinaryAttachmentStream(boolean autocloseBinaryAttachmentStream)
      define if the binary attachment stream is closed automatically after sending the content to facebook
      Parameters:
      autocloseBinaryAttachmentStream - true if the BinaryAttachment stream should be closed automatically, false otherwise
      Since:
      1.7.0
    • getCurrentHeaders

      access to the current response headers
      Returns:
      the current reponse header map
    • executeDelete

      public WebRequestor.Response executeDelete(String url, String headerAccessToken) throws IOException
      Description copied from interface: WebRequestor
      Given a Facebook API endpoint URL and parameter string, execute a DELETE to the endpoint URL.
      Specified by:
      executeDelete in interface WebRequestor
      Parameters:
      url - The URL to submit the DELETE to.
      headerAccessToken - access token used in the header. May be null, if access token is already part of the query string
      Returns:
      HTTP response data.
      Throws:
      IOException - If an error occurs while performing the DELETE.
    • getDebugHeaderInfo

      Description copied from interface: WebRequestor
      Provides access to the facebook header information. The fields x-fb-rev, x-fb-trace-id and x-fb-debug are checked and returned in a single container of the type DebugHeaderInfo
      Specified by:
      getDebugHeaderInfo in interface WebRequestor
      Returns:
      container with the explained facebook debug header information
    • fillHeaderAndDebugInfo

      protected void fillHeaderAndDebugInfo(HttpURLConnection httpUrlConnection)
    • fetchResponse

      protected WebRequestor.Response fetchResponse(HttpURLConnection httpUrlConnection) throws IOException
      Throws:
      IOException