response.setStatus(404);
request.setHandled(true);
response.setReason("Not Found");
response.setContentType(HttpFields.__TextHtml);
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500);
String uri=request.getPath();
uri=StringUtil.replace(uri,"<","<");
uri=StringUtil.replace(uri,">",">");
writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found");
writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n");
writer.write("No context on this server matched or handled this request.<BR>");
writer.write("Contexts known to this server are: <ul>");
HttpContext[] contexts = getHttpContext().getHttpServer().getContexts();
for (int i=0;i<contexts.length;i++)
{
HttpContext context = contexts[i];
writer.write("<li><a href=\"");
writer.write(context.getContextPath());
writer.write("/\">");
writer.write(context.toString());
writer.write("</a></li>\n");
}
writer.write("</ul><small><I>The links above may not work if a virtual host is configured</I></small>");
for (int i=0;i<10;i++)
writer.write("\n<!-- Padding for IE -->");
writer.write("\n</BODY>\n</HTML>\n");
writer.flush();
response.setContentLength(writer.size());
OutputStream out=response.getOutputStream();
writer.writeTo(out);
out.close();
}