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 -
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 voidcloseQuietly(HttpURLConnection httpUrlConnection) Attempts to cleanly close anHttpURLConnection, swallowing any exceptions that might occur since there's no way to recover anyway.protected StringcreateFormFieldName(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".protected voidcustomizeConnection(HttpURLConnection connection) Hook method which allows subclasses to easily customize theconnections created byexecuteGet(com.restfb.WebRequestor.Request)andexecutePost(com.restfb.WebRequestor.Request)- for example, setting a custom read timeout or request header.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 WebRequestor.ResponsefetchResponse(HttpURLConnection httpUrlConnection) protected voidfillHeaderAndDebugInfo(HttpURLConnection httpUrlConnection) access to the current response headersProvides access to the facebook header information.protected voidinitHeaderAccessToken(HttpURLConnection httpUrlConnection, WebRequestor.Request request) booleanreturns if the binary attachment stream is closed automaticallyprotected HttpURLConnectionopenConnection(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.
-
Constructor Details
-
DefaultWebRequestor
public DefaultWebRequestor()
-
-
Method Details
-
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(HttpURLConnection httpUrlConnection, 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
-
customizeConnection
Hook method which allows subclasses to easily customize theconnections created byexecuteGet(com.restfb.WebRequestor.Request)andexecutePost(com.restfb.WebRequestor.Request)- for example, setting a custom read timeout or request header.This implementation is a no-op.
- Parameters:
connection- The connection to customize.
-
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.
-
closeQuietly
Attempts to cleanly close anHttpURLConnection, 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:
httpUrlConnection- The connection 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.
-
createFormFieldName
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:
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
-
getCurrentHeaders
access to the current response headers- Returns:
- the current reponse header map
-
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.
-
getDebugHeaderInfo
Description copied from interface:WebRequestorProvides access to the facebook header information.The fields
x-fb-rev,x-fb-trace-idandx-fb-debugare checked and returned in a single container of the typeDebugHeaderInfo- Specified by:
getDebugHeaderInfoin interfaceWebRequestor- Returns:
- container with the explained facebook debug header information
-
fillHeaderAndDebugInfo
-
fetchResponse
protected WebRequestor.Response fetchResponse(HttpURLConnection httpUrlConnection) throws IOException - Throws:
IOException
-