public class ConnectionRequest extends Object implements IOProgressListener
This class represents a connection object in the form of a request response
typically common for HTTP/HTTPS connections. A connection request is added to
the NetworkManager
for processing in a queue on one of the
network threads. You can read more about networking in Codename One here
The sample
code below fetches a page of data from the nestoria housing listing API.
You can see instructions on how to display the data in the InfiniteScrollAdapter
class. You can read more about networking in Codename One here
.
Modifier and Type | Class and Description |
---|---|
static class |
ConnectionRequest.CachingMode
There are 5 caching modes:
|
class |
ConnectionRequest.SSLCertificate
Encapsulates an SSL certificate fingerprint.
|
Modifier and Type | Field and Description |
---|---|
static byte |
PRIORITY_CRITICAL
A critical priority request will "push" through the queue to the highest point
regardless of anything else and ignoring anything that is not in itself of
critical priority.
|
static byte |
PRIORITY_HIGH
A high priority request is the second highest level, it will act exactly like
a critical priority with one difference.
|
static byte |
PRIORITY_LOW
Low priority requests are mostly background tasks that should still be accomplished though
|
static byte |
PRIORITY_NORMAL
Normal priority executes as usual on the queue
|
static byte |
PRIORITY_REDUNDANT
Redundant elements can be discarded from the queue when paused
|
Constructor and Description |
---|
ConnectionRequest()
Default constructor
|
ConnectionRequest(String url)
Construct a connection request to a url
|
ConnectionRequest(String url,
boolean post)
Construct a connection request to a url
|
Modifier and Type | Method and Description |
---|---|
void |
addArgument(String key,
byte[] value)
Deprecated.
use the version that accepts a string instead
|
void |
addArgument(String key,
String value)
Add an argument to the request response
|
void |
addArgument(String key,
String[] value)
Add an argument to the request response as an array of elements, this will
trigger multiple request entries with the same key
|
void |
addArgumentArray(String key,
String... value)
Add an argument to the request response as an array of elements, this will
trigger multiple request entries with the same key
|
void |
addArgumentNoEncoding(String key,
String value)
Add an argument to the request response without encoding it, this is useful for
arguments which are already encoded
|
void |
addArgumentNoEncoding(String key,
String[] value)
Add an argument to the request response as an array of elements, this will
trigger multiple request entries with the same key, notice that this doesn't implicitly
encode the value
|
void |
addArgumentNoEncodingArray(String key,
String... value)
Add an argument to the request response as an array of elements, this will
trigger multiple request entries with the same key, notice that this doesn't implicitly
encode the value
|
void |
addArguments(String key,
String... value)
Add an argument to the request response as an array of elements, this will
trigger multiple request entries with the same key
|
void |
addExceptionListener(ActionListener<NetworkEvent> a)
Adds a listener that would be notified on the CodenameOne thread of an exception
in this connection request
|
void |
addRequestHeader(String key,
String value)
Adds the given header to the request that will be sent
|
void |
addResponseCodeListener(ActionListener<NetworkEvent> a)
Adds a listener that would be notified on the CodenameOne thread of a response code that
is not a 200 (OK) or 301/2 (redirect) response code.
|
void |
addResponseListener(ActionListener<NetworkEvent> a)
Adds a listener that would be notified on the CodenameOne thread of a response from the server.
|
protected void |
buildRequestBody(OutputStream os)
Invoked when send body is true, by default sends the request arguments based
on "POST" conventions
|
protected void |
cacheUnmodified()
This callback is invoked on a 304 server response indicating the data in the server matches the result
we currently have in the cache.
|
boolean |
canGetSSLCertificates()
Checks to see if the platform supports getting SSL certificates.
|
protected void |
checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates)
A callback that can be overridden by subclasses to check the SSL certificates
for the server, and kill the connection if they don't pass muster.
|
protected void |
cookieReceived(Cookie c)
Callback invoked for every cookie received from the server
|
protected void |
cookieSent(Cookie c)
Callback invoked for every cookie being sent to the server
|
protected String |
createRequestURL()
Creates the request URL mostly for a get request
|
AsyncResource<Image> |
downloadImageToFileSystem(String file)
Downloads an image to a the file system asynchronously returning an AsyncResource object that resolves to the loaded image..
|
AsyncResource<Image> |
downloadImageToFileSystem(String file,
boolean useCache)
Downloads an image to a the file system asynchronously returning an AsyncResource object that resolves to the loaded image..
|
void |
downloadImageToFileSystem(String file,
SuccessCallback<Image> onSuccess)
Downloads an image to a the file system asynchronously and calls the onSuccessCallback with the resulting image.
|
void |
downloadImageToFileSystem(String file,
SuccessCallback<Image> onSuccess,
boolean useCache)
Downloads an image to a the file system asynchronously and calls the onSuccessCallback with the resulting image.
|
void |
downloadImageToFileSystem(String file,
SuccessCallback<Image> onSuccess,
FailureCallback<Image> onFail)
Downloads an image to a the file system asynchronously and calls the onSuccessCallback with the resulting image.
|
void |
downloadImageToFileSystem(String file,
SuccessCallback<Image> onSuccess,
FailureCallback<Image> onFail,
boolean useCache)
Downloads an image to a the file system asynchronously and calls the onSuccessCallback with the resulting image.
|
AsyncResource<Image> |
downloadImageToStorage(String storageFile)
Downloads an image to a specified storage file asynchronously returning an AsyncResource that resolves to the resulting image..
|
AsyncResource<Image> |
downloadImageToStorage(String storageFile,
boolean useCache)
Downloads an image to a specified storage file asynchronously returning an AsyncResource that resolves to the resulting image..
|
void |
downloadImageToStorage(String storageFile,
SuccessCallback<Image> onSuccess)
Downloads an image to a specified storage file asynchronously and calls the onSuccessCallback with the resulting image.
|
void |
downloadImageToStorage(String storageFile,
SuccessCallback<Image> onSuccess,
boolean useCache)
Downloads an image to a specified storage file asynchronously and calls the onSuccessCallback with the resulting image.
|
void |
downloadImageToStorage(String storageFile,
SuccessCallback<Image> onSuccess,
FailureCallback<Image> onFail)
Downloads an image to a specified storage file asynchronously and calls the onSuccessCallback with the resulting image.
|
void |
downloadImageToStorage(String storageFile,
SuccessCallback<Image> onSuccess,
FailureCallback<Image> onFail,
boolean useCache)
Downloads an image to a specified storage file asynchronously and calls the onSuccessCallback with the resulting image.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
static Map<String,Object> |
fetchJSON(String url)
Utility method that returns a JSON structure or throws an IOException in case of a failure.
|
static AsyncResource<Map<String,Object>> |
fetchJSONAsync(String url)
Fetches JSON asynchronously.
|
protected void |
fireResponseListener(ActionEvent ev)
Fires the response event to the listeners on this connection
|
protected InputStream |
getCachedData()
This method should be overriden in
CacheMode.MANUAL to provide offline caching. |
ConnectionRequest.CachingMode |
getCacheMode()
There are 5 caching modes:
|
int |
getContentLength()
Returns the content length header value
|
String |
getContentType() |
static String |
getCookieHeader()
Workaround for https://bugs.php.net/bug.php?id=65633 allowing developers to
customize the name of the cookie header to Cookie
|
static ConnectionRequest.CachingMode |
getDefaultCacheMode()
The default value for the cacheMode property see
getCacheMode() |
static String |
getDefaultUserAgent() |
String |
getDestinationFile()
When set to a none null string saves the response to file system under
this file name
|
String |
getDestinationStorage()
When set to a none null string saves the response to storage under
this file name
|
Dialog |
getDisposeOnCompletion()
A dialog that will be seamlessly disposed once the given request has been completed
|
protected String |
getHeader(Object connection,
String header)
Returns the HTTP header field for the given connection, this method is only guaranteed to work
when invoked from the readHeaders method.
|
protected String[] |
getHeaderFieldNames(Object connection)
Returns the HTTP header field names for the given connection, this method is only guaranteed to work
when invoked from the readHeaders method.
|
protected String[] |
getHeaders(Object connection,
String header)
Returns the HTTP header field for the given connection, this method is only guaranteed to work
when invoked from the readHeaders method.
|
String |
getHttpMethod()
Returns the http method
|
byte |
getPriority()
The priority of this connection based on the constants in this class
|
int |
getReadTimeout()
Gets the read timeout for this connection.
|
String |
getRequestBody()
The request body can be used instead of arguments to pass JSON data to a restful request,
it can't be used in a get request and will fail if you have arguments
|
Data |
getRequestBodyData()
The request body can be used instead of arguments to pass JSON data to a restful request,
it can't be used in a get request and will fail if you have arguments
|
int |
getResponseCode()
Returns the response code for this request, this is only relevant after the request completed and
might contain a temporary (e.g.
|
String |
getResponseContentType()
Returns the content type from the response headers
|
byte[] |
getResponseData()
This method will return a valid value for only some of the responses and only after the response was processed
|
String |
getResponseErrorMessage()
Returns error message associated with an error response code
|
int |
getResposeCode()
Deprecated.
misspelled method name please use getResponseCode
|
Dialog |
getShowOnInit()
This dialog will be shown when this request enters the network queue
|
int |
getSilentRetryCount()
Indicates the number of times to silently retry a connection that failed
before prompting
|
ConnectionRequest.SSLCertificate[] |
getSSLCertificates()
Gets the server's SSL certificates for this requests.
|
int |
getTimeout()
Indicates the timeout for this connection request
|
String |
getUrl() |
String |
getUserAgent() |
protected int |
getYield()
Returns the amount of time to yield for other processes, this is an implicit
method that automatically generates values for lower priority connections
|
protected void |
handleErrorResponseCode(int code,
String message)
Handles a server response code that is not 200 and not a redirect (unless redirect handling is disabled)
|
protected void |
handleException(Exception err)
Handles an exception thrown when performing a network operation, the default
implementation shows a retry dialog.
|
protected void |
handleIOException(IOException err)
Handles IOException thrown when performing a network operation
|
protected void |
handleRuntimeException(RuntimeException err)
Handles an exception thrown when performing a network operation
|
int |
hashCode()
Returns a hash code value for the object.
|
protected boolean |
hasResponseListeners()
Returns true if someone is listening to action response events, this is useful
so we can decide whether to bother collecting data for an event in some cases
since building the event object might be memory/CPU intensive.
|
protected void |
initConnection(Object connection)
Invoked to initialize HTTP headers, cookies etc.
|
protected String |
initCookieHeader(String cookie)
Allows subclasses to inject cookies into the request
|
void |
ioStreamUpdate(Object source,
int bytes)
Indicates the number of bytes that were read/written to/from the source stream
|
boolean |
isCheckSSLCertificates() |
boolean |
isCookiesEnabled() |
static boolean |
isCookiesEnabledDefault() |
static boolean |
isDefaultFollowRedirects()
Enables/Disables automatic redirects globally and returns the 302 error code, IMPORTANT
this feature doesn't work on all platforms and currently doesn't work on iOS which always implicitly redirects
|
boolean |
isDuplicateSupported()
Indicates whether this connection request supports duplicate entries in the request queue
|
boolean |
isFailSilently()
Indicates that we are uninterested in error handling
|
boolean |
isFollowRedirects()
Enables/Disables automatic redirects globally and returns the 302 error code, IMPORTANT
this feature doesn't work on all platforms and currently doesn't work on iOS which always implicitly redirects
|
static boolean |
isHandleErrorCodesInGlobalErrorHandler()
When set to true (the default), the global error handler in
NetworkManager should receive errors for response code as well |
boolean |
isInsecure()
Checks if the request is insecure (default false).
|
protected boolean |
isKilled() |
static boolean |
isNativeCookieSharingSupported()
Checks if the platform supports sharing cookies between the native components (e.g.
|
protected boolean |
isPausable()
Return true from this method if this connection can be paused and resumed later on.
|
protected boolean |
isPaused() |
boolean |
isPost()
Returns true for a post operation and false for a get operation
|
boolean |
isReadRequest() |
boolean |
isReadResponseForErrors()
When set to true the read response code will happen even for error codes such as 400 and 500
|
static boolean |
isReadResponseForErrorsDefault()
Determines the default value for
isReadResponseForErrors() |
static boolean |
isReadTimeoutSupported()
Checks if this platform supports read timeouts.
|
boolean |
isRedirecting()
Returns true if this request is been redirected to a different url
|
boolean |
isWriteRequest() |
void |
kill()
Kills this request if possible
|
boolean |
onRedirect(String url)
This is a callback method that been called when there is a redirect.
|
boolean |
pause()
Invoked to pause this opeation, this method will only be invoked if isPausable() returns true
(its false by default).
|
protected void |
postResponse()
A callback method that's invoked on the EDT after the readResponse() method has finished,
this is the place where developers should change their Codename One user interface to
avoid race conditions that might be triggered by modifications within readResponse.
|
void |
purgeCache()
Deletes the cache file if it exists, notice that this will not work for download files
|
static void |
purgeCacheDirectory()
Purges all locally cached files
|
protected void |
readErrorCodeHeaders(Object connection)
Allows reading the headers from the connection by calling the getHeader() method when a response that isn't 200 OK is sent.
|
protected void |
readHeaders(Object connection)
Allows reading the headers from the connection by calling the getHeader() method.
|
protected void |
readResponse(InputStream input)
Callback for the server response with the input stream from the server.
|
void |
removeAllArguments()
Removes all arguments
|
void |
removeArgument(String key)
Removes the given argument from the request
|
void |
removeExceptionListener(ActionListener<NetworkEvent> a)
Removes the given listener
|
void |
removeResponseCodeListener(ActionListener<NetworkEvent> a)
Removes the given listener
|
void |
removeResponseListener(ActionListener<NetworkEvent> a)
Removes the given listener
|
boolean |
resume()
Called when a previously paused operation now has the networking time to resume.
|
void |
retry()
Retry the current operation in case of an exception
|
void |
setCacheMode(ConnectionRequest.CachingMode cacheMode)
There are 5 caching modes:
|
void |
setCheckSSLCertificates(boolean checkSSLCertificates) |
void |
setChunkedStreamingMode(int chunklen)
This method is used to enable streaming of a HTTP request body without
internal buffering, when the content length is not known in advance.
|
void |
setContentType(String contentType) |
static void |
setCookieHeader(String aCookieHeader)
Workaround for https://bugs.php.net/bug.php?id=65633 allowing developers to
customize the name of the cookie header to Cookie
|
void |
setCookiesEnabled(boolean cookiesEnabled) |
static void |
setCookiesEnabledDefault(boolean aCookiesEnabledDefault) |
static void |
setDefaultCacheMode(ConnectionRequest.CachingMode aDefaultCacheMode)
The default value for the cacheMode property see
getCacheMode() |
static void |
setDefaultFollowRedirects(boolean aDefaultFollowRedirects)
Enables/Disables automatic redirects globally and returns the 302 error code, IMPORTANT
this feature doesn't work on all platforms and currently doesn't work on iOS which always implicitly redirects
|
static void |
setDefaultUserAgent(String aDefaultUserAgent) |
void |
setDestinationFile(String destinationFile)
When set to a none null string saves the response to file system under
this file name
|
void |
setDestinationStorage(String destinationStorage)
When set to a none null string saves the response to storage under
this file name
|
void |
setDisposeOnCompletion(Dialog disposeOnCompletion)
A dialog that will be seamlessly disposed once the given request has been completed
|
void |
setDuplicateSupported(boolean duplicateSupported)
Indicates whether this connection request supports duplicate entries in the request queue
|
void |
setFailSilently(boolean failSilently)
Indicates that we are uninterested in error handling
|
void |
setFollowRedirects(boolean followRedirects)
Enables/Disables automatic redirects globally and returns the 302 error code, IMPORTANT
this feature doesn't work on all platforms and currently doesn't work on iOS which always implicitly redirects
|
static void |
setHandleErrorCodesInGlobalErrorHandler(boolean aHandleErrorCodesInGlobalErrorHandler)
When set to true (the default), the global error handler in
NetworkManager should receive errors for response code as well |
void |
setHttpMethod(String httpMethod)
Sets the http method for the request
|
void |
setInsecure(boolean insecure)
Turns off checking to make sure that SSL certificate is valid.
|
protected void |
setKilled(boolean killed) |
protected void |
setPaused(boolean paused) |
void |
setPost(boolean post)
Set to true for a post operation and false for a get operation, this will implicitly
set the method to post/get respectively (which you can change back by setting the method).
|
void |
setPriority(byte priority)
The priority of this connection based on the constants in this class
|
void |
setReadRequest(boolean readRequest) |
void |
setReadResponseForErrors(boolean readResponseForErrors)
When set to true the read response code will happen even for error codes such as 400 and 500
|
static void |
setReadResponseForErrorsDefault(boolean aReadResponseForErrorsDefault)
Determines the default value for
setReadResponseForErrors(boolean) |
void |
setReadTimeout(int timeout)
Sets the read timeout for the connection.
|
void |
setRequestBody(Data data)
The request body can be used instead of arguments to pass JSON data to a restful request,
it can't be used in a get request and will fail if you have arguments.
|
void |
setRequestBody(String requestBody)
The request body can be used instead of arguments to pass JSON data to a restful request,
it can't be used in a get request and will fail if you have arguments.
|
void |
setShowOnInit(Dialog showOnInit)
This dialog will be shown when this request enters the network queue
|
void |
setSilentRetryCount(int silentRetryCount)
Indicates the number of times to silently retry a connection that failed
before prompting
|
void |
setTimeout(int timeout)
Indicates the timeout for this connection request
|
void |
setUrl(String url) |
static void |
setUseNativeCookieStore(boolean b)
Indicates whether the native Cookie stores should be used
|
void |
setUserAgent(String userAgent) |
void |
setWriteRequest(boolean writeRequest) |
protected boolean |
shouldAutoCloseResponse()
Indicates whether the response stream should be closed automatically by
the framework (defaults to true), this might cause an issue if the stream
needs to be passed to a separate thread for reading.
|
protected boolean |
shouldConvertPostToGetOnRedirect()
This mimics the behavior of browsers that convert post operations to get operations when redirecting a
request.
|
protected boolean |
shouldStop()
Returns true if the request is paused or killed, developers should call this
method periodically to test whether they should quit the current IO operation immediately
|
protected boolean |
shouldWriteUTFAsGetBytes()
Returns whether when writing a post body the platform expects something in the form of
string.getBytes("UTF-8") or new OutputStreamWriter(os, "UTF-8").
|
protected void |
validate()
Validates that the request has the required information before being added to the queue
e.g.
|
public static final byte PRIORITY_CRITICAL
public static final byte PRIORITY_HIGH
public static final byte PRIORITY_NORMAL
public static final byte PRIORITY_LOW
public static final byte PRIORITY_REDUNDANT
public ConnectionRequest()
public ConnectionRequest(String url)
url
- the urlpublic ConnectionRequest(String url, boolean post)
url
- the urlpost
- whether the request is a post url or a get URLpublic static ConnectionRequest.CachingMode getDefaultCacheMode()
getCacheMode()
public static void setDefaultCacheMode(ConnectionRequest.CachingMode aDefaultCacheMode)
getCacheMode()
aDefaultCacheMode
- the defaultCacheMode to setpublic static boolean isReadResponseForErrorsDefault()
isReadResponseForErrors()
public static void setReadResponseForErrorsDefault(boolean aReadResponseForErrorsDefault)
setReadResponseForErrors(boolean)
aReadResponseForErrorsDefault
- the readResponseForErrorsDefault to setpublic static boolean isHandleErrorCodesInGlobalErrorHandler()
NetworkManager
should receive errors for response code as wellpublic static void setHandleErrorCodesInGlobalErrorHandler(boolean aHandleErrorCodesInGlobalErrorHandler)
NetworkManager
should receive errors for response code as wellaHandleErrorCodesInGlobalErrorHandler
- the handleErrorCodesInGlobalErrorHandler to setpublic ConnectionRequest.CachingMode getCacheMode()
There are 5 caching modes:
OFF
is the default, meaning no caching.
SMART
means all get requests are cached intelligently and caching is "mostly" seamless.
MANUAL
means that the developer is responsible for the actual caching but the system will not do a
request on a resource that's already "fresh".
OFFLINE
will fetch data from the cache and wont try to go to the server. It will generate a 404 error
if data isn't available.
OFFLINE_FIRST
works the same way as offline but if data isn't available locally it will try to
connect to the server.
public void setCacheMode(ConnectionRequest.CachingMode cacheMode)
There are 5 caching modes:
OFF
is the default, meaning no caching.
SMART
means all get requests are cached intelligently and caching is "mostly" seamless.
MANUAL
means that the developer is responsible for the actual caching but the system will not do a
request on a resource that's already "fresh".
OFFLINE
will fetch data from the cache and wont try to go to the server. It will generate a 404 error
if data isn't available.
OFFLINE_FIRST
works the same way as offline but if data isn't available locally it will try to
connect to the server.
cacheMode
- the cacheMode to setpublic boolean isCheckSSLCertificates()
public void setCheckSSLCertificates(boolean checkSSLCertificates)
checkSSLCertificates
- the checkSSLCertificates to setpublic static String getCookieHeader()
public static void setCookieHeader(String aCookieHeader)
aCookieHeader
- the cookieHeader to setpublic static boolean isCookiesEnabledDefault()
public static void setCookiesEnabledDefault(boolean aCookiesEnabledDefault)
aCookiesEnabledDefault
- the cookiesEnabledDefault to setpublic static boolean isDefaultFollowRedirects()
public static void setDefaultFollowRedirects(boolean aDefaultFollowRedirects)
aDefaultFollowRedirects
- the defaultFollowRedirects to setpublic void setInsecure(boolean insecure)
insecure
- public boolean isInsecure()
public byte[] getResponseData()
public void setHttpMethod(String httpMethod)
httpMethod
- the http method stringpublic String getHttpMethod()
public void addRequestHeader(String key, String value)
key
- the header keyvalue
- the header valueprotected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates)
NOTE: This method will only be called if isCheckSSLCertificates()
is true and the platform supports SSL certificates (canGetSSLCertificates()
.
WARNING: On iOS it is possible that certificates for a request would not be available even through the platform supports it, and checking certificates are enabled. This could happen if the certificates had been cached by the TLS cache by some network mechanism other than ConnectionRequest (e.g. native code, websockets, etc..). In such cases this method would receive an empty array as a parameter.
This is called after the SSL handshake, but before any data has been sent.
certificates
- The server's SSL certificates.setCheckSSLCertificates(boolean)
,
isCheckSSLCertificates()
public void setReadTimeout(int timeout)
isReadTimeoutSupported()
is true on this platform. Currently Android, Mac Desktop, Windows Desktop, and Simulator supports read timeouts.timeout
- The read timeout. If less than or equal to zero, then there is no timeout.isReadTimeoutSupported()
public int getReadTimeout()
isReadTimeoutSupported()
is true on this platform. Currently Android, Mac Desktop, Windows Desktop, and Simulator supports read timeouts.public static boolean isReadTimeoutSupported()
protected void initConnection(Object connection)
connection
- the connection objectprotected InputStream getCachedData() throws IOException
CacheMode.MANUAL
to provide offline caching. The default
implementation will work as expected in the CacheMode.SMART
and CacheMode.OFFLINE_FIRST
modes.IOException
public void purgeCache()
protected void cacheUnmodified() throws IOException
IOException
public static void purgeCacheDirectory() throws IOException
IOException
protected void cookieReceived(Cookie c)
c
- the cookieprotected void cookieSent(Cookie c)
c
- the cookieprotected String initCookieHeader(String cookie)
cookie
- the cookie that the implementation is about to send or null for no cookiepublic int getResponseCode()
public int getResposeCode()
protected boolean shouldConvertPostToGetOnRedirect()
protected void readHeaders(Object connection) throws IOException
connection
- used when invoking getHeaderIOException
- thrown on failureprotected void readErrorCodeHeaders(Object connection) throws IOException
connection
- used when invoking getHeaderIOException
- thrown on failureprotected String getHeader(Object connection, String header) throws IOException
connection
- the connection to the networkheader
- the name of the headerIOException
- thrown on failureprotected String[] getHeaders(Object connection, String header) throws IOException
connection
- the connection to the networkheader
- the name of the headerIOException
- thrown on failureprotected String[] getHeaderFieldNames(Object connection) throws IOException
connection
- the connection to the networkIOException
- thrown on failureprotected int getYield()
protected boolean shouldAutoCloseResponse()
protected void handleIOException(IOException err)
err
- the exception thrownprotected void handleRuntimeException(RuntimeException err)
err
- the exception thrownprotected void handleException(Exception err)
err
- the exception thrownpublic boolean canGetSSLCertificates()
public ConnectionRequest.SSLCertificate[] getSSLCertificates() throws IOException
IOException
protected void handleErrorResponseCode(int code, String message)
code
- the response code from the servermessage
- the response message from the serverpublic void retry()
public boolean onRedirect(String url)
url
- the url to be redirectedprotected void readResponse(InputStream input) throws IOException
input
- the input stream containing the responseIOException
- when a read input occursprotected void postResponse()
protected String createRequestURL()
protected void buildRequestBody(OutputStream os) throws IOException
os
- output stream of the bodyIOException
protected boolean shouldWriteUTFAsGetBytes()
public void kill()
protected boolean shouldStop()
protected boolean isPausable()
public boolean pause()
public boolean resume()
public boolean isPost()
public void setPost(boolean post)
IllegalStateException
- if invoked after an addArgument callpublic void addArgument(String key, byte[] value)
key
- the key of the argumentvalue
- the value for the argumentpublic void removeArgument(String key)
key
- the key of the argument no longer usedpublic void removeAllArguments()
public void addArgumentNoEncoding(String key, String value)
key
- the key of the argumentvalue
- the value for the argumentpublic void addArgumentNoEncoding(String key, String[] value)
key
- the key of the argumentvalue
- the value for the argumentpublic void addArgumentNoEncodingArray(String key, String... value)
key
- the key of the argumentvalue
- the value for the argumentpublic void addArgument(String key, String value)
key
- the key of the argumentvalue
- the value for the argumentpublic void addArgumentArray(String key, String... value)
key
- the key of the argumentvalue
- the value for the argumentpublic void addArgument(String key, String[] value)
key
- the key of the argumentvalue
- the value for the argumentpublic void addArguments(String key, String... value)
key
- the key of the argumentvalue
- the value for the argumentpublic String getContentType()
public void setContentType(String contentType)
contentType
- the contentType to setpublic boolean isWriteRequest()
public void setWriteRequest(boolean writeRequest)
writeRequest
- the writeRequest to setpublic boolean isReadRequest()
public void setReadRequest(boolean readRequest)
readRequest
- the readRequest to setprotected boolean isPaused()
protected void setPaused(boolean paused)
paused
- the paused to setprotected boolean isKilled()
protected void setKilled(boolean killed)
killed
- the killed to setpublic byte getPriority()
public void setPriority(byte priority)
priority
- the priority to setpublic String getUserAgent()
public void setUserAgent(String userAgent)
userAgent
- the userAgent to setpublic static String getDefaultUserAgent()
public static void setDefaultUserAgent(String aDefaultUserAgent)
aDefaultUserAgent
- the defaultUserAgent to setpublic boolean isFollowRedirects()
public void setFollowRedirects(boolean followRedirects)
followRedirects
- the followRedirects to setpublic int getTimeout()
public void setTimeout(int timeout)
timeout
- the timeout to setpublic int getContentLength()
public void ioStreamUpdate(Object source, int bytes)
ioStreamUpdate
in interface IOProgressListener
source
- the source stream which can be either an input stream or an output streambytes
- the number of bytes read or writtenpublic String getUrl()
public void setUrl(String url)
url
- the url to setpublic void addResponseListener(ActionListener<NetworkEvent> a)
a
- listenerpublic void removeResponseListener(ActionListener<NetworkEvent> a)
a
- listenerpublic void addResponseCodeListener(ActionListener<NetworkEvent> a)
a
- listenerpublic void addExceptionListener(ActionListener<NetworkEvent> a)
a
- listenerpublic void removeResponseCodeListener(ActionListener<NetworkEvent> a)
a
- listenerpublic void removeExceptionListener(ActionListener<NetworkEvent> a)
a
- listenerprotected boolean hasResponseListeners()
protected void fireResponseListener(ActionEvent ev)
ev
- the event to firepublic boolean isDuplicateSupported()
public void setDuplicateSupported(boolean duplicateSupported)
duplicateSupported
- the duplicateSupported to setpublic int hashCode()
public boolean equals(Object o)
protected void validate()
public Dialog getDisposeOnCompletion()
public void setDisposeOnCompletion(Dialog disposeOnCompletion)
disposeOnCompletion
- the disposeOnCompletion to setpublic Dialog getShowOnInit()
public void setShowOnInit(Dialog showOnInit)
showOnInit
- the showOnInit to setpublic int getSilentRetryCount()
public void setSilentRetryCount(int silentRetryCount)
silentRetryCount
- the silentRetryCount to setpublic boolean isFailSilently()
public void setFailSilently(boolean failSilently)
failSilently
- the failSilently to setpublic static void setUseNativeCookieStore(boolean b)
NOTE: If the platform doesn't support Native Cookie sharing, then this method will
have no effect. Use isNativeCookieSharingSupported()
} to check if the platform
supports native cookie sharing at runtime.
b
- true to enable native cookie stores when applicablepublic static boolean isNativeCookieSharingSupported()
If the platform does not support native cookie sharing, then methods like setUseNativeCookieStore(boolean)
will
have no effect.
public boolean isReadResponseForErrors()
public void setReadResponseForErrors(boolean readResponseForErrors)
readResponseForErrors
- the readResponseForErrors to setpublic String getResponseContentType()
public boolean isRedirecting()
public String getDestinationFile()
public void setDestinationFile(String destinationFile)
destinationFile
- the destinationFile to setpublic String getDestinationStorage()
public void setDestinationStorage(String destinationStorage)
destinationStorage
- the destinationStorage to setpublic boolean isCookiesEnabled()
public void setCookiesEnabled(boolean cookiesEnabled)
cookiesEnabled
- the cookiesEnabled to setpublic void setChunkedStreamingMode(int chunklen)
chunklen
- The number of bytes to write in each chunk. If chunklen
is zero a default value will be used.public static Map<String,Object> fetchJSON(String url) throws IOException
url
- the URL hosing the JSONIOException
- in case of an errorpublic static AsyncResource<Map<String,Object>> fetchJSONAsync(String url)
url
- The URL to fetch.public void downloadImageToStorage(String storageFile, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail, boolean useCache)
storageFile
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.onFail
- Callback called if we fail to load the image.useCache
- If true, then this will first check the storage to see if the image is already downloaded.public AsyncResource<Image> downloadImageToStorage(String storageFile)
storageFile
- The storage file where the file should be saved.public AsyncResource<Image> downloadImageToStorage(String storageFile, boolean useCache)
storageFile
- The storage file where the file should be saved.useCache
- If true, then this will first check the storage to see if the image is already downloaded.public void downloadImageToStorage(String storageFile, SuccessCallback<Image> onSuccess, boolean useCache)
storageFile
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.useCache
- If true, then this will first check the storage to see if the image is already downloaded.public void downloadImageToStorage(String storageFile, SuccessCallback<Image> onSuccess)
storageFile
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.public void downloadImageToStorage(String storageFile, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail)
storageFile
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.public AsyncResource<Image> downloadImageToFileSystem(String file, boolean useCache)
file
- The storage file where the file should be saved.useCache
- If true, then this will first check the storage to see if the image is already downloaded.public AsyncResource<Image> downloadImageToFileSystem(String file)
downloadImageToFileSystem(java.lang.String, boolean)
with true as the 2nd parameter.file
- The storage file where the file should be saved.public void downloadImageToFileSystem(String file, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail, boolean useCache)
file
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.onFail
- Callback called if we fail to load the image.useCache
- If true, then this will first check the storage to see if the image is already downloaded.public void downloadImageToFileSystem(String file, SuccessCallback<Image> onSuccess, boolean useCache)
file
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.useCache
- If true, then this will first check the storage to see if the image is already downloaded.public void downloadImageToFileSystem(String file, SuccessCallback<Image> onSuccess)
file
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.public void downloadImageToFileSystem(String file, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail)
file
- The storage file where the file should be saved.onSuccess
- Callback called if the image is successfully loaded.onFail
- Callback called if the image fails to load.public String getRequestBody()
public Data getRequestBodyData()
public void setRequestBody(String requestBody)
The request body can be used instead of arguments to pass JSON data to a restful request, it can't be used in a get request and will fail if you have arguments.
Notice that invoking this method blocks the buildRequestBody(java.io.OutputStream)
method
callback.
requestBody
- a string to pass in the post bodypublic void setRequestBody(Data data)
The request body can be used instead of arguments to pass JSON data to a restful request, it can't be used in a get request and will fail if you have arguments.
Notice that invoking this method blocks the buildRequestBody(java.io.OutputStream)
method
callback.
data
- a data to pass in the post bodypublic String getResponseErrorMessage()