comparison gwt-client/src/main/java/org/dive4elements/river/client/server/DischargeInfoXML.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/server/DischargeInfoXML.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.client.server;
2
3 import java.io.InputStream;
4 import java.io.IOException;
5 import java.io.OutputStream;
6
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9
10 import org.apache.log4j.Logger;
11
12 import javax.servlet.http.HttpServlet;
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15
16 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
17 import org.dive4elements.artifacts.common.utils.XMLUtils;
18
19 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException;
20 import org.dive4elements.artifacts.httpclient.http.HttpClient;
21 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
22 import org.dive4elements.artifacts.httpclient.http.response.StreamResponseHandler;
23
24
25 /**
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
27 */
28 public class DischargeInfoXML
29 extends HttpServlet
30 {
31 private static final Logger logger = Logger.getLogger(DischargeInfoXML.class);
32
33
34 public static final String ERROR_NO_DISTANCEINFO_FOUND =
35 "error_no_dischargeinfo_found";
36
37
38 public void doGet(HttpServletRequest req, HttpServletResponse resp) {
39 logger.info("DischargeInfoXML.doGet");
40
41 String url = getServletContext().getInitParameter("server-url");
42
43 String gauge = req.getParameter("gauge");
44
45 Document doc = XMLUtils.newDocument();
46
47 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
48 doc,
49 ArtifactNamespaceContext.NAMESPACE_URI,
50 ArtifactNamespaceContext.NAMESPACE_PREFIX);
51
52 Element gaugeEl = ec.create("gauge");
53 gaugeEl.setTextContent(gauge);
54
55 doc.appendChild(gaugeEl);
56
57 HttpClient client = new HttpClientImpl(url);
58
59 try {
60 InputStream in = (InputStream) client.callService(
61 url, "dischargeinfo", doc, new StreamResponseHandler());
62
63 OutputStream out = resp.getOutputStream();
64
65 byte[] b = new byte[4096];
66 int i;
67 while ((i = in.read(b)) >= 0) {
68 out.write(b, 0, i);
69 }
70
71 out.flush();
72 out.close();
73 }
74 catch (ConnectionException ce) {
75 logger.error(ce, ce);
76 }
77 catch (IOException ioe) {
78 logger.error(ioe, ioe);
79 }
80 }
81 }
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org