Package com.google.gwt.http.client
Class RequestBuilder
java.lang.Object
com.google.gwt.http.client.RequestBuilder
Builder for constructing
Request
objects.
Required Module
Modules that use this class should inheritcom.google.gwt.http.HTTP
.
<module> <!-- other inherited modules, such as com.google.gwt.user.User --> <inherits name="com.google.gwt.http.HTTP"/> <!-- additional module settings --> </module>
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
HTTP request method constants. -
Field Summary
Modifier and TypeFieldDescriptionstatic final RequestBuilder.Method
Specifies that the HTTP DELETE method should be used.static final RequestBuilder.Method
Specifies that the HTTP GET method should be used.static final RequestBuilder.Method
Specifies that the HTTP HEAD method should be used.static final RequestBuilder.Method
Specifies that the HTTP POST method should be used.static final RequestBuilder.Method
Specifies that the HTTP PUT method should be used. -
Constructor Summary
ModifierConstructorDescriptionRequestBuilder
(RequestBuilder.Method httpMethod, String url) Creates a builder using the parameters for configuration.protected
RequestBuilder
(String httpMethod, String url) Creates a builder using the parameters values for configuration. -
Method Summary
Modifier and TypeMethodDescriptionReturns the callback previously set bysetCallback(RequestCallback)
, ornull
if no callback was set.Returns the value of a header previous set bysetHeader(String, String)
, ornull
if no such header was set.Returns the HTTP method specified in the constructor.Returns the password previously set bysetPassword(String)
, ornull
if no password was set.Returns the requestData previously set bysetRequestData(String)
, ornull
if no requestData was set.int
Returns the timeoutMillis previously set bysetTimeoutMillis(int)
, or0
if no timeoutMillis was set.getUrl()
Returns the HTTP URL specified in the constructor.getUser()
Returns the user previously set bysetUser(String)
, ornull
if no user was set.send()
Sends an HTTP request based on the current builder configuration.sendRequest
(String requestData, RequestCallback callback) Sends an HTTP request based on the current builder configuration with the specified data and callback.void
setCallback
(RequestCallback callback) Sets the response handler for this request.void
Sets a request header with the given name and value.void
setIncludeCredentials
(boolean includeCredentials) Sets whether the cross origin request will include credentials.void
setPassword
(String password) Sets the password to use in the request URL.void
setRequestData
(String requestData) Sets the data to send as part of this request.void
setTimeoutMillis
(int timeoutMillis) Sets the number of milliseconds to wait for a request to complete.void
Sets the user name that will be used in the request URL.
-
Field Details
-
DELETE
Specifies that the HTTP DELETE method should be used. -
GET
Specifies that the HTTP GET method should be used. -
HEAD
Specifies that the HTTP HEAD method should be used. -
POST
Specifies that the HTTP POST method should be used. -
PUT
Specifies that the HTTP PUT method should be used.
-
-
Constructor Details
-
RequestBuilder
Creates a builder using the parameters for configuration.- Parameters:
httpMethod
- HTTP method to use for the requesturl
- URL that has already has already been encoded. Please seeURL.encode(String)
,URL.encodePathSegment(String)
andURL.encodeQueryString(String)
for how to do this.- Throws:
IllegalArgumentException
- if the httpMethod or URL are emptyNullPointerException
- if the httpMethod or the URL are null
-
RequestBuilder
Creates a builder using the parameters values for configuration.- Parameters:
httpMethod
- HTTP method to use for the requesturl
- URL that has already has already been URL encoded. Please seeURL.encode(String)
andURL.encodePathSegment(String)
andURL.encodeQueryString(String)
for how to do this.- Throws:
IllegalArgumentException
- if the httpMethod or URL are emptyNullPointerException
- if the httpMethod or the URL are null
-
-
Method Details
-
getCallback
Returns the callback previously set bysetCallback(RequestCallback)
, ornull
if no callback was set. -
getHeader
Returns the value of a header previous set bysetHeader(String, String)
, ornull
if no such header was set.- Parameters:
header
- the name of the header
-
getHTTPMethod
Returns the HTTP method specified in the constructor. -
getPassword
Returns the password previously set bysetPassword(String)
, ornull
if no password was set. -
getRequestData
Returns the requestData previously set bysetRequestData(String)
, ornull
if no requestData was set. -
getTimeoutMillis
public int getTimeoutMillis()Returns the timeoutMillis previously set bysetTimeoutMillis(int)
, or0
if no timeoutMillis was set. -
getUrl
Returns the HTTP URL specified in the constructor. -
getUser
Returns the user previously set bysetUser(String)
, ornull
if no user was set. -
send
Sends an HTTP request based on the current builder configuration. If no request headers have been set, the header "Content-Type" will be used with a value of "text/plain; charset=utf-8". You must callsetRequestData(String)
andsetCallback(RequestCallback)
before calling this method.- Returns:
- a
Request
object that can be used to track the request - Throws:
RequestException
- if the call fails to initiateNullPointerException
- if a request callback has not been set
-
sendRequest
Sends an HTTP request based on the current builder configuration with the specified data and callback. If no request headers have been set, the header "Content-Type" will be used with a value of "text/plain; charset=utf-8". This method does not cacherequestData
orcallback
.- Parameters:
requestData
- the data to send as part of the requestcallback
- the response handler to be notified when the request fails or completes- Returns:
- a
Request
object that can be used to track the request - Throws:
NullPointerException
- ifcallback
null
RequestException
-
setCallback
Sets the response handler for this request. This method must be called before callingsend()
.- Parameters:
callback
- the response handler to be notified when the request fails or completes- Throws:
NullPointerException
- ifcallback
isnull
-
setHeader
Sets a request header with the given name and value. If a header with the specified name has already been set then the new value overwrites the current value.- Parameters:
header
- the name of the headervalue
- the value of the header- Throws:
NullPointerException
- if header or value are nullIllegalArgumentException
- if header or value are the empty string
-
setPassword
Sets the password to use in the request URL. This is ignored if there is no user specified.- Parameters:
password
- password to use in the request URL- Throws:
IllegalArgumentException
- if the password is emptyNullPointerException
- if the password is null
-
setRequestData
Sets the data to send as part of this request. This method must be called before callingsend()
.- Parameters:
requestData
- the data to send as part of the request
-
setTimeoutMillis
public void setTimeoutMillis(int timeoutMillis) Sets the number of milliseconds to wait for a request to complete. Should the request timeout, theRequestCallback.onError(Request, Throwable)
method will be called on the callback instance given to thesendRequest(String, RequestCallback)
method. The callback method will receive an instance of theRequestTimeoutException
class as itsThrowable
argument.- Parameters:
timeoutMillis
- number of milliseconds to wait before canceling the request, a value of zero disables timeouts- Throws:
IllegalArgumentException
- if the timeout value is negative
-
setUser
Sets the user name that will be used in the request URL.- Parameters:
user
- user name to use- Throws:
IllegalArgumentException
- if the user is emptyNullPointerException
- if the user is null
-
setIncludeCredentials
public void setIncludeCredentials(boolean includeCredentials) Sets whether the cross origin request will include credentials.- Parameters:
withCredentials
- whether to include credentials in XHR
-