protected Server prepareServerWithCatch(int code)
throws Exception
{
if (code == 200) {
final Server result = Server.withPort(0);
result.serve("/trunk/somerepo/").withBehaviours(
new DeliverBehaviour(200, "text/html", ROOT_BODY));
result.serve("/trunk/somerepo/com/").withBehaviours(
new DeliverBehaviour(200, "text/html", COM_BODY));
result.serve("/trunk/somerepo/com/foo/").withBehaviours(
new DeliverBehaviour(200, "text/html", COM_FOO_BODY));
result.serve("/trunk/somerepo/com/bar/").withBehaviours(
new DeliverBehaviour(200, "text/html", COM_BAR_BODY));
return result;
}
else if (code == 403) {
final Server result = Server.withPort(0);
result.serve("/trunk/somerepo/").withBehaviours(
new DeliverBehaviour(200, "text/html", ROOT_BODY));
result.serve("/trunk/somerepo/com/").withBehaviours(
new DeliverBehaviour(403, "text/html", "<h1>Access denied</h1>"));
return result;
}
else if (code == 404) {
final Server result = Server.withPort(0);
result.serve("/trunk/somerepo/").withBehaviours(
new DeliverBehaviour(200, "text/html", ROOT_BODY));
result.serve("/trunk/somerepo/com/").withBehaviours(
new DeliverBehaviour(404, "text/html", "<h1>Not found</h1>"));
return result;
}
else if (code == 500) {
final Server result = Server.withPort(0);
result.serve("/trunk/somerepo/").withBehaviours(
new DeliverBehaviour(200, "text/html", ROOT_BODY));
result.serve("/trunk/somerepo/com/").withBehaviours(
new DeliverBehaviour(500, "text/html", "<h1>Ooops!</h1>"));
return result;
}
else {
throw new IllegalArgumentException("Code " + code + " not supported!");