Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.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; |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
11 import java.io.InputStreamReader; |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import java.io.OutputStream; |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import java.io.IOException; |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
14 import java.io.OutputStreamWriter; |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import org.w3c.dom.Document; |
3499
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
17 import org.w3c.dom.Element; |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
9726 | 19 import org.apache.logging.log4j.Logger; |
20 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:
432
diff
changeset
|
21 |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import javax.servlet.http.HttpServlet; |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import javax.servlet.http.HttpServletRequest; |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import javax.servlet.http.HttpServletResponse; |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
26 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
27 import org.dive4elements.artifacts.common.utils.XMLUtils; |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
5835
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; |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 /** |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 * This service is used to request a data export from the artifact server. The |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 * response is directed directly to the output stream, so that a file dialog is |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 * opened. |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 * |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 */ |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 public class ExportServiceImpl |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 extends HttpServlet |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 { |
8203
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
43 private static final Logger log = |
9726 | 44 LogManager.getLogger(ExportServiceImpl.class); |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
45 |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
46 |
274
71a7533555d0
Added a service to export data from the artifact server.
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:
7633
diff
changeset
|
48 log.info("ExportServiceImpl.doGet"); |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 try { |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
51 final OutputStream out = resp.getOutputStream(); |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
3500
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
53 String url = getServletContext().getInitParameter("server-url"); |
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
54 String uuid = req.getParameter("uuid"); |
4912
94b95e002fb9
Added filename to export url.
Raimund Renkert <rrenkert@intevation.de>
parents:
3500
diff
changeset
|
55 String name = req.getParameter("name"); |
3500
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
56 String mode = req.getParameter("mode"); |
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
57 String type = req.getParameter("type"); |
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
58 String locale = req.getParameter("locale"); |
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
59 String km = req.getParameter("km"); |
4912
94b95e002fb9
Added filename to export url.
Raimund Renkert <rrenkert@intevation.de>
parents:
3500
diff
changeset
|
60 String fn = name + "." + type; |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
61 final String enc = req.getParameter("encoding"); |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 resp.setHeader("Content-Disposition", "attachment;filename=" + fn); |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
8203
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
65 if (log.isDebugEnabled()) { |
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
66 log.debug("Request " + type + " export."); |
3500
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
67 } |
3499
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
68 |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
69 Document attr = null; |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
70 if (km != null && km.length() > 0) { |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
71 attr = XMLUtils.newDocument(); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
72 XMLUtils.ElementCreator ec = |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
73 new XMLUtils.ElementCreator(attr, null, null); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
74 Element e = ec.create("km"); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
75 e.setTextContent(km); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
76 attr.appendChild(e); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
77 } |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 Document request = ClientProtocolUtils.newOutCollectionDocument( |
3499
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
79 uuid, mode, type, attr); |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
80 HttpClient client = new HttpClientImpl(url, locale); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
81 |
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
82 if (enc != null) { |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
83 InputStreamReader in = new InputStreamReader( |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
84 client.collectionOut(request, uuid, mode), |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
85 "UTF-8"); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
86 try { |
8856 | 87 OutputStreamWriter encOut = new OutputStreamWriter( |
88 out, enc); | |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
89 char buf [] = new char[4096]; |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
90 int c; |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
91 while ((c = in.read(buf, 0, buf.length)) >= 0) { |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
92 encOut.write(buf, 0, c); |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
93 } |
7633
e469d9939a52
(issue1630) Flush the correct outer output stream
Andre Heinecke <aheinecke@intevation.de>
parents:
7486
diff
changeset
|
94 encOut.flush(); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
95 } |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
96 finally { |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
97 in.close(); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
98 } |
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
99 } |
7486
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
100 else { // Just copy thru. |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
101 client.collectionOut(request, uuid, mode, out); |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
102 out.flush(); |
6b278187ed9d
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7139
diff
changeset
|
103 } |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 } |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 catch (IOException ioe) { |
8203
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
106 log.error(ioe, ioe); |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 } |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 } |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 } |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |