changeset 116:c92b50c9c99a

Slightly improved error handling if response entity could not be parsed.
author gernotbelger
date Wed, 13 Jun 2018 15:37:12 +0200
parents 6e694ec61246
children 5b184dc5b4a9
files src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java src/main/java/org/dive4elements/artifacts/httpclient/http/response/DocumentResponseHandler.java
diffstat 2 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Mon Dec 28 17:54:40 2015 +0100
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Wed Jun 13 15:37:12 2018 +0200
@@ -146,15 +146,23 @@
 
         try {
             String   url    = serverUrl + "/create";
-            Document result = (Document) handler.handle(doPost(url, doc));
+            Response response = doPost(url, doc);
+            try {
+                Document result = (Document) handler.handle(response);
 
-            return creator == null
-                ? ArtifactProtocolUtils.extractArtifact(result)
-                : creator.create(result);
+                return creator == null
+                    ? ArtifactProtocolUtils.extractArtifact(result)
+                    : creator.create(result);
+            }
+            catch (IOException e) {
+                String entityAsText = response.getEntityAsText();
+                throw new ConnectionException(
+                        "Connection to server failed. No Artifact created. Response was: " + entityAsText, e);
+            }
         }
         catch (IOException ioe) {
             throw new ConnectionException(
-                "Connection to server failed. No Artifact created.");
+                "Connection to server failed. No Artifact created.", ioe);
         }
     }
 
--- a/src/main/java/org/dive4elements/artifacts/httpclient/http/response/DocumentResponseHandler.java	Mon Dec 28 17:54:40 2015 +0100
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/http/response/DocumentResponseHandler.java	Wed Jun 13 15:37:12 2018 +0200
@@ -9,24 +9,19 @@
 
 import java.io.IOException;
 
+import org.dive4elements.artifacts.httpclient.utils.XMLUtils;
 import org.restlet.Response;
 import org.restlet.representation.Representation;
 
-import org.dive4elements.artifacts.httpclient.utils.XMLUtils;
-
-
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class DocumentResponseHandler implements ResponseHandler {
 
-    public DocumentResponseHandler() {
-    }
-
     @Override
-    public Object handle(Response response) throws IOException {
-        Representation output = response.getEntity();
-        return XMLUtils.readDocument(output.getStream());
+    public Object handle(final Response response) throws IOException {
+        final Representation output = response.getEntity();
+            // FIXME: stream not closed?
+            return XMLUtils.readDocument(output.getStream());
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org