svn commit: r1827212 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1827212 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java

nmalin
Author: nmalin
Date: Mon Mar 19 16:04:21 2018
New Revision: 1827212

URL: http://svn.apache.org/viewvc?rev=1827212&view=rev
Log:
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

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java?rev=1827212&r1=1827211&r2=1827212&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/HttpClient.java Mon Mar 19 16:04:21 2018
@@ -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;