changeset 1:c9ac6642973c

Renamed GNVClient and GNVClientImpl to HttpClient and HttpClientImpl. http-client/trunk@1324 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 17 Feb 2011 10:51:37 +0000
parents a1db30b33f43
children 2fdfa20cfa63
files ChangeLog src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java src/main/java/de/intevation/artifacts/httpclient/http/GNVClient.java src/main/java/de/intevation/artifacts/httpclient/http/GNVClientImpl.java src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java
diffstat 6 files changed, 285 insertions(+), 272 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Feb 17 10:31:40 2011 +0000
+++ b/ChangeLog	Thu Feb 17 10:51:37 2011 +0000
@@ -1,3 +1,16 @@
+2011-02-17  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/artifacts/httpclient/http/GNVClientImpl.java,
+	  src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java:
+	  Renamed the GNVClientImpl to HttpClientImpl.
+
+	* src/main/java/de/intevation/artifacts/httpclient/http/GNVClient.java,
+	  src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java:
+	  Renamed the GNVClient to HttpClient.
+
+	* src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java:
+	  Adjusted the imports and parameters of GNVClient and GNVClientImpl.
+
 2011-02-17  Ingo Weinzierl <ingo@intevation.de>
 
 	* *: Initial checkin. This package has been copied from 'console-client'.
--- a/src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java	Thu Feb 17 10:31:40 2011 +0000
+++ b/src/main/java/de/intevation/artifacts/httpclient/ConsoleClient.java	Thu Feb 17 10:51:37 2011 +0000
@@ -30,8 +30,8 @@
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
-import de.intevation.artifacts.httpclient.http.GNVClient;
-import de.intevation.artifacts.httpclient.http.GNVClientImpl;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
 
 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
@@ -121,13 +121,13 @@
 
     public static void main( String[] args )
     {
-        logger.info("Starting GNV console client.");
+        logger.info("Starting console client.");
 
         Configuration conf = readConfiguration();
 
         String serverHost  = (String) conf.getServerSettings("host");
         String serverPort  = (String) conf.getServerSettings("port");
-        GNVClient client   = new GNVClientImpl(serverHost + ":" + serverPort);
+        HttpClient client   = new HttpClientImpl(serverHost + ":" + serverPort);
 
         try {
             Document create = ArtifactProtocolUtils.createCreateDocument(
@@ -201,7 +201,7 @@
                     "IO error while writing the output: " + ioe.getMessage());
             }
 
-            logger.debug("Finished GNV console client.");
+            logger.debug("Finished console client.");
         }
         catch (ConnectionException ce) {
             logger.error(ce.getMessage());
@@ -214,7 +214,7 @@
 
 
     public static void feedAndGo(
-        GNVClient client,
+        HttpClient client,
         Artifact  artifact,
         Map       attr,
         String target)
@@ -237,7 +237,7 @@
      * abstract, so it needs to be reimplemented later, I think.
      */
     public static String[] extractOptions(
-        GNVClient client,
+        HttpClient client,
         Artifact  artifact,
         String    text)
     throws NoSuchOptionException, ConnectionException
@@ -299,7 +299,7 @@
      * describe document.
      */
     public static String[] extractMeasurements(
-        GNVClient client,
+        HttpClient client,
         Artifact  artifact,
         String    text)
     throws NoSuchOptionException, ConnectionException
--- a/src/main/java/de/intevation/artifacts/httpclient/http/GNVClient.java	Thu Feb 17 10:31:40 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2010 by Intevation GmbH
- *
- * This program is free software under the LGPL (>=v2.1)
- * Read the file LGPL.txt coming with the software for details
- * or visit http://www.gnu.org/licenses/ if it does not exist.
- */
-package de.intevation.artifacts.httpclient.http;
-
-import java.io.OutputStream;
-
-import org.w3c.dom.Document;
-
-import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
-import de.intevation.artifacts.httpclient.http.response.ResponseHandler;
-import de.intevation.artifacts.httpclient.objects.Artifact;
-import de.intevation.artifacts.httpclient.objects.ArtifactFactory;
-
-/**
- * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
- */
-public interface GNVClient {
-
-    ArtifactFactory[] getArtifactFactories()
-    throws ConnectionException;
-
-    Artifact create(Document createDocument)
-    throws ConnectionException;
-
-    Object describe(
-        Artifact        artifact,
-        Document        describeDocument,
-        ResponseHandler handler)
-    throws ConnectionException;
-
-    Object feed(Artifact artifact, Document feedDocument, ResponseHandler handler)
-    throws ConnectionException;
-
-    Object advance(
-        Artifact        artifact,
-        Document        advanceDocument,
-        ResponseHandler handler)
-    throws ConnectionException;
-
-    void out(
-        Artifact     artifact,
-        Document     outDocument,
-        String       target,
-        OutputStream out)
-    throws ConnectionException;
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/src/main/java/de/intevation/artifacts/httpclient/http/GNVClientImpl.java	Thu Feb 17 10:31:40 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) 2010 by Intevation GmbH
- *
- * This program is free software under the LGPL (>=v2.1)
- * Read the file LGPL.txt coming with the software for details
- * or visit http://www.gnu.org/licenses/ if it does not exist.
- */
-package de.intevation.artifacts.httpclient.http;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.apache.log4j.Logger;
-
-import org.restlet.Client;
-import org.restlet.Request;
-import org.restlet.Response;
-import org.restlet.data.MediaType;
-import org.restlet.data.Method;
-import org.restlet.data.Protocol;
-import org.restlet.data.Status;
-import org.restlet.ext.xml.DomRepresentation;
-import org.restlet.representation.Representation;
-
-import org.w3c.dom.Document;
-
-import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
-import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
-import de.intevation.artifacts.httpclient.http.response.ResponseHandler;
-import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
-import de.intevation.artifacts.httpclient.objects.Artifact;
-import de.intevation.artifacts.httpclient.objects.ArtifactFactory;
-import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils;
-import de.intevation.artifacts.httpclient.utils.XMLUtils;
-
-/**
- * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
- */
-public class GNVClientImpl implements GNVClient {
-
-    private static final Logger logger = Logger.getLogger(GNVClient.class);
-
-    private String serverUrl;
-
-
-    public GNVClientImpl(String serverUrl) {
-        this.serverUrl = serverUrl;
-    }
-
-
-    @Override
-    public ArtifactFactory[] getArtifactFactories()
-    throws ConnectionException
-    {
-        ResponseHandler handler = new DocumentResponseHandler();
-
-        try {
-            String    url   = serverUrl + "/factories";
-            Document result = (Document) handler.handle(doGet(url));
-
-            return ArtifactProtocolUtils.extractArtifactFactories(result);
-        }
-        catch (IOException ioe) {
-            throw new ConnectionException(
-                "Connection to server failed. No Factories recieved.");
-        }
-    }
-
-
-    @Override
-    public Artifact create(Document doc) throws ConnectionException {
-        ResponseHandler handler = new DocumentResponseHandler();
-
-        try {
-            String   url    = serverUrl + "/create";
-            Document result = (Document) handler.handle(doPost(url, doc));
-
-            return ArtifactProtocolUtils.extractArtifact(result);
-        }
-        catch (IOException ioe) {
-            throw new ConnectionException(
-                "Connection to server failed. No Artifact created.");
-        }
-    }
-
-
-    @Override
-    public Object describe(
-        Artifact        artifact,
-        Document        doc,
-        ResponseHandler handler)
-    throws ConnectionException
-    {
-        try {
-            String   url    = serverUrl + "/artifact/" + artifact.getUuid();
-            return handler.handle(doPost(url, doc));
-        }
-        catch (IOException ioe) {
-            throw new ConnectionException(
-                "Connection to server failed: " + ioe.getMessage());
-        }
-    }
-
-
-    @Override
-    public Object feed(Artifact artifact, Document doc, ResponseHandler handler)
-    throws ConnectionException
-    {
-        try {
-            String   url    = serverUrl + "/artifact/" + artifact.getUuid();
-            Document result = (Document) handler.handle(doPost(url, doc));
-
-            return result;
-        }
-        catch (IOException ioe) {
-            throw new ConnectionException(
-                "Connection to server failed: " + ioe.getMessage());
-        }
-    }
-
-
-    @Override
-    public Object advance(Artifact artifact, Document doc, ResponseHandler handler)
-    throws ConnectionException
-    {
-        try {
-            String   url    = serverUrl + "/artifact/" + artifact.getUuid();
-            Document result = (Document) handler.handle(doPost(url, doc));
-
-            return result;
-        }
-        catch (IOException ioe) {
-            throw new ConnectionException(
-                "Connection to server failed: " + ioe.getMessage());
-        }
-    }
-
-
-    @Override
-    public void out(
-        Artifact     artifact,
-        Document     doc,
-        String       target,
-        OutputStream out)
-    throws ConnectionException
-    {
-        try {
-            String url =
-                serverUrl
-                + "/artifact/"
-                + artifact.getUuid()
-                + "/" + target;
-
-            ResponseHandler handler = new StreamResponseHandler();
-
-            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(
-                "Connection to server failed: " + ioe.getMessage());
-        }
-    }
-
-
-    private Response doPost(String url, Document body) throws IOException {
-        logger.info("Start HTTP-POST request to: "+ url);
-
-        Client client   = new Client(Protocol.HTTP);
-        Request request = new Request(Method.POST, url);
-
-        Representation representation = new DomRepresentation(
-            MediaType.APPLICATION_XML,
-            body);
-
-        request.setEntity(representation);
-        Response response = client.handle(request);
-
-        Status status = response.getStatus();
-        if (status.getCode() != 200) {
-            logger.error("Response status: " + status.getCode());
-            throw new IOException(status.getDescription());
-        }
-
-        return response;
-    }
-
-
-    private Response doGet(String url) throws IOException {
-        logger.info("Start HTTP-POST request to: "+ url);
-
-        Client client   = new Client(Protocol.HTTP);
-        Request request = new Request(Method.GET, url);
-
-        Response response = client.handle(request);
-
-        Status status = response.getStatus();
-        if (status.getCode() != 200) {
-            logger.error("Response status: " + status.getCode());
-            throw new IOException(status.getDescription());
-        }
-
-        return response;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClient.java	Thu Feb 17 10:51:37 2011 +0000
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+package de.intevation.artifacts.httpclient.http;
+
+import java.io.OutputStream;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.response.ResponseHandler;
+import de.intevation.artifacts.httpclient.objects.Artifact;
+import de.intevation.artifacts.httpclient.objects.ArtifactFactory;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface HttpClient {
+
+    ArtifactFactory[] getArtifactFactories()
+    throws ConnectionException;
+
+    Artifact create(Document createDocument)
+    throws ConnectionException;
+
+    Object describe(
+        Artifact        artifact,
+        Document        describeDocument,
+        ResponseHandler handler)
+    throws ConnectionException;
+
+    Object feed(Artifact artifact, Document feedDocument, ResponseHandler handler)
+    throws ConnectionException;
+
+    Object advance(
+        Artifact        artifact,
+        Document        advanceDocument,
+        ResponseHandler handler)
+    throws ConnectionException;
+
+    void out(
+        Artifact     artifact,
+        Document     outDocument,
+        String       target,
+        OutputStream out)
+    throws ConnectionException;
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java	Thu Feb 17 10:51:37 2011 +0000
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2010 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+package de.intevation.artifacts.httpclient.http;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.log4j.Logger;
+
+import org.restlet.Client;
+import org.restlet.Request;
+import org.restlet.Response;
+import org.restlet.data.MediaType;
+import org.restlet.data.Method;
+import org.restlet.data.Protocol;
+import org.restlet.data.Status;
+import org.restlet.ext.xml.DomRepresentation;
+import org.restlet.representation.Representation;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
+import de.intevation.artifacts.httpclient.http.response.ResponseHandler;
+import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
+import de.intevation.artifacts.httpclient.objects.Artifact;
+import de.intevation.artifacts.httpclient.objects.ArtifactFactory;
+import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils;
+import de.intevation.artifacts.httpclient.utils.XMLUtils;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class HttpClientImpl implements HttpClient {
+
+    private static final Logger logger = Logger.getLogger(HttpClient.class);
+
+    private String serverUrl;
+
+
+    public HttpClientImpl(String serverUrl) {
+        this.serverUrl = serverUrl;
+    }
+
+
+    @Override
+    public ArtifactFactory[] getArtifactFactories()
+    throws ConnectionException
+    {
+        ResponseHandler handler = new DocumentResponseHandler();
+
+        try {
+            String    url   = serverUrl + "/factories";
+            Document result = (Document) handler.handle(doGet(url));
+
+            return ArtifactProtocolUtils.extractArtifactFactories(result);
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(
+                "Connection to server failed. No Factories recieved.");
+        }
+    }
+
+
+    @Override
+    public Artifact create(Document doc) throws ConnectionException {
+        ResponseHandler handler = new DocumentResponseHandler();
+
+        try {
+            String   url    = serverUrl + "/create";
+            Document result = (Document) handler.handle(doPost(url, doc));
+
+            return ArtifactProtocolUtils.extractArtifact(result);
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(
+                "Connection to server failed. No Artifact created.");
+        }
+    }
+
+
+    @Override
+    public Object describe(
+        Artifact        artifact,
+        Document        doc,
+        ResponseHandler handler)
+    throws ConnectionException
+    {
+        try {
+            String   url    = serverUrl + "/artifact/" + artifact.getUuid();
+            return handler.handle(doPost(url, doc));
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(
+                "Connection to server failed: " + ioe.getMessage());
+        }
+    }
+
+
+    @Override
+    public Object feed(Artifact artifact, Document doc, ResponseHandler handler)
+    throws ConnectionException
+    {
+        try {
+            String   url    = serverUrl + "/artifact/" + artifact.getUuid();
+            Document result = (Document) handler.handle(doPost(url, doc));
+
+            return result;
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(
+                "Connection to server failed: " + ioe.getMessage());
+        }
+    }
+
+
+    @Override
+    public Object advance(Artifact artifact, Document doc, ResponseHandler handler)
+    throws ConnectionException
+    {
+        try {
+            String   url    = serverUrl + "/artifact/" + artifact.getUuid();
+            Document result = (Document) handler.handle(doPost(url, doc));
+
+            return result;
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(
+                "Connection to server failed: " + ioe.getMessage());
+        }
+    }
+
+
+    @Override
+    public void out(
+        Artifact     artifact,
+        Document     doc,
+        String       target,
+        OutputStream out)
+    throws ConnectionException
+    {
+        try {
+            String url =
+                serverUrl
+                + "/artifact/"
+                + artifact.getUuid()
+                + "/" + target;
+
+            ResponseHandler handler = new StreamResponseHandler();
+
+            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(
+                "Connection to server failed: " + ioe.getMessage());
+        }
+    }
+
+
+    private Response doPost(String url, Document body) throws IOException {
+        logger.info("Start HTTP-POST request to: "+ url);
+
+        Client client   = new Client(Protocol.HTTP);
+        Request request = new Request(Method.POST, url);
+
+        Representation representation = new DomRepresentation(
+            MediaType.APPLICATION_XML,
+            body);
+
+        request.setEntity(representation);
+        Response response = client.handle(request);
+
+        Status status = response.getStatus();
+        if (status.getCode() != 200) {
+            logger.error("Response status: " + status.getCode());
+            throw new IOException(status.getDescription());
+        }
+
+        return response;
+    }
+
+
+    private Response doGet(String url) throws IOException {
+        logger.info("Start HTTP-POST request to: "+ url);
+
+        Client client   = new Client(Protocol.HTTP);
+        Request request = new Request(Method.GET, url);
+
+        Response response = client.handle(request);
+
+        Status status = response.getStatus();
+        if (status.getCode() != 200) {
+            logger.error("Response status: " + status.getCode());
+            throw new IOException(status.getDescription());
+        }
+
+        return response;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org