Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/server/BedKMChartServiceImpl.java @ 5622:b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Data properties are identified by starting with mapfish-data
and they are then split in info value pairs where info
can be the description of the information and value the value
of the information to be transported in the data map.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 09 Apr 2013 19:04:32 +0200 |
parents | f84ed73311f2 |
children |
line wrap: on
line source
package de.intevation.flys.client.server; 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; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.httpclient.exceptions.ConnectionException; import de.intevation.artifacts.httpclient.http.HttpClient; import de.intevation.artifacts.httpclient.http.HttpClientImpl; import de.intevation.artifacts.httpclient.http.response.StreamResponseHandler; public class BedKMChartServiceImpl extends HttpServlet { private static final Logger log = Logger.getLogger(FixingsKMChartServiceImpl.class); public static final String SERVICE_NAME = "bed-km-chart"; public BedKMChartServiceImpl() { } public void doGet(HttpServletRequest req, HttpServletResponse resp) { log.info("BedKMChartServiceImpl.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; } InputStream in; try { HttpClient client = new HttpClientImpl(url, locale); 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; } resp.setHeader("Content-Type", guessMIMEType(filterDoc)); 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; } }