# HG changeset patch # User Sascha L. Teichmann # Date 1336989124 0 # Node ID 427df4e81af0ea4010ea69eef92031a8180d4767 # Parent b3bf9e5ce9e6d44daae4ec0374b9c0bb710241dd Call MapFish Printer via servlet to evade viral GPLv3. flys-client/trunk@4398 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b3bf9e5ce9e6 -r 427df4e81af0 flys-client/ChangeLog --- a/flys-client/ChangeLog Sun May 13 18:29:22 2012 +0000 +++ b/flys-client/ChangeLog Mon May 14 09:52:04 2012 +0000 @@ -1,3 +1,15 @@ +2012-05-10 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java: + Call MapFish print via Apache Commons Http Client to re-establish + LGPL conformance. + + * src/main/webapp/WEB-INF/web.xml: Configured the MapFish Print servlet + again. You need to adjust the init parameter 'print-url' of the + servlet MapPrintService to point to the MapFish Print servlet. + + * pom.xml: Added dependency to Apache Commons Http Client 3.1 + 2012-05-13 Felix Wolfsteller * src/main/java/de/intevation/flys/client/client/FLYSConstants.java, diff -r b3bf9e5ce9e6 -r 427df4e81af0 flys-client/pom.xml --- a/flys-client/pom.xml Sun May 13 18:29:22 2012 +0000 +++ b/flys-client/pom.xml Mon May 14 09:52:04 2012 +0000 @@ -85,6 +85,11 @@ 0.6 + commons-httpclient + commons-httpclient + 3.1 + + log4j log4j 1.2.14 diff -r b3bf9e5ce9e6 -r 427df4e81af0 flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java Sun May 13 18:29:22 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java Mon May 14 09:52:04 2012 +0000 @@ -17,14 +17,19 @@ import de.intevation.flys.client.shared.model.MapConfig; import de.intevation.flys.client.shared.MapUtils; +/* import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +*/ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; @@ -38,14 +43,19 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; + +import org.apache.commons.httpclient.methods.GetMethod; + import org.apache.log4j.Logger; +/* Used by direct API call. -> Enforce GPLv3 import org.mapfish.print.MapPrinter; - import org.mapfish.print.output.OutputFactory; import org.mapfish.print.output.OutputFormat; import org.mapfish.print.utils.PJsonObject; +*/ import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -336,6 +346,58 @@ return url; } + private static final String encode(String s) { + try { + return URLEncoder.encode(s, "UTF-8"); + } + catch (UnsupportedEncodingException usee) { + // Should not happen. + return s; + } + } + + protected void producePDF(String json, HttpServletResponse resp) + throws ServletException, IOException + { + String printUrl = getInitParameter("print-url"); + + if (printUrl == null) { + throw new ServletException("Missing 'print-url' in web.xml"); + } + + String url = printUrl + "/print.pdf?spec=" + encode(json); + + org.apache.commons.httpclient.HttpClient client = + new org.apache.commons.httpclient.HttpClient( + new MultiThreadedHttpConnectionManager()); + + GetMethod get = new GetMethod(url); + int result = client.executeMethod(get); + InputStream in = get.getResponseBodyAsStream(); + + if (in != null) { + try { + OutputStream out = resp.getOutputStream(); + try { + byte [] buf = new byte[4096]; + int r; + while ((r = in.read(buf)) >= 0) { + out.write(buf, 0, r); + } + out.flush(); + } + finally { + out.close(); + } + } + finally { + in.close(); + } + } + } + + /* Use this if you want directly call the MapPrinter. Enforces GPLv3! + protected MapPrinter getMapPrinter() throws ServletException, IOException { String configPath = getInitParameter("config"); if (configPath == null) { @@ -354,7 +416,6 @@ return new MapPrinter(configFile); } - protected void producePDF(String json, HttpServletResponse resp) throws ServletException, IOException { @@ -411,5 +472,6 @@ } } } + */ } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r b3bf9e5ce9e6 -r 427df4e81af0 flys-client/src/main/webapp/WEB-INF/web.xml --- a/flys-client/src/main/webapp/WEB-INF/web.xml Sun May 13 18:29:22 2012 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Mon May 14 09:52:04 2012 +0000 @@ -254,6 +254,20 @@ /flys/map + + mapfish.print + org.mapfish.print.servlet.MapPrinterServlet + + config + WEB-INF/config.yaml + + + + + mapfish.print + /flys/mapfish-print/* + + MapPrintService @@ -262,6 +276,10 @@ config WEB-INF/config.yaml + + print-url + http://localhost:8888/flys/mapfish-print +