changeset 7486:6b278187ed9d

Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 31 Oct 2013 19:03:57 +0100
parents 47905b570eaf
children e327492ba9d0
files gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java
diffstat 2 files changed, 20 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java	Thu Oct 31 18:34:10 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java	Thu Oct 31 19:03:57 2013 +0100
@@ -55,7 +55,6 @@
             String uuid     = req.getParameter("uuid");
             String type     = req.getParameter("type");
             String locale   = req.getParameter("locale");
-            String encoding = req.getParameter("encoding");
 
             prepareHeader(req, resp);
 
@@ -65,15 +64,6 @@
 
             HttpClient client = new HttpClientImpl(url, locale);
 
-            if (encoding != null) {
-                try {
-                client.setOutEncoding(
-                    java.nio.charset.Charset.forName(encoding));
-                }
-                catch(java.nio.charset.UnsupportedCharsetException e) {
-                    logger.warn("Unsupported encoding: " + encoding);
-                }
-            }
             client.collectionOut(request, uuid, "chart", out);
 
             out.close();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java	Thu Oct 31 18:34:10 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java	Thu Oct 31 19:03:57 2013 +0100
@@ -8,8 +8,10 @@
 
 package org.dive4elements.river.client.server;
 
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -45,7 +47,7 @@
         logger.info("ExportServiceImpl.doGet");
 
         try {
-            OutputStream out = resp.getOutputStream();
+            final OutputStream out = resp.getOutputStream();
 
             String url    = getServletContext().getInitParameter("server-url");
             String uuid   = req.getParameter("uuid");
@@ -55,7 +57,7 @@
             String locale = req.getParameter("locale");
             String km     = req.getParameter("km");
             String fn     = name + "." + type;
-            String enc    = req.getParameter("encoding");
+            final String enc = req.getParameter("encoding");
 
             resp.setHeader("Content-Disposition", "attachment;filename=" + fn);
 
@@ -76,21 +78,27 @@
                 uuid, mode, type, attr);
             HttpClient client = new HttpClientImpl(url, locale);
 
-            // Set out encoding if specified.
             if (enc != null) {
+                InputStreamReader in = new InputStreamReader(
+                    client.collectionOut(request, uuid, mode),
+                    "UTF-8");
                 try {
-                client.setOutEncoding(
-                    java.nio.charset.Charset.forName(enc));
+                    OutputStreamWriter encOut = new OutputStreamWriter(out, enc);
+                    char buf [] = new char[4096];
+                    int c;
+                    while ((c = in.read(buf, 0, buf.length)) >= 0) {
+                        encOut.write(buf, 0, c);
+                    }
+                    out.flush();
                 }
-                catch(java.nio.charset.UnsupportedCharsetException e) {
-                    logger.warn("Unsupported encoding: " + enc);
+                finally {
+                    in.close();
                 }
             }
-
-            client.collectionOut(request, uuid, mode, out);
-
-            out.close();
-            out.flush();
+            else { // Just copy thru.
+                client.collectionOut(request, uuid, mode, out);
+                out.flush();
+            }
         }
         catch (IOException ioe) {
             logger.error(ioe, ioe);

http://dive4elements.wald.intevation.org