annotate gwt-client/src/main/java/org/dive4elements/river/client/server/DistanceInfoXML.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5861
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5993
ea9eef426962 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5861
diff changeset
6 * documentation coming with Dive4Elements River for details.
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 package org.dive4elements.river.client.server;
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
10
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
11 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
12 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
13 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
14
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 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
16 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
17
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
18 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
19 import org.apache.logging.log4j.LogManager;
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 782
diff changeset
20
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
21 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
22 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
23 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
24
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
25 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
26 import org.dive4elements.artifacts.common.utils.XMLUtils;
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
27
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
28 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
29 import org.dive4elements.artifacts.httpclient.http.HttpClient;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
30 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
31 import org.dive4elements.artifacts.httpclient.http.response.StreamResponseHandler;
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
32
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
33
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 /**
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 * @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
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 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
38 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
39 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8203
diff changeset
40 private static final Logger log = LogManager.getLogger(DistanceInfoXML.class);
1367
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 782
diff changeset
41
ab8eb2f544f2 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 782
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 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
44 "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
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
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 public void doGet(HttpServletRequest req, HttpServletResponse resp) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
48 log.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
49
1425
bc06a671ef60 Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1367
diff changeset
50 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
51
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
52 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
53 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
54
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 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
56
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 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
58 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
59 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
60 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
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 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
63 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
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 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
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 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
68 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
69 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
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 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
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
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 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
75
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 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
77 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
78 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
79
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 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
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 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
83 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
84 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
85 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
86 }
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 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
89 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
90 }
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
91 catch (ConnectionException ce) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
92 log.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
93 }
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
94 catch (IOException ioe) {
8203
238fc722f87a sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5993
diff changeset
95 log.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
96 }
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
97 }
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
98 }
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
99 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org