From 73bd798ddaaa57045cb4c4060e947bd5410da292 Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Mon, 19 Mar 2018 16:04:21 +0000 Subject: [PATCH] Fixed: HttpClient failed to return the error result (OFBIZ-10281) When you call the HttpClient on Rest API on url that return you an error, the HttpClient failed to give you the error stream: callResult = restClient.getStream(); If the flow is an error in the catch block with the line in = con.getInputStream(); that return a FileNotFoundException To solve if, if the connexion is an instance of HttpURLConnection we resolve this error inputStream contains the error message git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1827212 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/ofbiz/base/util/HttpClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java index 7ad0154eea..150401b0da 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java @@ -537,6 +537,14 @@ public class HttpClient { Debug.logWarning(ioe.getCause(), module); return sendHttpRequestStream(method, true); } + if ((con instanceof HttpURLConnection)) { + try { + in = ((HttpURLConnection) con).getErrorStream(); + } catch (Exception ioerror) { + throw new HttpClientException("IO Error processing request", ioerror); + } + return in; + } throw new HttpClientException("IO Error processing request", ioe); } catch (RuntimeException e) { throw e;