/** * Specify the order for this route. The router tests routes in that order. * @param order the order * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.Route order(int order) { delegate.order(order); return this; }
@Override public InternalEndpointRoute order(int order) { route.order(order); return this; }
/** * Specify the order for this route. The router tests routes in that order. * @param order the order * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.Route order(int order) { delegate.order(order); return this; }
@Override public Route order(int order) { return delegate.order(order); }
@Test public void testOrdering() throws Exception { String path = "/blah"; router.route(path).order(1).handler(rc -> { rc.response().write("apples"); rc.next(); }); router.route(path).order(2).handler(rc -> { rc.response().write("oranges"); rc.response().end(); }); router.route(path).order(0).handler(rc -> { rc.response().setChunked(true); rc.response().write("bananas"); rc.next(); }); testRequest(HttpMethod.GET, path, 200, "OK", "bananasapplesoranges"); }
@Test public void testChangeOrderAfterActive2() throws Exception { String path = "/blah"; Route route = router.route(path).failureHandler(rc -> { rc.response().write("apples"); rc.next(); }); try { route.order(23); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testChangeOrderAfterActive1() throws Exception { String path = "/blah"; Route route = router.route(path).handler(rc -> { rc.response().write("apples"); rc.next(); }); try { route.order(23); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testCacheNotOverwritingCacheControlHeaderValues() throws Exception { router.clear(); router.route().order(0).handler(context -> { context.response().putHeader("cache-control", "test1"); context.response().putHeader("last-modified", "test2"); context.response().putHeader("vary", "test3"); context.next(); }); router.route().order(2).handler(stat); testRequest(HttpMethod.GET, "/otherpage.html", req -> req.putHeader("accept-encoding", "gzip"), res -> { String cacheControl = res.headers().get("cache-control"); String lastModified = res.headers().get("last-modified"); String vary = res.headers().get("vary"); assertEquals("test1", cacheControl); assertEquals("test2", lastModified); assertEquals("test3", vary); }, 200, "OK", "<html><body>Other page</body></html>"); }
@Test public void testIssue176() throws Exception { router.route().order(0).handler(context -> { context.response().headers().add("X-Here-1", "1"); context.next(); }); router.route().order(0).handler(context -> { context.response().headers().add("X-Here-2", "2"); context.next(); }); router.route().handler(context -> { context.response().headers().add("X-Here-3", "3"); context.response().end(); }); testRequest(HttpMethod.GET, "/", null, resp -> { MultiMap headers = resp.headers(); assertTrue(headers.contains("X-Here-1")); assertTrue(headers.contains("X-Here-2")); assertTrue(headers.contains("X-Here-3")); }, 200, "OK", null); }
public static void provide(Router output, ContextProvider<?> provider) { output.route().order(ORDER_PROVIDER_HANDLER).handler(getContextHandler(provider)); }
@Override public void mount(final Router router) { /* Breaker and Dispatch **/ router.route("/*") .order(Orders.EVENT) .handler(ServiceJet .create(this.options) .connect(this.vertx) .handle()); } }
public static void provide(Router output, Class<? extends ContextProvider> provider) { try { Class clazz = (Class) ClassFactory.getGenericType(provider); ContextProvider instance = getContextProviders().getContextProvider(injectionProvider, clazz, provider, null); // set before other routes ... output.route().order(ORDER_PROVIDER_HANDLER).handler(getContextHandler(instance)); } catch (Throwable e) { throw new IllegalArgumentException(e); } }
@Override public void mount(final Router router) { /* Breaker and Dispatch **/ router.route("/*") .order(Orders.EVENT) .handler(ServiceJet .create(this.options) .connect(this.vertx) .handle()); } }
@Override public void mount(final Router router) { // Session Global for Authorzation router.route().order(Orders.SESSION).handler( SessionHandler.create(LocalSessionStore.create(this.vertx)) ); Pool.WALL_MAP.forEach((path, cliffes) -> { // 1. Build Handler final AuthHandler handler = this.create(this.vertx, cliffes); // 2. Path/Order to set Router if (null != handler) { router.route(path).order(Orders.SECURE).handler(handler) .failureHandler(AuthenticateEndurer.create()); } // 3. Wall Advanced, For user data filling. }); }
@Test public void testOrdering() throws Exception { String path = "/blah"; router.route(path).order(1).handler(rc -> { rc.response().write("apples"); rc.next(); }); router.route(path).order(2).handler(rc -> { rc.response().write("oranges"); rc.response().end(); }); router.route(path).order(0).handler(rc -> { rc.response().setChunked(true); rc.response().write("bananas"); rc.next(); }); testRequest(HttpMethod.GET, path, 200, "OK", "bananasapplesoranges"); }
@Test public void testChangeOrderAfterActive1() throws Exception { String path = "/blah"; Route route = router.route(path).handler(rc -> { rc.response().write("apples"); rc.next(); }); try { route.order(23); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testChangeOrderAfterActive2() throws Exception { String path = "/blah"; Route route = router.route(path).failureHandler(rc -> { rc.response().write("apples"); rc.next(); }); try { route.order(23); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testCacheNotOverwritingCacheControlHeaderValues() throws Exception { router.clear(); router.route().order(0).handler(context -> { context.response().putHeader("cache-control", "test1"); context.response().putHeader("last-modified", "test2"); context.response().putHeader("vary", "test3"); context.next(); }); router.route().order(2).handler(stat); testRequest(HttpMethod.GET, "/otherpage.html", req -> req.putHeader("accept-encoding", "gzip"), res -> { String cacheControl = res.headers().get("cache-control"); String lastModified = res.headers().get("last-modified"); String vary = res.headers().get("vary"); assertEquals("test1", cacheControl); assertEquals("test2", lastModified); assertEquals("test3", vary); }, 200, "OK", "<html><body>Other page</body></html>"); }