public ReplyInterface perform(RequestInterface ri)
throws org.w3c.tools.resources.ProtocolException,
org.w3c.tools.resources.ResourceException
{
Request request = (Request) ri;
Reply reply = null;
boolean stated = false;
// check the expectations
if (!checkExpect(request)) {
reply = createDefaultReply(request, HTTP.EXPECTATION_FAILED);
reply.setContent("The requested expectation could not be"+
" met by the resource");
return reply;
}
// Perform the request:
try {
if (request.getMaxForwards() != -1) { // 14.31 decrement the value
if (request.getMaxForwards() == 0) {
if (request.getMethod().equals("TRACE") ||
request.getMethod().equals("OPTIONS"))
return super.perform(request);
}
}
org.w3c.www.protocol.http.Request req = dupRequest(request);
org.w3c.www.protocol.http.Reply rep = null;
// Perform the request
rep = manager.runRequest(req);
// Dump back the client reply into a server reply:
reply = dupReply(request, rep);
// Update statistics:
updateStatistics(req);
stated = true;
// Trace the request (debug):
if ( getTraceRequest() ) {
// if ( req.hasState(CacheFilter.STATE_HOW) ) {
// System.out.println(request.getURL()+": "+
// CacheFilter.getHow(req));
// }
// if ( req.hasState(micp) )
// System.out.println(req.getURL()+": (icp) "+
// req.getState(micp));
}
} catch (HTTPException shex) {
// An server-side HTTP-related error happened
if (debug) {
System.out.println("HTTP Server Exception while running"
+" request:");
shex.printStackTrace();
}
// Make sure the request is accounted:
if ( ! stated ) {
synchronized(this) {
reqcount++;
reqerred++;
}
stated = true;
}
Reply r = (Reply) shex.getReply();
if (reply == null) {
// Send an appropriate error message back:
reply = request.makeReply(HTTP.BAD_GATEWAY);
boolean showerr =
props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P, false);
if (showerr) {
reply.setContent("An HTTP error occured while getting: "
+ "<p><strong>"+request.getURL()
+ "</strong>"
+ "<p>Details \""+shex.getMessage()+"\"."
+ "<hr>Generated by <i>"
+ getServer().getURL());
} else {
reply.setContent("An HTTP error occured while getting the "
+ "requested URI.</p>"
+ "<hr>Generated by <i>"
+ getServer().getURL());
}
reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
}
} catch (HttpInvalidValueException iex) {
// An server-side HTTP-related error happened
if (debug) {
System.out.println("Parsing Exception while running"
+" request:");
iex.printStackTrace();
}
// Make sure the request is accounted:
if ( ! stated ) {
synchronized(this) {
reqcount++;
reqerred++;
}
stated = true;
}
reply = request.makeReply(HTTP.BAD_GATEWAY);
boolean showerr =
props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P, false);
if (showerr) {
reply.setContent("An HTTP error occured while getting: "
+ "<p><strong>"+request.getURL()
+ "</strong>"
+ "<p>Details \""+iex.getMessage()+"\"."
+ "<hr>Generated by <i>"
+ getServer().getURL());
} else {
reply.setContent("An HTTP error occured while getting the "
+ "requested URI.</p>"
+ "<hr>Generated by <i>"
+ getServer().getURL());
}
reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
} catch (HttpException hex) {
// An HTTP-related error happened
if (debug) {
System.out.println("HTTP Exception while running request:");
hex.printStackTrace();
}
// Make sure the request is accounted:
if ( ! stated ) {
synchronized(this) {
reqcount++;
reqerred++;
}
stated = true;
}
org.w3c.www.protocol.http.Reply rep = hex.getReply();
if (rep != null) {
try {
reply = dupReply(request, rep);
} catch (IOException ioex) {
reply = null;
}
}
if (reply == null) {
// Send an appropriate error message back:
String msg = hex.getMessage();
if (msg.startsWith("Unable to contact target server ")) {
reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
} else {
reply = request.makeReply(HTTP.BAD_GATEWAY);
}
boolean showerr =
props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P, false);
if (showerr) {
reply.setContent("An HTTP error occured while getting: "
+ "<p><strong>"+request.getURL()
+ "</strong>"
+ "<p>Details \""+hex.getMessage()+"\"."
+ "<hr>Generated by <i>"
+ getServer().getURL());
} else {
reply.setContent("An HTTP error occured while getting the "
+ "requested URI.</p>"
+ "<hr>Generated by <i>"
+ getServer().getURL());
}
reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
}
} catch (Exception ex) {
// Debug trace (when debuggging):
if ( debug ) {
System.out.println("Exception while running request:");
ex.printStackTrace();
}
// Make sure the request is accounted:
if ( ! stated ) {
synchronized(this) {
reqcount++;
reqerred++;
}
stated = true;
}
// Send an appropriate error message back:
reply = request.makeReply(HTTP.GATEWAY_TIMEOUT);
boolean showerr = props.getBoolean(httpd.DISPLAY_URL_ON_ERROR_P,
false);
if (showerr) {
reply.setContent("An HTTP error occured while getting: "
+ "<p><strong>"+request.getURL()+"</strong>"
+ "<p>Details \""+ex.getMessage()+"\"."
+ "<hr>Generated by <i>"
+ getServer().getURL());
} else {
reply.setContent("An HTTP error occured while getting the "