comparison flys-client/src/main/java/org/dive4elements/river/client/server/DischargeInfoXML.java @ 5834:f507086aa94b

Repaired internal references.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:31:32 +0200
parents flys-client/src/main/java/de/intevation/flys/client/server/DischargeInfoXML.java@67468c90ca68
children 821a02bbfb4e
comparison
equal deleted inserted replaced
5833:a2bdc0f524e8 5834:f507086aa94b
1 package de.intevation.flys.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 de.intevation.artifacts.common.ArtifactNamespaceContext;
17 import de.intevation.artifacts.common.utils.XMLUtils;
18
19 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
20 import de.intevation.artifacts.httpclient.http.HttpClient;
21 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
22 import de.intevation.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