[logback-dev] svn commit: r1323 - in logback/trunk/logback-access/src/main/java/ch/qos/logback/access: pattern servlet
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Mon Feb 19 15:32:29 CET 2007
Author: ceki
Date: Mon Feb 19 15:32:29 2007
New Revision: 1323
Modified:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/FullResponseConverter.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeHttpServletResponse.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeServletOutputStream.java
Log:
Minor fixes
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/FullResponseConverter.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/FullResponseConverter.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/FullResponseConverter.java Mon Feb 19 15:32:29 2007
@@ -12,8 +12,10 @@
StringBuffer buf = new StringBuffer();
buf.append("HTTP/1.1 ");
- buf.append(ae.getStatusCode());
- buf.append(" DO_FIXME");
+ int statusCode = ae.getStatusCode();
+ buf.append(statusCode);
+ buf.append(" ");
+ buf.append(getStatusCodeDescription(statusCode));
buf.append(Layout.LINE_SEP);
List<String> hnList = ae.getResponseHeaderNameList();
@@ -29,4 +31,48 @@
return buf.toString();
}
+ static String getStatusCodeDescription(int sc) {
+ switch(sc) {
+ case 200: return "OK";
+ case 201: return "Created";
+ case 202: return "Accepted";
+ case 203: return "Non-Authoritative Information";
+ case 204: return "No Content";
+ case 205: return "Reset Content";
+ case 206: return "Partial Content";
+ case 300: return "Multiple Choices";
+ case 301: return "Moved Permanently";
+ case 302: return "Found";
+ case 303: return "See Other";
+ case 304: return "Not Modified";
+ case 305: return "Use Proxy";
+ case 306: return "(Unused)";
+ case 307: return "Temporary Redirect";
+ case 400: return "Bad Request";
+ case 401: return "Unauthorized";
+ case 402: return "Payment Required";
+ case 403: return "Forbidden";
+ case 404: return "Not Found";
+ case 405: return "Method Not Allowed";
+ case 406: return "Not Acceptable";
+ case 407: return "Proxy Authentication Required";
+ case 408: return "Request Timeout";
+ case 409: return "Conflict";
+ case 410: return "Gone";
+ case 411: return "Length Required";
+ case 412: return "Precondition Failed";
+ case 413: return "Request Entity Too Large";
+ case 414: return "Request-URI Too Long";
+ case 415: return "Unsupported Media Type";
+ case 416: return "Requested Range Not Satisfiable";
+ case 417: return "Expectation Failed";
+ case 500: return "Internal Server Error";
+ case 501: return "Not Implemented";
+ case 502: return "Bad Gateway";
+ case 503: return "Service Unavailable";
+ case 504: return "Gateway Timeout";
+ case 505: return "HTTP Version Not Supported";
+ default: return "NA";
+ }
+ }
}
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeHttpServletResponse.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeHttpServletResponse.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeHttpServletResponse.java Mon Feb 19 15:32:29 2007
@@ -15,44 +15,47 @@
public TeeHttpServletResponse(HttpServletResponse httpServletResponse) {
super(httpServletResponse);
- //System.out.println("TeeHttpServletResponse.constructor called");
+ // System.out.println("TeeHttpServletResponse.constructor called");
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
- //System.out.println("TeeHttpServletResponse.getOutputStream() called");
- if(teeServletOutputStream == null) {
- teeServletOutputStream = new TeeServletOutputStream(
- this.getResponse());
+ if (teeServletOutputStream == null) {
+ teeServletOutputStream = new TeeServletOutputStream(this.getResponse());
}
return teeServletOutputStream;
}
@Override
public PrintWriter getWriter() throws IOException {
- //System.out.println("TeeHttpServletResponse.getWriter() called");
+ // System.out.println("TeeHttpServletResponse.getWriter() called");
if (this.writer == null) {
- this.writer = new PrintWriter(new OutputStreamWriter(getOutputStream()), true);
+ this.writer = new PrintWriter(new OutputStreamWriter(getOutputStream()),
+ true);
}
return this.writer;
}
@Override
public void flushBuffer() {
- //System.out.println("TeeHttpServletResponse.flushBuffer() called");
+ // System.out.println("TeeHttpServletResponse.flushBuffer() called");
this.writer.flush();
}
-
+
byte[] getOutputBuffer() {
- return teeServletOutputStream.getOutputBuffer();
+ // teeServletOutputStream can be null if the getOutputStream method is never called.
+ if (teeServletOutputStream != null) {
+ return teeServletOutputStream.getOutputBuffer();
+ } else {
+ return null;
+ }
}
-
-
- void finish() throws IOException {
- if(this.writer != null) {
+
+ void finish() throws IOException {
+ if (this.writer != null) {
this.writer.close();
}
- if(this.teeServletOutputStream != null) {
+ if (this.teeServletOutputStream != null) {
this.teeServletOutputStream.close();
}
}
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeServletOutputStream.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeServletOutputStream.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeServletOutputStream.java Mon Feb 19 15:32:29 2007
@@ -11,60 +11,77 @@
final ServletOutputStream underlyingStream;
final ByteArrayOutputStream baos;
-
- TeeServletOutputStream(ServletResponse httpServletResponse) throws IOException {
- //System.out.println("TeeServletOutputStream.constructor() called");
+ TeeServletOutputStream(ServletResponse httpServletResponse)
+ throws IOException {
+ // System.out.println("TeeServletOutputStream.constructor() called");
this.underlyingStream = httpServletResponse.getOutputStream();
+ if (underlyingStream == null) {
+ System.out.println("XXXXX underlyingStream == null");
+ } else {
+ System.out.println("XXXXX underlyingStream != null");
+ }
baos = new ByteArrayOutputStream();
}
byte[] getOutputBuffer() {
return baos.toByteArray();
}
-
+
@Override
public void write(int val) throws IOException {
- //System.out.println("XXXXXXXXXXXWRITE TeeServletOutputStream.write(int) called");
- underlyingStream.write(val);
- baos.write(val);
+ // System.out.println("XXXXXXXXXXXWRITE TeeServletOutputStream.write(int)
+ // called");
+ if (underlyingStream != null) {
+ underlyingStream.write(val);
+ baos.write(val);
+ }
}
@Override
public void write(byte[] byteArray) throws IOException {
- //System.out.println("WRITE TeeServletOutputStream.write(byte[]) called");
+ if (underlyingStream == null) {
+ return;
+ }
+ // System.out.println("WRITE TeeServletOutputStream.write(byte[]) called");
write(byteArray, 0, byteArray.length);
}
@Override
public void write(byte byteArray[], int offset, int length)
throws IOException {
- //System.out.println("WRITE TeeServletOutputStream.write(byte[], int, int) called");
- //System.out.println(new String(byteArray, offset, length));
+ if (underlyingStream == null) {
+ return;
+ }
+ // System.out.println("WRITE TeeServletOutputStream.write(byte[], int, int)
+ // called");
+ // System.out.println(new String(byteArray, offset, length));
underlyingStream.write(byteArray, offset, length);
baos.write(byteArray, offset, length);
}
public void close() throws IOException {
- // System.out.println("CLOSE TeeServletOutputStream.close() called");
-
- // If the servlet accessing the stream is using a writer instead of
+ // System.out.println("CLOSE TeeServletOutputStream.close() called");
+
+ // If the servlet accessing the stream is using a writer instead of
// an OutputStream, it will probably call os.close() begore calling
// writer.close. Thus, the undelying output stream will be called
// before the data sent to the writer could be flushed.
}
public void finish() throws IOException {
- //System.out.println("FINISH TeeServletOutputStream.close() called");
+ // System.out.println("FINISH TeeServletOutputStream.close() called");
flush();
underlyingStream.close();
baos.close();
}
public void flush() throws IOException {
- //System.out.println("FLUSH TeeServletOutputStream.flush() called");
+ if (underlyingStream == null) {
+ return;
+ }
+ // System.out.println("FLUSH TeeServletOutputStream.flush() called");
underlyingStream.flush();
baos.flush();
}
-
}
More information about the logback-dev
mailing list