Index: src/main/java/ch/qos/logback/access/spi/AccessEvent.java =================================================================== --- src/main/java/ch/qos/logback/access/spi/AccessEvent.java (revision 1613) +++ src/main/java/ch/qos/logback/access/spi/AccessEvent.java (working copy) @@ -1,21 +1,15 @@ package ch.qos.logback.access.spi; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; +import ch.qos.logback.access.Constants; +import ch.qos.logback.access.pattern.AccessConverter; +import ch.qos.logback.access.servlet.Util; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.*; -import ch.qos.logback.access.Constants; -import ch.qos.logback.access.pattern.AccessConverter; -import ch.qos.logback.access.servlet.Util; - // Contributors: Joern Huxhorn (see also bug #110) /** @@ -29,7 +23,7 @@ */ public class AccessEvent implements Serializable { - private static final long serialVersionUID = -3118194368414470960L; + private static final long serialVersionUID = 866718993618836343L; public final static String NA = "-"; public final static String[] NA_STRING_ARRAY = new String[] { AccessEvent.NA }; @@ -68,7 +62,7 @@ private long timeStamp = 0; public AccessEvent(HttpServletRequest httpRequest, - HttpServletResponse httpResponse, ServerAdapter adapter) { + HttpServletResponse httpResponse, ServerAdapter adapter) { this.httpRequest = httpRequest; this.httpResponse = httpResponse; this.timeStamp = System.currentTimeMillis(); @@ -339,47 +333,49 @@ return requestContent; } - if (Util.isFormUrlEncoded(httpRequest)) { - StringBuffer buf = new StringBuffer(); + if (httpRequest != null) { + if (Util.isFormUrlEncoded(httpRequest)) { + StringBuffer buf = new StringBuffer(); - Enumeration pramEnumeration = httpRequest.getParameterNames(); + Enumeration pramEnumeration = httpRequest.getParameterNames(); - // example: id=1234&user=cgu - // number=1233&x=1 - int count = 0; - try { - while (pramEnumeration.hasMoreElements()) { + // example: id=1234&user=cgu + // number=1233&x=1 + int count = 0; + try { + while (pramEnumeration.hasMoreElements()) { - String key = (String) pramEnumeration.nextElement(); - if (count++ != 0) { - buf.append("&"); + String key = (String) pramEnumeration.nextElement(); + if (count++ != 0) { + buf.append("&"); + } + buf.append(key); + buf.append("="); + String val = httpRequest.getParameter(key); + if (val != null) { + buf.append(val); + } else { + buf.append(""); + } } - buf.append(key); - buf.append("="); - String val = httpRequest.getParameter(key); - if (val != null) { - buf.append(val); - } else { - buf.append(""); - } + } catch (Exception e) { + // FIXME Why is try/catch required? + e.printStackTrace(); } - } catch (Exception e) { - // FIXME Why is try/catch required? - e.printStackTrace(); - } - requestContent = buf.toString(); - } else { + requestContent = buf.toString(); + } else { - // retreive the byte array placed by TeeFilter - byte[] inputBuffer = (byte[]) httpRequest - .getAttribute(Constants.LB_INPUT_BUFFER); + // retreive the byte array placed by TeeFilter + byte[] inputBuffer = (byte[]) httpRequest + .getAttribute(Constants.LB_INPUT_BUFFER); - if (inputBuffer != null) { - requestContent = new String(inputBuffer); - } + if (inputBuffer != null) { + requestContent = new String(inputBuffer); + } - if (requestContent == null || requestContent.length() == 0) { - requestContent = EMPTY; + if (requestContent == null || requestContent.length() == 0) { + requestContent = EMPTY; + } } } @@ -391,22 +387,23 @@ return responseContent; } - if (Util.isImageResponse(httpResponse)) { - responseContent = "[IMAGE CONTENTS SUPPRESSED]"; - } else { + if(httpResponse != null) { + if (Util.isImageResponse(httpResponse)) { + responseContent = "[IMAGE CONTENTS SUPPRESSED]"; + } else { - // retreive the byte array previously placed by TeeFilter - byte[] outputBuffer = (byte[]) httpRequest - .getAttribute(Constants.LB_OUTPUT_BUFFER); + // retreive the byte array previously placed by TeeFilter + byte[] outputBuffer = (byte[]) httpRequest + .getAttribute(Constants.LB_OUTPUT_BUFFER); - if (outputBuffer != null) { - responseContent = new String(outputBuffer); + if (outputBuffer != null) { + responseContent = new String(outputBuffer); + } + if (responseContent == null || responseContent.length() == 0) { + responseContent = EMPTY; + } } - if (responseContent == null || responseContent.length() == 0) { - responseContent = EMPTY; - } } - return responseContent; }