Search in sources :

Example 1 with TemplateHandler

use of io.vertx.ext.web.handler.TemplateHandler in project vertx-web by vert-x3.

the class TemplateHandlerImplTest method testTurnOffIndex.

@Test
public void testTurnOffIndex() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalisedPath()).thenReturn("/");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.setIndexTemplate(null);
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(), eq("templates"), eq("/"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.templ.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) Test(org.junit.Test)

Example 2 with TemplateHandler

use of io.vertx.ext.web.handler.TemplateHandler in project vertx-web by vert-x3.

the class TemplateHandlerImplTest method testSimpleTemplate.

@Test
public void testSimpleTemplate() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalisedPath()).thenReturn("/about");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(), eq("templates"), eq("/about"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.templ.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) Test(org.junit.Test)

Example 3 with TemplateHandler

use of io.vertx.ext.web.handler.TemplateHandler in project vertx-web by vert-x3.

the class TemplateHandlerImplTest method testDefaultIndex.

@Test
public void testDefaultIndex() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalisedPath()).thenReturn("/");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(), eq("templates"), eq("/index"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.templ.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) Test(org.junit.Test)

Example 4 with TemplateHandler

use of io.vertx.ext.web.handler.TemplateHandler in project vertx-web by vert-x3.

the class TemplateHandlerImplTest method testSetIndex.

@Test
public void testSetIndex() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalisedPath()).thenReturn("/");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.setIndexTemplate("home");
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(), eq("templates"), eq("/home"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.templ.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) Test(org.junit.Test)

Example 5 with TemplateHandler

use of io.vertx.ext.web.handler.TemplateHandler in project VX-API-Gateway by EliMirren.

the class ClientVerticle method start.

@Override
public void start(Future<Void> fut) throws Exception {
    LOG.info("start Client Verticle ...");
    thisVertxName = System.getProperty("thisVertxName", "VX-API");
    Router router = Router.router(vertx);
    router.route().handler(FaviconHandler.create(getFaviconPath()));
    router.route().handler(BodyHandler.create().setUploadsDirectory(getUploadsDirectory()));
    router.route().handler(CookieHandler.create());
    if (vertx.isClustered()) {
        router.route().handler(SessionHandler.create(ClusteredSessionStore.create(vertx)).setSessionCookieName(VxApiGatewayAttribute.SESSION_COOKIE_NAME));
    } else {
        router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)).setSessionCookieName(VxApiGatewayAttribute.SESSION_COOKIE_NAME));
    }
    // 通过html的方式管理应用网关
    TemplateEngine engine = VxApiFreeMarkerTemplateEngine.create(getTemplateRoot());
    TemplateHandler tempHandler = TemplateHandler.create(engine, getTemplateRoot(), CONTENT_VALUE_HTML_UTF8);
    router.getWithRegex(".+\\.ftl").handler(tempHandler);
    // 权限相关
    router.route("/static/*").handler(VxApiClientStaticAuth.create());
    router.route("/static/*").handler(this::staticAuth);
    router.route("/loginOut").handler(this::loginOut);
    router.route("/static/CreateAPI.html").handler(this::staticAPI);
    router.route("/static/CreateAPP.html").handler(this::staticAPP);
    router.route("/static/*").handler(StaticHandler.create(getStaticRoot()));
    // 查看系统信息
    router.route("/static/sysInfo").handler(this::sysInfo);
    router.route("/static/sysReplaceIpList").handler(this::sysReplaceIpList);
    // Application相关
    router.route("/static/findAPP").handler(this::findAPP);
    router.route("/static/getAPP/:name").handler(this::getAPP);
    router.route("/static/addAPP").handler(this::addAPP);
    router.route("/static/delAPP/:name").handler(this::delAPP);
    router.route("/static/updtAPP/:name").handler(this::loadUpdtAPP);
    router.route("/static/updtAPP").handler(this::updtAPP);
    router.route("/static/deployAPP/:name").handler(this::deployAPP);
    router.route("/static/unDeployAPP/:name").handler(this::unDeployAPP);
    // API相关
    router.route("/static/findAPI/:name").handler(this::findAPI);
    router.route("/static/getAPI/:name").handler(this::getAPI);
    router.route("/static/addAPI").handler(this::addAPI);
    router.route("/static/updtAPI/:name").handler(this::loadUpdtAPI);
    router.route("/static/updtAPI").handler(this::updtAPI);
    router.route("/static/delAPI/:appName/:apiName").handler(this::delAPI);
    router.route("/static/startAllAPI/:appName").handler(this::startAllAPI);
    router.route("/static/startAPI/:apiName").handler(this::startAPI);
    router.route("/static/stopAPI/:appName/:apiName").handler(this::stopAPI);
    router.route("/static/trackInfo/:appName/:apiName").handler(this::getTrackInfo);
    // 欢迎页
    router.route("/").handler(this::welcome);
    vertx.createHttpServer().requestHandler(router::accept).listen(config().getInteger("clientPort", 5256), res -> {
        if (res.succeeded()) {
            LOG.info("start Clinet Verticle successful");
            fut.complete();
        } else {
            LOG.info("start Clinet Verticle unsuccessful");
            fut.fail(res.cause());
        }
    });
}
Also used : TemplateEngine(io.vertx.ext.web.templ.TemplateEngine) VxApiFreeMarkerTemplateEngine(com.szmirren.vxApi.core.handler.freemarker.VxApiFreeMarkerTemplateEngine) Router(io.vertx.ext.web.Router) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler)

Aggregations

TemplateHandler (io.vertx.ext.web.handler.TemplateHandler)5 TemplateEngine (io.vertx.ext.web.templ.TemplateEngine)5 Route (io.vertx.ext.web.Route)4 RoutingContext (io.vertx.ext.web.RoutingContext)4 TemplateHandlerImpl (io.vertx.ext.web.handler.impl.TemplateHandlerImpl)4 Test (org.junit.Test)4 VxApiFreeMarkerTemplateEngine (com.szmirren.vxApi.core.handler.freemarker.VxApiFreeMarkerTemplateEngine)1 Router (io.vertx.ext.web.Router)1