javahtmlwebserverhttp-status-code-406jooby

Jooby Webserver Always throwing error "406 Not acceptable: text/html"


I'm setting up a simple Jooby Webserver. I have a App.java and a home.html file. For now, the only thing i want it to do, is that if you open the home page it shows a html page saying "Hello World". However, I'm always getting the error "org.jooby.Err: Not Acceptable(406): text/html".

I created the project via maven with an archetype, but I also tried to create it with gradle. I run the program with Java 8, in IntellIJ IDEA. I've already tried using different HTML files, but I don't think anything is wrong with it, because if I return it as a raw String, it works (I just don't want to do it because I would't be able to use JavaScript and Image files normally). I've also tried doing it in a seperate class, doing it with the get() method, and I tried to not return the Result but instead do response.send(result).

Here is my code:

home.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
</head>
<body>
    Hello World!
</body>
</html>

App.java:

public class App extends Jooby {
    {
        get("/", req -> {
            //Line that throws the error:
            return Results.html("home").put("model", new Object());
        });
    }

    public static void main(final String[] args) {
        run(App::new, args);
    }
}

I would obviously expect it to just show me the "Hello World" text, but instead it shows me a screen with the following stacktrace:

org.jooby.Err: Not Acceptable(406): text/html

at org.jooby.internal.AbstractRendererContext.render(AbstractRendererContext.java:280)

at org.jooby.internal.ResponseImpl.send(ResponseImpl.java:562)

at org.jooby.Response.send(Response.java:624)

at org.jooby.Route$OneArgHandler.handle(Route.java:2000)

at org.jooby.internal.RouteImpl.handle(RouteImpl.java:282)

at org.jooby.internal.RouteChain.next(RouteChain.java:262)

at org.jooby.Route$Chain.next(Route.java:2345)

at org.jooby.internal.HttpHandlerImpl.handle(HttpHandlerImpl.java:497)

at org.jooby.internal.netty.NettyHandler.channelRead0(NettyHandler.java:271)

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)

at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:38)

at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:353)

at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66)

at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)

at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)

at java.lang.Thread.run(Thread.java:748)

Solution

  • Results.html requires a template engine. If all you want is to show a static page, try this:

    {
      assets("/", "index.html");
    }
    

    The index.html file must be at the root of the classpath.