From 979d0a2768d089cde853429a7becd36244bacefe Mon Sep 17 00:00:00 2001 From: Manuel Carrasco Moñino Date: Fri, 7 Feb 2014 21:18:25 +0100 Subject: Dont define ajaxtransport static, so as we can override it in JVM tests --- .../main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java | 8 +++----- 1 file changed, 3 insertions(+), 5 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 7b472ba5..e11e5923 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 @@ -44,8 +44,6 @@ public class Ajax extends GQuery { Promise getXhr(Settings settings); } - static AjaxTransport transport = GQ.getAjaxTransport(); - /** * Ajax Settings object */ @@ -137,11 +135,11 @@ public class Ajax extends GQuery { Promise ret = null; if ("jsonp".equalsIgnoreCase(dataType)) { - ret = transport.getJsonP(settings); + ret = GQ.getAjaxTransport().getJsonP(settings); } else if ("loadscript".equalsIgnoreCase(dataType)){ - ret = transport.getLoadScript(settings); + ret = GQ.getAjaxTransport().getLoadScript(settings); } else { - ret = transport.getXhr(settings) + ret = GQ.getAjaxTransport().getXhr(settings) .then(new Function() { public Object f(Object...args) { Response response = arguments(0); -- cgit v1.2.3 From e081f61c8c5340bbc1b2050e1d9b84a08d116bb6 Mon Sep 17 00:00:00 2001 From: Manuel Carrasco Moñino Date: Sat, 8 Feb 2014 11:26:29 +0100 Subject: Fix filenotfound exception when the response is an error --- .../com/google/gwt/query/vm/AjaxTransportJre.java | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java index d6f2fcdb..4ac9ed1a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java @@ -4,6 +4,7 @@ package com.google.gwt.query.vm; import java.io.BufferedReader; import java.io.DataOutputStream; +import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -177,19 +178,25 @@ public class AjaxTransportJre implements AjaxTransport { } } - BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream())); - String inputLine; - StringBuffer response = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - response.append(inputLine + "\n"); + String payload = ""; + + InputStream is = code >= 400 ? c.getErrorStream() : c.getInputStream(); + if (is != null) { + BufferedReader in = new BufferedReader(new InputStreamReader(is)); + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine + "\n"); + } + in.close(); + payload = response.toString(); } - in.close(); - + if (cookieManager != null) { cookieManager.storeCookies(c); } - return new ResponseJre(code, c.getResponseMessage(), response.toString(), c.getHeaderFields()); + return new ResponseJre(code, c.getResponseMessage(), payload, c.getHeaderFields()); } private void debugRequest(HttpURLConnection c, String payload) { -- cgit v1.2.3