Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java @ 782:4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
flys-client/trunk@2273 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 01 Jul 2011 08:44:24 +0000 |
parents | |
children | ab8eb2f544f2 |
comparison
equal
deleted
inserted
replaced
781:6653cf54b45d | 782:4a7ece57f44c |
---|---|
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 javax.servlet.http.HttpServlet; | |
11 import javax.servlet.http.HttpServletRequest; | |
12 import javax.servlet.http.HttpServletResponse; | |
13 | |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
15 import de.intevation.artifacts.common.utils.XMLUtils; | |
16 | |
17 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | |
18 import de.intevation.artifacts.httpclient.http.HttpClient; | |
19 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
20 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; | |
21 | |
22 | |
23 /** | |
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
25 */ | |
26 public class DistanceInfoXML | |
27 extends HttpServlet | |
28 { | |
29 public static final String ERROR_NO_DISTANCEINFO_FOUND = | |
30 "error_no_distanceinfo_found"; | |
31 | |
32 | |
33 public void doGet(HttpServletRequest req, HttpServletResponse resp) { | |
34 System.out.println("DistanceInfoXML.doGet"); | |
35 | |
36 String river = req.getParameter("river"); | |
37 String url = req.getParameter("server"); | |
38 String filter = req.getParameter("filter"); | |
39 | |
40 Document doc = XMLUtils.newDocument(); | |
41 | |
42 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
43 doc, | |
44 ArtifactNamespaceContext.NAMESPACE_URI, | |
45 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
46 | |
47 Element riverEl = ec.create("river"); | |
48 riverEl.setTextContent(river); | |
49 | |
50 doc.appendChild(riverEl); | |
51 | |
52 if (filter != null && filter.length() > 0) { | |
53 Element typeEl = ec.create("filter"); | |
54 typeEl.setTextContent(filter); | |
55 | |
56 riverEl.appendChild(typeEl); | |
57 } | |
58 | |
59 HttpClient client = new HttpClientImpl(url); | |
60 | |
61 try { | |
62 InputStream in = (InputStream) client.callService( | |
63 url, "distanceinfo", doc, new StreamResponseHandler()); | |
64 | |
65 OutputStream out = resp.getOutputStream(); | |
66 | |
67 byte[] b = new byte[4096]; | |
68 int i; | |
69 while ((i = in.read(b)) >= 0) { | |
70 out.write(b, 0, i); | |
71 } | |
72 | |
73 out.flush(); | |
74 out.close(); | |
75 } | |
76 catch (ConnectionException ce) { | |
77 System.err.println(ce.getLocalizedMessage()); | |
78 } | |
79 catch (IOException ioe) { | |
80 System.err.println(ioe.getLocalizedMessage()); | |
81 } | |
82 } | |
83 } | |
84 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |