# HG changeset patch # User Ingo Weinzierl # Date 1291022401 0 # Node ID 2996395e44c989348d62ff46813decc7938bde79 # Parent b45faa9315ce4e19ace0e246d1e25884a4fa15b8 Improved the logging of incoming mapviewer call data. gnv/trunk@1279 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b45faa9315ce -r 2996395e44c9 gnv/ChangeLog --- a/gnv/ChangeLog Fri Nov 26 10:48:30 2010 +0000 +++ b/gnv/ChangeLog Mon Nov 29 09:20:01 2010 +0000 @@ -1,3 +1,13 @@ +2010-11-29 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/util/CaptureInputStream.java: New. This + class makes it possible to capture incoming data (InputStream) in a proper + way. + + * src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java: + Improved the mechanism to print the incoming data to log by using the + CaptureInputStream class. + 2010-11-26 Ingo Weinzierl ISSUE #323 diff -r b45faa9315ce -r 2996395e44c9 gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java --- a/gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java Fri Nov 26 10:48:30 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java Mon Nov 29 09:20:01 2010 +0000 @@ -31,6 +31,7 @@ import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; import de.intevation.gnv.artifactdatabase.objects.map.MapService; +import de.intevation.gnv.util.CaptureInputStream; /** * This class provides the businesslogic for handling an @@ -73,21 +74,19 @@ } if (inputStream != null){ - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] b = new byte[4096]; - int i = -1; - while ((i = inputStream.read(b)) > 0) { - out.write(b, 0, i); - } - out.close(); - inputStream.reset(); - - log.debug("REQUEST DOCUMENT: " + out.toString()); + CaptureInputStream capture = log.isDebugEnabled() + ? new CaptureInputStream(inputStream) + : null; try { - ExternalCallParser ecp = new XMLExternalCallParser(inputStream); + ExternalCallParser ecp = new XMLExternalCallParser(capture); ecp.parse(); + + // print incoming data to log + if (capture != null) { + log.debug("REQUEST DOCUMENT: " + capture.copyToString()); + } + String geometry = ecp.getGeometry(); String srs = ecp.getSRS(); Collection mapServices = ecp.getMapServices(); diff -r b45faa9315ce -r 2996395e44c9 gnv/src/main/java/de/intevation/gnv/util/CaptureInputStream.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/util/CaptureInputStream.java Mon Nov 29 09:20:01 2010 +0000 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2010 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ + +package de.intevation.gnv.util; + +import java.io.FilterInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +/** + * @author Sascha Teichmann + */ +public class CaptureInputStream +extends FilterInputStream +{ + protected ByteArrayOutputStream copy; + + public CaptureInputStream(InputStream in) { + super(in); + copy = new ByteArrayOutputStream(10*1024); + } + + public int read() throws IOException { + int x = in.read(); + if (x != -1) { + copy.write(x); + } + return x; + } + + public int read(byte [] b, int off, int len) throws IOException { + int r = in.read(b, off, len); + if (r > 0) { + copy.write(b, off, r); + } + return r; + } + + public long skip(long n) throws IOException { + long m = in.skip(n); + for (long i = m; i > 0L; --i) { // simulate gab + copy.write(0); + } + return m; + } + + public String copyToString() { + return copy.toString(); + } + + public String copyToString(String charsetName) + throws UnsupportedEncodingException + { + return copy.toString(charsetName); + } + + public byte [] toByteArray() { + return copy.toByteArray(); + } + + public void clear() { + copy.reset(); + } +}