[PATCH] Removed charset encoding on outs. They are mainly binary data which simply should be proxied through
Wald Commits
scm-commit at wald.intevation.org
Thu Oct 31 19:04:11 CET 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1383242637 -3600
# Node ID 6b278187ed9d8c034086c0ac9ab77ef51c34ea45
# Parent 47905b570eaf84e290df2dccd4482b38c07b9f19
Removed charset encoding on outs. They are mainly binary data which simply should be proxied through.
diff -r 47905b570eaf -r 6b278187ed9d gwt-client/src/main/java/org/dive4elements/river/client/server/ChartOutputServiceImpl.java
--- 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();
diff -r 47905b570eaf -r 6b278187ed9d gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java
--- 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);
More information about the Dive4elements-commits
mailing list