ctx.addHandler("/test/*", new TestRequestHandler());
HttpServer server = new HttpServer(ctx);
server.start();
HttpClient httpClient = new HttpClient();
IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + jettyServer.getConnectors()[0].getLocalPort() + "/ctx1/test/you"));
if (response.getStatus() != 200) {
System.out.println("got " + response.getStatus() + " instead of 200");
Assert.fail();
}
String body = response.getBlockingBody().readString();
if (body.indexOf("contextPath=/ctx1") == -1) {
System.out.println("contextPath=/ctx1 expected");
Assert.fail();
}
if (body.indexOf("contextPath=/ctx1") == -1) {
System.out.println("servletPath=/test expected");
Assert.fail();
}
response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx1/test/you"));
if (response.getStatus() != 200) {
System.out.println("got " + response.getStatus());
Assert.fail();
}
body = response.getBlockingBody().readString();
Assert.assertTrue(body.indexOf("contextPath=/ctx1") != -1);
Assert.assertTrue(body.indexOf("servletPath=/test") != -1);
httpClient.close();
jettyServer.stop();
server.close();
}