changeset 9:072e8d488f83

Enhanced the HttpClient with a method to trigger the out() operation of Collections. http-client/trunk@1654 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 07 Apr 2011 11:28:15 +0000
parents 77c09d0e2c2e
children e79283dad6f2
files ChangeLog src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java
diffstat 3 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 30 13:46:07 2011 +0000
+++ b/ChangeLog	Thu Apr 07 11:28:15 2011 +0000
@@ -1,3 +1,10 @@
+2011-04-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java,
+	  src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java:
+	  Added a method that triggers the out() operation of a Collection and
+	  writes the result to an OutputStream.
+
 2011-03-30  Ingo Weinzierl <ingo@intevation.de>
 
 	Tagged RELEASE 0.1
--- a/src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java	Wed Mar 30 13:46:07 2011 +0000
+++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java	Thu Apr 07 11:28:15 2011 +0000
@@ -75,6 +75,13 @@
         ResponseHandler handler)
     throws ConnectionException;
 
+    void collectionOut(
+        Document     outDocument,
+        String       uuid,
+        String       type,
+        OutputStream out)
+    throws ConnectionException;
+
 
     /*******************************
      * Users API
--- a/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java	Wed Mar 30 13:46:07 2011 +0000
+++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java	Thu Apr 07 11:28:15 2011 +0000
@@ -58,6 +58,9 @@
     /** The URL path of the resource to work with an artifact collections.*/
     public static final String PATH_ACTION_COLLECTION = "/collection";
 
+    /** The URL path of the resource to work with an artifact collections.*/
+    public static final String PATH_OUT_COLLECTION = "/collection";
+
     private String serverUrl;
 
 
@@ -300,6 +303,42 @@
     }
 
 
+    /**
+     * This method triggers the out() operation of a Collection. The result of
+     * this operation is written to <i>out</i> directly - there is no return
+     * value.
+     *
+     * @param doc The request document for the out() operation.
+     * @param uuid The identifier of the Collection.
+     * @param type The name of the output type.
+     * @param out The OutputStream.
+     */
+    public void collectionOut(
+        Document     doc,
+        String       uuid,
+        String       type,
+        OutputStream out)
+    throws ConnectionException
+    {
+        String url = serverUrl + PATH_OUT_COLLECTION + "/" + uuid + "/" + type;
+
+        ResponseHandler handler = new StreamResponseHandler();
+
+        try {
+            InputStream stream = (InputStream) handler.handle(doPost(url, doc));
+
+            byte[] b = new byte[4096];
+            int i = -1;
+            while ((i = stream.read(b)) > 0) {
+                out.write(b, 0, i);
+            }
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(ioe.getMessage(), ioe);
+        }
+    }
+
+
     /*******************************
      * Service API
      *******************************/

http://dive4elements.wald.intevation.org