Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java @ 9071:a561b882436d
create module bundu (Betrieb & Unterhaltung)
incl. original Fixierungsanalyse+Ausgelagerte Wasserspiegellage
author | gernotbelger |
---|---|
date | Wed, 16 May 2018 11:08:56 +0200 |
parents | 5e38e2924c07 |
children | 0a5239a1e46e |
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 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
19 import org.apache.log4j.Logger; |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
20 |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
25 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
26 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
|
27 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
28 import org.dive4elements.artifacts.httpclient.http.HttpClient; |
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
29 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
|
30 |
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 * 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
|
34 * 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
|
35 * opened. |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 * |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 * @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
|
38 */ |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 public class ExportServiceImpl |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 extends HttpServlet |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 { |
8203
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
42 private static final Logger log = |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
43 Logger.getLogger(ExportServiceImpl.class); |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
44 |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
432
diff
changeset
|
45 |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 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
|
47 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
|
48 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 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
|
50 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
|
51 |
3500
def13f23bb27
Removed superfluous import. Removed some inner whitespace. Made debug output conditional.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3499
diff
changeset
|
52 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
|
53 String uuid = req.getParameter("uuid"); |
4912
94b95e002fb9
Added filename to export url.
Raimund Renkert <rrenkert@intevation.de>
parents:
3500
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 String km = req.getParameter("km"); |
4912
94b95e002fb9
Added filename to export url.
Raimund Renkert <rrenkert@intevation.de>
parents:
3500
diff
changeset
|
59 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
|
60 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
|
61 |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 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
|
63 |
8203
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
64 if (log.isDebugEnabled()) { |
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
65 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
|
66 } |
3499
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
67 |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
68 Document attr = null; |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
69 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
|
70 attr = XMLUtils.newDocument(); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
71 XMLUtils.ElementCreator ec = |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
72 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
|
73 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
|
74 e.setTextContent(km); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
75 attr.appendChild(e); |
17c66d38f095
FixA: Added AT file export to FixAnalysis W/Q.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1425
diff
changeset
|
76 } |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 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
|
78 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
|
79 HttpClient client = new HttpClientImpl(url, locale); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
80 |
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 "UTF-8"); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
85 try { |
8856 | 86 OutputStreamWriter encOut = new OutputStreamWriter( |
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 } |
7633
e469d9939a52
(issue1630) Flush the correct outer output stream
Andre Heinecke <aheinecke@intevation.de>
parents:
7486
diff
changeset
|
93 encOut.flush(); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
94 } |
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
|
95 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
|
96 in.close(); |
7139
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
97 } |
6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5993
diff
changeset
|
98 } |
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
|
99 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
|
100 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
|
101 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
|
102 } |
274
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 } |
71a7533555d0
Added a service to export data from the artifact server.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 catch (IOException ioe) { |
8203
238fc722f87a
sed 's/logger/log/g' src/**/*.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7633
diff
changeset
|
105 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
|
106 } |
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |