Method from org.apache.openejb.webadmin.httpd.HttpResponseImpl Detail: |
protected static HttpResponseImpl createError(String message) {
return createError(message, null);
}
This could be improved at some day in the future
to also include a stack trace of the exceptions |
protected static HttpResponseImpl createError(String message,
Throwable t) {
HttpResponseImpl res = new HttpResponseImpl(500, "Internal Server Error", "text/html");
java.io.PrintWriter body = res.getPrintWriter();
body.println("< html >");
body.println("< body >");
body.println("< h3 >Internal Server Error< /h3 >");
body.println("< br >< br >");
if (message != null) {
StringTokenizer msg = new StringTokenizer(message, "\n\r");
while (msg.hasMoreTokens()) {
body.print( msg.nextToken() );
body.println("< br >");
}
}
if (t != null) {
try{
body.println("< br >< br >");
body.println("Stack Trace:< br >");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter( baos );
t.printStackTrace(writer);
writer.flush();
writer.close();
message = new String(baos.toByteArray());
StringTokenizer msg = new StringTokenizer(message, "\n\r");
while (msg.hasMoreTokens()) {
body.print( msg.nextToken() );
body.println("< br >");
}
} catch (Exception e){
}
}
body.println("< /body >");
body.println("< /html >");
return res;
}
creates an error with user defined variables |
protected static HttpResponseImpl createForbidden(String ip) {
HttpResponseImpl res = new HttpResponseImpl(403, "Forbidden", "text/html");
java.io.PrintWriter body = res.getPrintWriter();
body.println("< html >");
body.println("< body >");
body.println("< h3 >Forbidden< /h3 >");
body.println("< br >< br >");
// Add more text here
// IP not allowed, etc.
body.println("IP address: " + ip + " is not registered on this server, please contact your system administrator.");
body.println("< /body >");
body.println("< /html >");
return res;
}
Creates a forbidden response to be sent to the browser using IP authentication |
public int getCode() {
return code;
}
gets the HTTP response code |
public String getContentType() {
return getHeader("Content-Type");
}
gets the content type that will be sent to the browser |
public String getHeader(String name) {
return (String) headers.get(name);
}
Gets a header based on the name passed in |
public OutputStream getOutputStream() {
return baos;
}
gets the OutputStream to send data to the browser |
public PrintWriter getPrintWriter() {
return writer;
}
Gets the PrintWriter to send data to the browser |
public String getResponseString() {
return responseString;
}
Sets the response string to be sent to the browser |
public String getServerName() {
if (server == null) {
String version = "???";
String os = "(unknown os)";
OpenEjbVersion openejbInfo = OpenEjbVersion.get();
version = openejbInfo.getVersion();
os = System.getProperty("os.name")+"/"+System.getProperty("os.version")+" ("+System.getProperty("os.arch")+")";
server = "OpenEJB/" +version+ " "+os;
}
return server;
}
gets the name of the server being used |
public void reset() {
initBody();
}
resets the data to be sent to the browser |
public void reset(int code,
String responseString) {
setCode(code);
setResponseString(responseString);
initBody();
}
resets the data to be sent to the browser with the response code and response
string |
public void setCode(int code) {
this.code = code;
}
sets the HTTP response code to be sent to the browser. These codes are:
OPTIONS = 0
GET = 1
HEAD = 2
POST = 3
PUT = 4
DELETE = 5
TRACE = 6
CONNECT = 7
UNSUPPORTED = 8 |
public void setContent(URLConnection content) {
this.content = content;
}
|
public void setContentType(String type) {
setHeader("Content-Type", type);
}
sets the content type to be sent back to the browser |
public void setHeader(String name,
String value) {
headers.put(name, value);
}
sets a header to be sent back to the browser |
protected void setRequest(HttpRequestImpl request) {
this.request = request;
}
|
public void setResponseString(String responseString) {
this.responseString = responseString;
}
Sets the response string to be sent to the browser |
public String toString() {
StringBuffer buf = new StringBuffer(40);
buf.append(HTTP_VERSION);
buf.append(SP);
buf.append(code+"");
buf.append(SP);
buf.append(responseString);
return buf.toString();
}
Creates a string version of the response similar to:
HTTP/1.1 200 OK |
protected void writeMessage(OutputStream output) throws IOException {
DataOutput out = new DataOutputStream(output);
DataOutput log = new DataOutputStream(System.out);
//System.out.println("\nRESPONSE");
closeMessage();
//writeResponseLine(log);
// writeHeaders(log);
// writeBody(log);
writeResponseLine(out);
writeHeaders(out);
writeBody(out);
}
Takes care of sending the response line, headers and body
HTTP/1.1 200 OK
Server: Netscape-Enterprise/3.6 SP3
Date: Thu, 07 Jun 2001 17:30:42 GMT
Content-Type: text/html
Connection: close |