001: /*
002: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.lib.http;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.lib.aSocket.*;
029: import seda.sandStorm.core.*;
030:
031: import java.util.*;
032: import java.io.*;
033: import java.net.*;
034:
035: /**
036: * An httpResponse corresponding to a '500 Internal Server Error'
037: * Use httpNotFoundResponse for a '404 Not Found'.
038: *
039: * @author Matt Welsh
040: * @see httpNotFoundResponse
041: *
042: */
043: public class httpInternalServerErrorResponse extends httpResponse
044: implements httpConst, QueueElementIF {
045:
046: private static final boolean DEBUG = false;
047:
048: public httpInternalServerErrorResponse(httpRequest request,
049: String reason) {
050: super (httpResponse.RESPONSE_INTERNAL_SERVER_ERROR, "text/html");
051:
052: String str = "<html><head><title>500 Internal Server Error</title></head>"
053: + "<body bgcolor=white><font face=\"helvetica\"><big><big>"
054: + "<b>500 Internal Server Error</b></big></big>"
055: + "<p>The URL you requested:<p><blockquote><tt>"
056: + request.getURL()
057: + "</tt></blockquote>"
058: + "<p>generated an internal server error. "
059: + "The reason given by the server was:"
060: + "<p><blockquote><tt>"
061: + reason
062: + "</tt></blockquote></body></html>\n";
063: BufferElement mypayload = new BufferElement(str.getBytes());
064: setPayload(mypayload);
065: }
066:
067: public httpInternalServerErrorResponse(httpRequest request,
068: Exception e) {
069:
070: super (httpResponse.RESPONSE_INTERNAL_SERVER_ERROR, "text/html");
071:
072: StringBuffer buf = new StringBuffer();
073:
074: buf
075: .append("<html><head><title>500 Internal Server Error</title></head>");
076: buf
077: .append("<body bgcolor=white><font face=\"helvetica\"><big><big>");
078: buf.append("<b>500 Internal Server Error</b></big></big>");
079: buf.append("<p>The URL you requested:<p><blockquote><tt>"
080: + request.getURL() + "</tt></blockquote>");
081: buf.append("<p>generated an internal server error. ");
082: buf.append("The reason given by the server was:");
083: buf
084: .append("<p><blockquote><tt>The following exception occurred:<p><pre>"
085: + e + "</pre></tt></blockquote>");
086:
087: StackTraceElement[] ste_list = e.getStackTrace();
088:
089: buf.append("<br><br>");
090: for (int i = 0; i < ste_list.length; i++) {
091: StackTraceElement ste = ste_list[i];
092: buf.append(ste.toString() + "<br>");
093: }
094:
095: buf.append("</body></html>\n");
096:
097: BufferElement mypayload = new BufferElement(buf.toString()
098: .getBytes());
099: setPayload(mypayload);
100: }
101:
102: public httpInternalServerErrorResponse(httpRequest request,
103: Exception e, String loc) {
104:
105: super (httpResponse.RESPONSE_INTERNAL_SERVER_ERROR, "text/html");
106:
107: StringBuffer buf = new StringBuffer();
108:
109: buf
110: .append("<html><head><title>500 Internal Server Error</title></head>");
111: buf
112: .append("<body bgcolor=white><font face=\"helvetica\"><big><big>");
113: buf.append("<b>500 Internal Server Error</b></big></big>");
114: buf.append("<p>The URL you requested:<p><blockquote><tt>"
115: + request.getURL() + "</tt></blockquote>");
116: buf.append("<p>generated an internal server error. ");
117: buf.append("<p>The error occured at : " + loc);
118: buf.append("<p>The reason given by the server was:");
119: buf
120: .append("<p><blockquote><tt>The following exception occurred:<p><pre>"
121: + e + "</pre></tt></blockquote>");
122:
123: StackTraceElement[] ste_list = e.getStackTrace();
124:
125: buf.append("<br><br>");
126: for (int i = 0; i < ste_list.length; i++) {
127: StackTraceElement ste = ste_list[i];
128: buf.append(ste.toString() + "<br>");
129: }
130:
131: buf.append("</body></html>\n");
132:
133: BufferElement mypayload = new BufferElement(buf.toString()
134: .getBytes());
135: setPayload(mypayload);
136: }
137:
138: protected String getEntityHeader() {
139: return null;
140: }
141: }
|