* @throws NullPointerException if request data has not been set
* @throws NullPointerException if a request callback has not been set
*/
private Request doSend(String requestData, final RequestCallback callback)
throws RequestException {
XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create();
try {
if (user != null && password != null) {
xmlHttpRequest.open(httpMethod, url, user, password);
} else if (user != null) {
xmlHttpRequest.open(httpMethod, url, user);
} else {
xmlHttpRequest.open(httpMethod, url);
}
} catch (JavaScriptException e) {
RequestPermissionException requestPermissionException = new RequestPermissionException(
url);
requestPermissionException.initCause(new RequestException(e.getMessage()));
throw requestPermissionException;
}
setHeaders(xmlHttpRequest);
final Request request = new Request(xmlHttpRequest, timeoutMillis, callback);
// Must set the onreadystatechange handler before calling send().
xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() {
public void onReadyStateChange(XMLHttpRequest xhr) {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
xhr.clearOnReadyStateChange();
request.fireOnResponseReceived(callback);
}
}
});
try {
xmlHttpRequest.send(requestData);
} catch (JavaScriptException e) {
throw new RequestException(e.getMessage());
}
return request;