comparison gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java @ 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 6efa25f97f7e
children e469d9939a52
comparison
equal deleted inserted replaced
7485:47905b570eaf 7486:6b278187ed9d
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.client.server; 9 package org.dive4elements.river.client.server;
10 10
11 import java.io.InputStreamReader;
11 import java.io.OutputStream; 12 import java.io.OutputStream;
12 import java.io.IOException; 13 import java.io.IOException;
14 import java.io.OutputStreamWriter;
13 15
14 import org.w3c.dom.Document; 16 import org.w3c.dom.Document;
15 import org.w3c.dom.Element; 17 import org.w3c.dom.Element;
16 18
17 import org.apache.log4j.Logger; 19 import org.apache.log4j.Logger;
43 45
44 public void doGet(HttpServletRequest req, HttpServletResponse resp) { 46 public void doGet(HttpServletRequest req, HttpServletResponse resp) {
45 logger.info("ExportServiceImpl.doGet"); 47 logger.info("ExportServiceImpl.doGet");
46 48
47 try { 49 try {
48 OutputStream out = resp.getOutputStream(); 50 final OutputStream out = resp.getOutputStream();
49 51
50 String url = getServletContext().getInitParameter("server-url"); 52 String url = getServletContext().getInitParameter("server-url");
51 String uuid = req.getParameter("uuid"); 53 String uuid = req.getParameter("uuid");
52 String name = req.getParameter("name"); 54 String name = req.getParameter("name");
53 String mode = req.getParameter("mode"); 55 String mode = req.getParameter("mode");
54 String type = req.getParameter("type"); 56 String type = req.getParameter("type");
55 String locale = req.getParameter("locale"); 57 String locale = req.getParameter("locale");
56 String km = req.getParameter("km"); 58 String km = req.getParameter("km");
57 String fn = name + "." + type; 59 String fn = name + "." + type;
58 String enc = req.getParameter("encoding"); 60 final String enc = req.getParameter("encoding");
59 61
60 resp.setHeader("Content-Disposition", "attachment;filename=" + fn); 62 resp.setHeader("Content-Disposition", "attachment;filename=" + fn);
61 63
62 if (logger.isDebugEnabled()) { 64 if (logger.isDebugEnabled()) {
63 logger.debug("Request " + type + " export."); 65 logger.debug("Request " + type + " export.");
74 } 76 }
75 Document request = ClientProtocolUtils.newOutCollectionDocument( 77 Document request = ClientProtocolUtils.newOutCollectionDocument(
76 uuid, mode, type, attr); 78 uuid, mode, type, attr);
77 HttpClient client = new HttpClientImpl(url, locale); 79 HttpClient client = new HttpClientImpl(url, locale);
78 80
79 // Set out encoding if specified.
80 if (enc != null) { 81 if (enc != null) {
82 InputStreamReader in = new InputStreamReader(
83 client.collectionOut(request, uuid, mode),
84 "UTF-8");
81 try { 85 try {
82 client.setOutEncoding( 86 OutputStreamWriter encOut = new OutputStreamWriter(out, enc);
83 java.nio.charset.Charset.forName(enc)); 87 char buf [] = new char[4096];
88 int c;
89 while ((c = in.read(buf, 0, buf.length)) >= 0) {
90 encOut.write(buf, 0, c);
91 }
92 out.flush();
84 } 93 }
85 catch(java.nio.charset.UnsupportedCharsetException e) { 94 finally {
86 logger.warn("Unsupported encoding: " + enc); 95 in.close();
87 } 96 }
88 } 97 }
89 98 else { // Just copy thru.
90 client.collectionOut(request, uuid, mode, out); 99 client.collectionOut(request, uuid, mode, out);
91 100 out.flush();
92 out.close(); 101 }
93 out.flush();
94 } 102 }
95 catch (IOException ioe) { 103 catch (IOException ioe) {
96 logger.error(ioe, ioe); 104 logger.error(ioe, ioe);
97 } 105 }
98 } 106 }

http://dive4elements.wald.intevation.org