Package com.restfb
Class DefaultWebRequestor
java.lang.Object
com.restfb.DefaultWebRequestor
- All Implemented Interfaces:
WebRequestor
- Direct Known Subclasses:
ETagWebRequestor
Default implementation of a service that sends HTTP requests to the Facebook API endpoint.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.restfb.WebRequestor
WebRequestor.Request, WebRequestor.Response -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcloseQuietly(Closeable closeable) Attempts to cleanly close a resource, swallowing any exceptions that might occur since there's no way to recover anyway.protected java.net.http.HttpClient.BuilderFactory for the HTTP client builder used by this requestor.protected WebRequestor.ResponsecreateResponse(java.net.http.HttpResponse<InputStream> httpResponse, Map<String, List<String>> headers) protected voidcustomizeRequest(java.net.http.HttpRequest.Builder builder, WebRequestor.Request request, DefaultWebRequestor.HttpMethod httpMethod) Hook method that lets subclasses tweak theHttpRequest.Builderbefore the request is sent.executeDelete(WebRequestor.Request request) Given a Facebook API endpoint URL and parameter string, execute aDELETEto the endpoint URL.executeGet(WebRequestor.Request request) Given a Facebook API endpoint URL, execute aGETagainst it.executePost(WebRequestor.Request request) Given a Facebook API endpoint URL and parameter string, execute aPOSTto the endpoint URL.protected java.net.http.HttpClientprotected voidinitHeaderAccessToken(java.net.http.HttpRequest.Builder builder, WebRequestor.Request request) booleanreturns if the binary attachment stream is closed automaticallyprotected java.net.http.HttpRequest.BuilderopenConnection(URL url) Given aurl, opens and returns a connection to it.voidsetAutocloseBinaryAttachmentStream(boolean autocloseBinaryAttachmentStream) define if the binary attachment stream is closed automatically after sending the content to facebookprotected voidwrite(InputStream source, OutputStream destination, int bufferSize) Writes the contents of thesourcestream to thedestinationstream using the givenbufferSize.
-
Field Details
-
HEADER_CONTENT_TYPE
- See Also:
-
-
Constructor Details
-
DefaultWebRequestor
public DefaultWebRequestor() -
DefaultWebRequestor
-
-
Method Details
-
getHttpClient
-
executeGet
Description copied from interface:WebRequestorGiven a Facebook API endpoint URL, execute aGETagainst it.- Specified by:
executeGetin interfaceWebRequestor- Parameters:
request- The request data for theGETrequest- Returns:
- HTTP response data.
- Throws:
IOException- If an error occurs while performing theGEToperation.
-
executePost
Description copied from interface:WebRequestorGiven a Facebook API endpoint URL and parameter string, execute aPOSTto the endpoint URL.- Specified by:
executePostin interfaceWebRequestor- Parameters:
request- The request data used for thePOSTrequest.- Returns:
- HTTP response data.
- Throws:
IOException- If an error occurs while performing thePOST.
-
initHeaderAccessToken
protected void initHeaderAccessToken(java.net.http.HttpRequest.Builder builder, WebRequestor.Request request) -
openConnection
Given aurl, 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
-
createHttpClientBuilder
Factory for the HTTP client builder used by this requestor.- Returns:
- pre-configured
HttpClient.Builder
-
customizeRequest
protected void customizeRequest(java.net.http.HttpRequest.Builder builder, WebRequestor.Request request, DefaultWebRequestor.HttpMethod httpMethod) Hook method that lets subclasses tweak theHttpRequest.Builderbefore the request is sent.Typical customizations include adding extra headers or adjusting timeouts per request type. This implementation is a no-op.
- Parameters:
builder- the builder for the outbound requestrequest- the logical RestFB request that triggered this HTTP callhttpMethod- the HTTP method used for the call
-
closeQuietly
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
nullin, this method will no-op in that case.- Parameters:
closeable- The resource to close.
-
write
protected void write(InputStream source, OutputStream destination, int bufferSize) throws IOException Writes the contents of thesourcestream to thedestinationstream using the givenbufferSize.- 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 fromsourceor writing todestination.NullPointerException- If eithersourceor @{code destination} isnull.
-
isAutocloseBinaryAttachmentStream
returns if the binary attachment stream is closed automatically- Returns:
trueif the binary stream should be closed automatically,falseotherwise- Since:
- 1.7.0
-
setAutocloseBinaryAttachmentStream
define if the binary attachment stream is closed automatically after sending the content to facebook- Parameters:
autocloseBinaryAttachmentStream-trueif theBinaryAttachmentstream should be closed automatically,falseotherwise- Since:
- 1.7.0
-
executeDelete
Description copied from interface:WebRequestorGiven a Facebook API endpoint URL and parameter string, execute aDELETEto the endpoint URL.- Specified by:
executeDeletein interfaceWebRequestor- Parameters:
request- The request data used for theDELETErequest.- Returns:
- HTTP response data.
- Throws:
IOException- If an error occurs while performing theDELETE.
-
createResponse
protected WebRequestor.Response createResponse(java.net.http.HttpResponse<InputStream> httpResponse, Map<String, List<String>> headers) throws IOException- Throws:
IOException
-