From e081f61c8c5340bbc1b2050e1d9b84a08d116bb6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Sat, 8 Feb 2014 11:26:29 +0100 Subject: [PATCH] Fix filenotfound exception when the response is an error --- .../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) { -- 2.39.5