Mercurial > dive4elements > river
changeset 5720:aa1a43f5c03a
Send errors as plaintext and not as pdf documents
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 15 Apr 2013 18:32:37 +0200 |
parents | e8b4c69967e2 |
children | 280093510e1d |
files | flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java |
diffstat | 1 files changed, 15 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java Mon Apr 15 18:27:37 2013 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java Mon Apr 15 18:32:37 2013 +0200 @@ -427,10 +427,22 @@ try { byte [] buf = new byte[4096]; int r; - resp.setHeader("Content-Disposition", - "attachment;filename=flys-karte.pdf"); - resp.setContentType("application/pdf"); + boolean checkedErrors = false; while ((r = in.read(buf)) >= 0) { + if (!checkedErrors) { + checkedErrors = true; + String header = new String(buf, "UTF-8"); + if (header.contains("Error while generating PDF:")) { + resp.setContentType("text/plain"); + } else { + // Only send content disposition and filename content + // type when we have a pdf + resp.setHeader("Content-Disposition", + "attachment;filename=flys-karte.pdf"); + resp.setContentType("application/pdf"); + } + + } out.write(buf, 0, r); } out.flush();