Mercurial > dive4elements > river
changeset 3498:92239b53823f
ProxyServlet: Use block instead of byte wise copy.
flys-client/trunk@5222 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 16 Aug 2012 16:38:21 +0000 |
parents | 88feb3347aa5 |
children | 17c66d38f095 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/ProxyServlet.java |
diffstat | 2 files changed, 32 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Thu Aug 16 14:42:36 2012 +0000 +++ b/flys-client/ChangeLog Thu Aug 16 16:38:21 2012 +0000 @@ -1,3 +1,9 @@ +2012-08-16 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/client/server/ProxyServlet.java: + Shortend lines to 80 chars. Made debug outout conditional. + Use block copy instead of tight byte wise loop. + 2012-08-16 Björn Ricks <bjoern.ricks@intevation.de> * src/main/java/de/intevation/flys/client/server/ProxyServlet.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ProxyServlet.java Thu Aug 16 14:42:36 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ProxyServlet.java Thu Aug 16 16:38:21 2012 +0000 @@ -1,6 +1,5 @@ package de.intevation.flys.client.server; -import java.io.BufferedInputStream; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; @@ -43,7 +42,8 @@ } @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { HttpClient httpclient = new DefaultHttpClient(); String requesturi = req.getRequestURI(); @@ -51,11 +51,16 @@ HttpGet httpget = new HttpGet(this.remoteurl + "?" + query); + boolean debug = logger.isDebugEnabled(); + for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) { String name = (String)e.nextElement(); for (Enumeration f = req.getHeaders(name); f.hasMoreElements();) { String value = (String)f.nextElement(); - logger.debug("Adding request header " + name + " : " + value); + if (debug) { + logger.debug( + "Adding request header " + name + " : " + value); + } httpget.addHeader(name, value); } } @@ -63,26 +68,37 @@ HttpResponse response = httpclient.execute(httpget); StatusLine statusline = response.getStatusLine(); - logger.debug("Response statuscode " + statusline.getStatusCode()); + if (debug) { + logger.debug("Response statuscode " + statusline.getStatusCode()); + } resp.setStatus(statusline.getStatusCode()); Header[] headers = response.getAllHeaders(); for(Header header : headers) { - logger.debug("Adding response header " + header.getName() + " : " + header.getValue()); + if (debug) { + logger.debug( + "Adding response header " + header.getName() + + " : " + header.getValue()); + } resp.setHeader(header.getName(), header.getValue()); } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); - BufferedInputStream binstream = new BufferedInputStream(instream); + byte [] buf = new byte[4096]; try { OutputStream outstream = resp.getOutputStream(); - int read; - while ( ( read = binstream.read() ) != -1 ) { - outstream.write(read); + try { + int read; + while ((read = instream.read(buf)) >= 0) { + outstream.write(buf, 0, read); + } + outstream.flush(); } - outstream.close(); + finally { + outstream.close(); + } } finally { instream.close();