diff flys-client/src/main/java/de/intevation/flys/client/server/DischargeInfoXML.java @ 1600:67468c90ca68

Added service to request discharge infos at a specific gauge. flys-client/trunk@3938 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 06 Feb 2012 16:01:22 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DischargeInfoXML.java	Mon Feb 06 16:01:22 2012 +0000
@@ -0,0 +1,82 @@
+package de.intevation.flys.client.server;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.log4j.Logger;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class DischargeInfoXML
+extends      HttpServlet
+{
+    private static final Logger logger = Logger.getLogger(DischargeInfoXML.class);
+
+
+    public static final String ERROR_NO_DISTANCEINFO_FOUND =
+        "error_no_dischargeinfo_found";
+
+
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+        logger.info("DischargeInfoXML.doGet");
+
+        String url  = getServletContext().getInitParameter("server-url");
+
+        String gauge = req.getParameter("gauge");
+
+        Document doc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element gaugeEl = ec.create("gauge");
+        gaugeEl.setTextContent(gauge);
+
+        doc.appendChild(gaugeEl);
+
+        HttpClient client = new HttpClientImpl(url);
+
+        try {
+            InputStream in = (InputStream) client.callService(
+                url, "dischargeinfo", doc, new StreamResponseHandler());
+
+            OutputStream out = resp.getOutputStream();
+
+            byte[] b = new byte[4096];
+            int i;
+            while ((i = in.read(b)) >= 0) {
+                out.write(b, 0, i);
+            }
+
+            out.flush();
+            out.close();
+        }
+        catch (ConnectionException ce) {
+            logger.error(ce, ce);
+        }
+        catch (IOException ioe) {
+            logger.error(ioe, ioe);
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org