Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoXML.java @ 4740:fb135e1dfa35
Added 'type' attribute to <dc:variable/> element. If an optional 'type' attribute is given
the result of the XPATH expression is interpreted as this type.
Valid values are 'number', 'bool', 'node' and 'nodeset'. All other defaults
to 'string' which also is the default if nor type is given.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 02 Jan 2013 15:31:53 +0100 |
parents | bc06a671ef60 |
children |
rev | line source |
---|---|
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.io.InputStream; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.io.IOException; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.io.OutputStream; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Document; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Element; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
10 import org.apache.log4j.Logger; |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
11 |
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import javax.servlet.http.HttpServlet; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import javax.servlet.http.HttpServletRequest; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import javax.servlet.http.HttpServletResponse; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifacts.common.utils.XMLUtils; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.artifacts.httpclient.http.HttpClient; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 /** |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 */ |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 public class DistanceInfoXML |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 extends HttpServlet |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
31 private static final Logger logger = Logger.getLogger(DistanceInfoXML.class); |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
32 |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
33 |
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public static final String ERROR_NO_DISTANCEINFO_FOUND = |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 "error_no_distanceinfo_found"; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 public void doGet(HttpServletRequest req, HttpServletResponse resp) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
39 logger.info("DistanceInfoXML.doGet"); |
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
41 String url = getServletContext().getInitParameter("server-url"); |
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
42 |
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 String river = req.getParameter("river"); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 String filter = req.getParameter("filter"); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 Document doc = XMLUtils.newDocument(); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 doc, |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 ArtifactNamespaceContext.NAMESPACE_URI, |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 Element riverEl = ec.create("river"); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 riverEl.setTextContent(river); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 doc.appendChild(riverEl); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 if (filter != null && filter.length() > 0) { |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 Element typeEl = ec.create("filter"); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 typeEl.setTextContent(filter); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 riverEl.appendChild(typeEl); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 HttpClient client = new HttpClientImpl(url); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 try { |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 InputStream in = (InputStream) client.callService( |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 url, "distanceinfo", doc, new StreamResponseHandler()); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 OutputStream out = resp.getOutputStream(); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 byte[] b = new byte[4096]; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 int i; |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 while ((i = in.read(b)) >= 0) { |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 out.write(b, 0, i); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 out.flush(); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 out.close(); |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 catch (ConnectionException ce) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
83 logger.error(ce, ce); |
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 catch (IOException ioe) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
782
diff
changeset
|
86 logger.error(ioe, ioe); |
782
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 } |
4a7ece57f44c
#159 The tables in the WQ panel for calculation 4 are now filled with data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |