Created
April 18, 2019 21:44
-
-
Save Jotschi/458c7101431b3d839b6a74d63ed4808e to your computer and use it in GitHub Desktop.
HandlebarsExample Vert.x Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.IllegalArgumentException: Cannot find resource /index.hbs | |
at io.vertx.ext.web.templ.handlebars.impl.HandlebarsTemplateEngineImpl$Loader.sourceAt(HandlebarsTemplateEngineImpl.java:137) | |
at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:438) | |
at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:419) | |
at io.vertx.ext.web.templ.handlebars.impl.HandlebarsTemplateEngineImpl.render(HandlebarsTemplateEngineImpl.java:86) | |
at de.jotschi.graphql.HandlebarsExample.lambda$0(HandlebarsExample.java:22) | |
at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:227) | |
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:121) | |
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:134) | |
at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:80) | |
at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:41) | |
at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:50) | |
at io.vertx.core.http.impl.WebSocketRequestHandler.handle(WebSocketRequestHandler.java:32) | |
at io.vertx.core.http.impl.HttpServerRequestImpl.handleBegin(HttpServerRequestImpl.java:151) | |
at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:138) | |
at io.vertx.core.impl.EventLoopContext.schedule(EventLoopContext.java:45) | |
at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:173) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) | |
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) | |
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) | |
at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:102) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) | |
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) | |
at io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:98) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) | |
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) | |
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) | |
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) | |
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) | |
at io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61) | |
at io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) | |
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) | |
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) | |
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) | |
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) | |
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) | |
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644) | |
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579) | |
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496) | |
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) | |
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) | |
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) | |
at java.base/java.lang.Thread.run(Thread.java:844) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HandlebarsExample extends AbstractVerticle { | |
@Override | |
public void start(Future<Void> startFuture) throws Exception { | |
HttpServerOptions options = new HttpServerOptions(); | |
options.setPort(9999); | |
HttpServer server = vertx.createHttpServer(options); | |
Router router = Router.router(vertx); | |
HandlebarsTemplateEngine engine = HandlebarsTemplateEngine.create(vertx); | |
router.route("/test").handler(rc -> { | |
engine.render(rc.data(), "index.hbs", rr -> { | |
if (rr.failed()) { | |
rr.cause().printStackTrace(); | |
rc.fail(rr.cause()); | |
} else { | |
rc.response().end(rr.result()); | |
} | |
}); | |
}); | |
server.requestHandler(router::handle); | |
server.listen(e -> { | |
if (e.failed()) { | |
startFuture.fail(e.cause()); | |
} else { | |
startFuture.complete(); | |
} | |
}); | |
} | |
public static void main(String[] args) { | |
Vertx vertx = Vertx.vertx(); | |
vertx.deployVerticle(new HandlebarsExample()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment