use of org.glassfish.grizzly.http.server.StaticHttpHandler in project Payara by payara.
the class BaseTestGrizzlyConfig method addStaticHttpHandler.
protected void addStaticHttpHandler(GenericGrizzlyListener listener, int count) {
final String name = "target/tmp/" + Dom.convertName(getClass().getSimpleName()) + count;
File dir = new File(name);
dir.mkdirs();
dir.deleteOnExit();
FileWriter writer;
try {
final File file = new File(dir, "index.html");
file.deleteOnExit();
writer = new FileWriter(file);
try {
writer.write("<html><body>You've found the server on port " + listener.getPort() + "</body></html>");
writer.flush();
} finally {
writer.close();
}
} catch (IOException e) {
Assert.fail(e.getMessage());
}
final List<HttpServerFilter> httpServerFilters = listener.getFilters(HttpServerFilter.class);
for (HttpServerFilter httpServerFilter : httpServerFilters) {
httpServerFilter.setHttpHandler(new StaticHttpHandler(name));
}
}
Aggregations