aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Carrasco <manolo@apache.org>2014-02-08 13:40:46 +0100
committerManuel Carrasco <manolo@apache.org>2014-02-08 13:40:46 +0100
commit10c8c43aed6a80277a128d0932a271da03df6347 (patch)
tree6e3373823e27113378ef08bcdf4352cc6d81ba25
parentb415e6a811f3e29bc401f94de0dbaf4a53bc597c (diff)
parente081f61c8c5340bbc1b2050e1d9b84a08d116bb6 (diff)
downloadgwtquery-10c8c43aed6a80277a128d0932a271da03df6347.tar.gz
gwtquery-10c8c43aed6a80277a128d0932a271da03df6347.zip
Merge pull request #267 from gwtquery/mcm_fixes
JVM ajax fixes
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java8
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java23
2 files changed, 18 insertions, 13 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);
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) {