annotate flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java @ 4671:4ca05e5f3399

Added i18n strings.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 13 Dec 2012 15:57:09 +0100
parents 51ed89b754ae
children
rev   line source
2488
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import de.intevation.artifacts.common.utils.XMLUtils;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import de.intevation.artifacts.httpclient.http.HttpClient;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.io.IOException;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.io.InputStream;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.io.OutputStream;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import javax.servlet.http.HttpServlet;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import javax.servlet.http.HttpServletRequest;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import javax.servlet.http.HttpServletResponse;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.apache.log4j.Logger;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.Document;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import org.w3c.dom.Element;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 import org.w3c.dom.NodeList;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 public class FixingsKMChartServiceImpl
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 extends HttpServlet
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 private static final Logger log =
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 Logger.getLogger(FixingsKMChartServiceImpl.class);
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public static final String SERVICE_NAME = "fixings-km-chart";
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public FixingsKMChartServiceImpl() {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public void doGet(HttpServletRequest req, HttpServletResponse resp) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 log.info("FixingsKMChartServiceImpl.doGet");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 String url = getServletContext().getInitParameter("server-url");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 String locale = req.getParameter("locale");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 String filter = req.getParameter("filter");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 if (filter == null || filter.length() == 0) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 log.warn("Missing 'filter' parameter.");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 return;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 if (locale == null || locale.length() == 0) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 locale = "de";
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 Document filterDoc = XMLUtils.jsonToXML(filter);
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 if (filterDoc == null) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 log.warn("Creating filter document failed.");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 return;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 InputStream in;
2905
51ed89b754ae FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2493
diff changeset
62
2488
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 try {
2493
f905c936ffff Added the XSL transformation to generate the fixings overview.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2488
diff changeset
64 HttpClient client = new HttpClientImpl(url, locale);
2488
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 in = (InputStream)client.callService(
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 url, // XXX: Why? The URL is passed by construction already.
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 SERVICE_NAME,
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 filterDoc,
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 new StreamResponseHandler());
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 catch (ConnectionException ce) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 log.error(ce);
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 return;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75
2493
f905c936ffff Added the XSL transformation to generate the fixings overview.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2488
diff changeset
76 resp.setHeader("Content-Type", guessMIMEType(filterDoc));
f905c936ffff Added the XSL transformation to generate the fixings overview.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2488
diff changeset
77
2488
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 try {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 OutputStream out = resp.getOutputStream();
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 byte [] buf = new byte[4096];
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 int i = -1;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 while ((i = in.read(buf)) >= 0) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 out.write(buf, 0, i);
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 out.flush();
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 catch (IOException ioe) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 log.error(ioe);
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 finally {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 try { in.close(); }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 catch (IOException ioe) { /* ignored */ }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 protected static String guessMIMEType(Document document) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 NodeList formats = document.getElementsByTagName("format");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 String format = "png";
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 if (formats.getLength() > 0) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 String type = ((Element)formats.item(0)).getAttribute("type");
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 if (type.length() > 0) {
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 format = type;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 return "image/" + format;
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 }
88d44cae592e Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org