public class RequestBuilder extends Object
Request
objects.
com.google.gwt.http.HTTP
.
Modifier and Type | Class and Description |
---|---|
static class |
RequestBuilder.Method
HTTP request method constants.
|
Modifier and Type | Field and Description |
---|---|
static RequestBuilder.Method |
DELETE
Specifies that the HTTP DELETE method should be used.
|
static RequestBuilder.Method |
GET
Specifies that the HTTP GET method should be used.
|
static RequestBuilder.Method |
HEAD
Specifies that the HTTP HEAD method should be used.
|
static RequestBuilder.Method |
POST
Specifies that the HTTP POST method should be used.
|
static RequestBuilder.Method |
PUT
Specifies that the HTTP PUT method should be used.
|
Modifier | Constructor and Description |
---|---|
|
RequestBuilder(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.
|
Modifier and Type | Method and Description |
---|---|
RequestCallback |
getCallback()
Returns the callback previously set by
setCallback(RequestCallback) , or null if no callback
was set. |
String |
getHeader(String header)
Returns the value of a header previous set by
setHeader(String, String) , or null if no such header
was set. |
String |
getHTTPMethod()
Returns the HTTP method specified in the constructor.
|
String |
getPassword()
Returns the password previously set by
setPassword(String) , or
null if no password was set. |
String |
getRequestData()
Returns the requestData previously set by
setRequestData(String) ,
or null if no requestData was set. |
int |
getTimeoutMillis()
Returns the timeoutMillis previously set by
setTimeoutMillis(int) ,
or 0 if no timeoutMillis was set. |
String |
getUrl()
Returns the HTTP URL specified in the constructor.
|
String |
getUser()
Returns the user previously set by
setUser(String) , or
null if no user was set. |
Request |
send()
Sends an HTTP request based on the current builder configuration.
|
Request |
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 |
setHeader(String header,
String value)
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 |
setUser(String user)
Sets the user name that will be used in the request URL.
|
public static final RequestBuilder.Method DELETE
public static final RequestBuilder.Method GET
public static final RequestBuilder.Method HEAD
public static final RequestBuilder.Method POST
public static final RequestBuilder.Method PUT
public RequestBuilder(RequestBuilder.Method httpMethod, String url)
httpMethod
- HTTP method to use for the requesturl
- URL that has already has already been encoded. Please see
URL.encode(String)
,
URL.encodePathSegment(String)
and
URL.encodeQueryString(String)
for
how to do this.IllegalArgumentException
- if the httpMethod or URL are emptyNullPointerException
- if the httpMethod or the URL are nullprotected RequestBuilder(String httpMethod, String url)
httpMethod
- HTTP method to use for the requesturl
- URL that has already has already been URL encoded. Please see
URL.encode(String)
and
URL.encodePathSegment(String)
and
URL.encodeQueryString(String)
for
how to do this.IllegalArgumentException
- if the httpMethod or URL are emptyNullPointerException
- if the httpMethod or the URL are nullpublic RequestCallback getCallback()
setCallback(RequestCallback)
, or null
if no callback
was set.public String getHeader(String header)
setHeader(String, String)
, or null
if no such header
was set.header
- the name of the headerpublic String getHTTPMethod()
public String getPassword()
setPassword(String)
, or
null
if no password was set.public String getRequestData()
setRequestData(String)
,
or null
if no requestData was set.public int getTimeoutMillis()
setTimeoutMillis(int)
,
or 0
if no timeoutMillis was set.public String getUrl()
public String getUser()
setUser(String)
, or
null
if no user was set.public Request send() throws RequestException
setRequestData(String)
and setCallback(RequestCallback)
before calling this method.Request
object that can be used to track the requestRequestException
- if the call fails to initiateNullPointerException
- if a request callback has not been setpublic Request sendRequest(String requestData, RequestCallback callback) throws RequestException
requestData
or
callback
.requestData
- the data to send as part of the requestcallback
- the response handler to be notified when the request fails
or completesRequest
object that can be used to track the requestNullPointerException
- if callback
null
RequestException
public void setCallback(RequestCallback callback)
send()
.callback
- the response handler to be notified when the request fails
or completesNullPointerException
- if callback
is null
public void setHeader(String header, String value)
header
- the name of the headervalue
- the value of the headerNullPointerException
- if header or value are nullIllegalArgumentException
- if header or value are the empty stringpublic void setPassword(String password)
password
- password to use in the request URLIllegalArgumentException
- if the password is emptyNullPointerException
- if the password is nullpublic void setRequestData(String requestData)
send()
.requestData
- the data to send as part of the requestpublic void setTimeoutMillis(int timeoutMillis)
RequestCallback.onError(Request, Throwable)
method will be called on the callback instance given to the
sendRequest(String, RequestCallback)
method. The callback method will receive an instance of the
RequestTimeoutException
class as its
Throwable
argument.timeoutMillis
- number of milliseconds to wait before canceling the
request, a value of zero disables timeoutsIllegalArgumentException
- if the timeout value is negativepublic void setUser(String user)
user
- user name to useIllegalArgumentException
- if the user is emptyNullPointerException
- if the user is nullpublic void setIncludeCredentials(boolean includeCredentials)
withCredentials
- whether to include credentials in XHRCopyright © 2018. All rights reserved.