Mercurial > dive4elements > river
changeset 2488:88d44cae592e
Added new proxy servlet to bridge the fixing km chart requests to the artefact server.
flys-client/trunk@4275 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 19 Apr 2012 11:00:18 +0000 |
parents | 75d11997921c |
children | 2a504b6d9a1b |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml |
diffstat | 3 files changed, 134 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Wed Apr 18 11:42:18 2012 +0000 +++ b/flys-client/ChangeLog Thu Apr 19 11:00:18 2012 +0000 @@ -1,3 +1,11 @@ +2012-04-19 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java: + New. Bridge fixings km chart requests from web to artefact server. The filters + have to be JSON encoded and passed in the the 'filter' parameter. + + src/main/webapp/WEB-INF/web.xml: Registered the new proxy servlet. + 2012-04-18 Raimund Renkert <raimund.renkert@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java Thu Apr 19 11:00:18 2012 +0000 @@ -0,0 +1,116 @@ +package de.intevation.flys.client.server; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; + +import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class FixingsKMChartServiceImpl +extends HttpServlet +{ + private static final Logger log = + Logger.getLogger(FixingsKMChartServiceImpl.class); + + public static final String SERVICE_NAME = "fixings-km-chart"; + + public FixingsKMChartServiceImpl() { + } + + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + + log.info("FixingsKMChartServiceImpl.doGet"); + + String url = getServletContext().getInitParameter("server-url"); + String locale = req.getParameter("locale"); + String filter = req.getParameter("filter"); + + if (filter == null || filter.length() == 0) { + log.warn("Missing 'filter' parameter."); + return; + } + + if (locale == null || locale.length() == 0) { + locale = "de"; + } + + Document filterDoc = XMLUtils.jsonToXML(filter); + + if (filterDoc == null) { + log.warn("Creating filter document failed."); + return; + } + + HttpClient client; + + client = new HttpClientImpl(url, locale); + + resp.setHeader("Content-Type", guessMIMEType(filterDoc)); + + InputStream in; + + try { + in = (InputStream)client.callService( + url, // XXX: Why? The URL is passed by construction already. + SERVICE_NAME, + filterDoc, + new StreamResponseHandler()); + } + catch (ConnectionException ce) { + log.error(ce); + return; + } + + try { + OutputStream out = resp.getOutputStream(); + + byte [] buf = new byte[4096]; + int i = -1; + while ((i = in.read(buf)) >= 0) { + out.write(buf, 0, i); + } + out.flush(); + } + catch (IOException ioe) { + log.error(ioe); + } + finally { + try { in.close(); } + catch (IOException ioe) { /* ignored */ } + } + } + + protected static String guessMIMEType(Document document) { + + NodeList formats = document.getElementsByTagName("format"); + + String format = "png"; + + if (formats.getLength() > 0) { + String type = ((Element)formats.item(0)).getAttribute("type"); + if (type.length() > 0) { + format = type; + } + } + + return "image/" + format; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml Wed Apr 18 11:42:18 2012 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Thu Apr 19 11:00:18 2012 +0000 @@ -244,6 +244,16 @@ </servlet-mapping> <servlet> + <servlet-name>FixingsKMChartService</servlet-name> + <servlet-class>de.intevation.flys.client.server.FixingsKMChartServiceImpl</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>FixingsKMChartService</servlet-name> + <url-pattern>/flys/fixings-km-chart</url-pattern> + </servlet-mapping> + + <servlet> <servlet-name>DistanceInfoXML</servlet-name> <servlet-class>de.intevation.flys.client.server.DistanceInfoXML</servlet-class> </servlet>