Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/DischargeInfoXML.java @ 5385:2da74705c29d
Scheme change: Building table is extended and got a lookup table for kind
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 22 Mar 2013 17:30:10 +0100 |
parents | 67468c90ca68 |
children |
rev | line source |
---|---|
1600
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import java.io.InputStream; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 import java.io.IOException; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 import java.io.OutputStream; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Document; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Element; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 import javax.servlet.http.HttpServlet; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 import javax.servlet.http.HttpServletRequest; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 import javax.servlet.http.HttpServletResponse; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifacts.common.utils.XMLUtils; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.artifacts.httpclient.http.HttpClient; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 /** |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 */ |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 public class DischargeInfoXML |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 extends HttpServlet |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 { |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 private static final Logger logger = Logger.getLogger(DischargeInfoXML.class); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 public static final String ERROR_NO_DISTANCEINFO_FOUND = |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 "error_no_dischargeinfo_found"; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 public void doGet(HttpServletRequest req, HttpServletResponse resp) { |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 logger.info("DischargeInfoXML.doGet"); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 String url = getServletContext().getInitParameter("server-url"); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 String gauge = req.getParameter("gauge"); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 Document doc = XMLUtils.newDocument(); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 doc, |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 ArtifactNamespaceContext.NAMESPACE_URI, |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 Element gaugeEl = ec.create("gauge"); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 gaugeEl.setTextContent(gauge); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 doc.appendChild(gaugeEl); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 HttpClient client = new HttpClientImpl(url); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 try { |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 InputStream in = (InputStream) client.callService( |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 url, "dischargeinfo", doc, new StreamResponseHandler()); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 OutputStream out = resp.getOutputStream(); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 byte[] b = new byte[4096]; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 int i; |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 while ((i = in.read(b)) >= 0) { |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 out.write(b, 0, i); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 } |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 out.flush(); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 out.close(); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 } |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 catch (ConnectionException ce) { |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 logger.error(ce, ce); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 } |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 catch (IOException ioe) { |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 logger.error(ioe, ioe); |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 } |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 } |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 } |
67468c90ca68
Added service to request discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |