X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Futil%2FRestarts.java;h=06ab68260d9468bf13b27007137d258074c9b301;hb=1897eace96225a1571a01031efc90a4224556c9d;hp=19536675aac529a42e1c3256aa9ee240e94e72b2;hpb=c25c3aadf42cf04fe8dbbfb60624589ba60112bd;p=jsvc.git diff --git a/src/dolda/jsvc/util/Restarts.java b/src/dolda/jsvc/util/Restarts.java index 1953667..06ab682 100644 --- a/src/dolda/jsvc/util/Restarts.java +++ b/src/dolda/jsvc/util/Restarts.java @@ -2,6 +2,7 @@ package dolda.jsvc.util; import dolda.jsvc.*; import java.net.*; +import java.io.*; public class Restarts { public static RequestRestart redirect(final URL to) { @@ -33,14 +34,53 @@ public class Restarts { public void respond(Request req) { req.status(303); URL url; - String rel = req.ctx().rootpath() + "/" + Misc.stripslashes(path, true, false); try { - url = new URL(req.url(), rel); + url = new URL(req.rooturl(), Misc.stripslashes(path, true, false)); } catch(MalformedURLException e) { - throw(new RuntimeException("Bad relative URL: + " + rel, e)); + throw(new RuntimeException("Bad relative URL: + " + path, e)); } req.outheaders().put("Location", url.toString()); } }); } + + public static RequestRestart stdresponse(final int code, final String title, final String message) { + return(new RequestRestart() { + public void respond(Request req) { + req.status(code); + req.outheaders().put("content-type", "text/html; charset=us-ascii"); + PrintWriter out; + try { + out = new PrintWriter(new OutputStreamWriter(req.output(), "US-ASCII")); + } catch(UnsupportedEncodingException e) { + throw(new Error(e)); + } + out.println(""); + out.println(""); + out.println(""); + out.println("" + title + ""); + out.println(""); + out.println("

" + title + "

"); + out.println(message); + out.println(""); + out.println(""); + out.flush(); + } + }); + } + + public static RequestRestart stdresponse(int code, String message) { + return(stdresponse(code, "An error occurred", message)); + } + + public static RequestRestart stdresponse(int code) { + return(stdresponse(code, "An error occurred", Misc.statustext(code))); + } + + public static RequestRestart done() { + return(new RequestRestart() { + public void respond(Request req) { + } + }); + } }