Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/server/DistanceInfoXML.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/DistanceInfoXML.java@bc06a671ef60 |
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:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
27 */ | |
28 public class DistanceInfoXML | |
29 extends HttpServlet | |
30 { | |
31 private static final Logger logger = Logger.getLogger(DistanceInfoXML.class); | |
32 | |
33 | |
34 public static final String ERROR_NO_DISTANCEINFO_FOUND = | |
35 "error_no_distanceinfo_found"; | |
36 | |
37 | |
38 public void doGet(HttpServletRequest req, HttpServletResponse resp) { | |
39 logger.info("DistanceInfoXML.doGet"); | |
40 | |
41 String url = getServletContext().getInitParameter("server-url"); | |
42 | |
43 String river = req.getParameter("river"); | |
44 String filter = req.getParameter("filter"); | |
45 | |
46 Document doc = XMLUtils.newDocument(); | |
47 | |
48 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
49 doc, | |
50 ArtifactNamespaceContext.NAMESPACE_URI, | |
51 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
52 | |
53 Element riverEl = ec.create("river"); | |
54 riverEl.setTextContent(river); | |
55 | |
56 doc.appendChild(riverEl); | |
57 | |
58 if (filter != null && filter.length() > 0) { | |
59 Element typeEl = ec.create("filter"); | |
60 typeEl.setTextContent(filter); | |
61 | |
62 riverEl.appendChild(typeEl); | |
63 } | |
64 | |
65 HttpClient client = new HttpClientImpl(url); | |
66 | |
67 try { | |
68 InputStream in = (InputStream) client.callService( | |
69 url, "distanceinfo", doc, new StreamResponseHandler()); | |
70 | |
71 OutputStream out = resp.getOutputStream(); | |
72 | |
73 byte[] b = new byte[4096]; | |
74 int i; | |
75 while ((i = in.read(b)) >= 0) { | |
76 out.write(b, 0, i); | |
77 } | |
78 | |
79 out.flush(); | |
80 out.close(); | |
81 } | |
82 catch (ConnectionException ce) { | |
83 logger.error(ce, ce); | |
84 } | |
85 catch (IOException ioe) { | |
86 logger.error(ioe, ioe); | |
87 } | |
88 } | |
89 } | |
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |