# HG changeset patch # User Sascha L. Teichmann # Date 1345135101 0 # Node ID 92239b53823f5aa07f284e0f7e9cb1c0f1beb92b # Parent 88feb3347aa5d920d7651af71379a643c9ab0dd5 ProxyServlet: Use block instead of byte wise copy. flys-client/trunk@5222 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 88feb3347aa5 -r 92239b53823f flys-client/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/client/server/ProxyServlet.java: diff -r 88feb3347aa5 -r 92239b53823f flys-client/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();