Search in sources :

Example 1 with StaticHttpHandler

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));
    }
}
Also used : HttpServerFilter(org.glassfish.grizzly.http.server.HttpServerFilter) StaticHttpHandler(org.glassfish.grizzly.http.server.StaticHttpHandler) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 HttpServerFilter (org.glassfish.grizzly.http.server.HttpServerFilter)1 StaticHttpHandler (org.glassfish.grizzly.http.server.StaticHttpHandler)1