From 00dfdfbc498d07d15e5abf2337daaca7a1b43ce9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Mon, 4 Mar 2013 14:35:20 +0100 Subject: [PATCH] We dont need to deal with XMLHttpRequest right now, it is ok to continue using RequestBuilder --- .../gwt/query/client/plugins/ajax/Ajax.java | 114 ------------------ 1 file changed, 114 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index 08f7a1a3..390dc378 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -176,120 +176,6 @@ public class Ajax extends GQuery { return dfd.promise(); } - - public static Promise ajaxNew(Settings settings) { - - final Deferred dfd = $().as(Deferred.Deferred); - - final Function onSuccess = settings.getSuccess(); - if (onSuccess != null) { - onSuccess.setElement(settings.getContext()); - dfd.promise().done(onSuccess); - } - - final Function onError = settings.getError(); - if (onError != null) { - onError.setElement(settings.getContext()); - dfd.promise().fail(onError); - } - - Method httpMethod = resolveHttpMethod(settings); - String data = resolveData(settings, httpMethod); - final String url = resolveUrl(settings, httpMethod, data); - final String dataType = settings.getDataType(); - - if ("jsonp".equalsIgnoreCase(dataType)) { - int timeout = settings.getTimeout(); - return getJSONP(url, onSuccess, onError, timeout); - } - - RequestCallback mdb = new RequestCallback() { - public void onError(Request request, Throwable exception) { - if (onError != null) { - dfd.reject(null, exception.getMessage(), request, null, exception); - } - } - - public void onResponseReceived(Request request, Response response) { - int statusCode = response.getStatusCode(); - if (statusCode <= 0 || statusCode >= 400) { - if (statusCode == 0) { - // Just warn the developer about the status code - GWT.log("GQuery.ajax error, the response.statusCode is 0, this usually happens when you try to access an external server without CORS enabled. url=" + url); - } - dfd.reject(response.getText(), "error", request, response); - } else if (onSuccess != null) { - Object retData = null; - try { - if ("xml".equalsIgnoreCase(dataType)) { - retData = JsUtils.parseXML(response.getText()); - } else if ("json".equalsIgnoreCase(dataType)) { - retData = JsUtils.parseJSON(response.getText()); - } else { - retData = response.getText(); - } - } catch (Exception e) { - if (GWT.getUncaughtExceptionHandler() != null) { - GWT.getUncaughtExceptionHandler().onUncaughtException(e); - } - } - dfd.resolve(retData, "success", request, response); - } - } - }; - - XMLHttpRequest xmlHttpRequest = createXHR(settings, httpMethod.toString(), url, dataType, mdb); - - try { - xmlHttpRequest.send(data); - } catch (JavaScriptException e) { - dfd.reject(null, e.getMessage(), null, null, e); - } - - return dfd.promise(); - } - - // Accessing protected constructor at XMLHttpRequest - private static native Request createRequest(XMLHttpRequest r, int t, RequestCallback c) /*-{ - return @com.google.gwt.http.client.Request::new(Lcom/google/gwt/xhr/client/XMLHttpRequest;ILcom/google/gwt/http/client/RequestCallback;)(r, t, c); - }-*/; - - // Accessing protected method at XMLHttpRequest - private static native void fireOnResponseReceived(Request q, RequestCallback c) /*-{ - q.@com.google.gwt.http.client.Request::fireOnResponseReceived(*)(c); - }-*/; - - private static XMLHttpRequest createXHR (Settings settings, String httpMethod, String url, String data, final RequestCallback cb) { - XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create(); - - if (settings.getUsername() != null && settings.getPassword() != null) { - xmlHttpRequest.open(httpMethod.toString(), url, settings.getUsername(), settings.getPassword()); - } else if (settings.getUsername() != null) { - xmlHttpRequest.open(httpMethod, url, settings.getUsername()); - } else { - xmlHttpRequest.open(httpMethod, url); - } - - Properties headers = settings.getHeaders(); - if (headers != null) { - for (String headerKey : headers.keys()) { - xmlHttpRequest.setRequestHeader(headerKey, headers.getStr(headerKey)); - } - } - - final Request request = createRequest(xmlHttpRequest, settings.getTimeout(), cb); - xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() { - public void onReadyStateChange(XMLHttpRequest xhr) { - if (xhr.getReadyState() == XMLHttpRequest.DONE) { - xhr.clearOnReadyStateChange(); - fireOnResponseReceived(request, cb); - } - } - }); - - return xmlHttpRequest; - } - private static RequestBuilder createRequestBuilder(Settings settings, Method httpMethod, String url, String data) { RequestBuilder requestBuilder = new RequestBuilder(httpMethod, url); -- 2.39.5