@Override public String normalisedPath() { return decoratedContext.normalisedPath(); }
@Override public String normalisedPath() { return inner.normalisedPath(); }
@Override public void parseCredentials(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) { if (skip != null && context.normalisedPath().startsWith(skip)) { context.next(); return; } parseAuthorization(context, false, parseAuthorization -> { if (parseAuthorization.failed()) { handler.handle(Future.failedFuture(parseAuthorization.cause())); return; } handler.handle(Future.succeededFuture(new JsonObject().put("jwt", parseAuthorization.result()).put("options", options))); }); }
private boolean pathMatches(String mountPoint, RoutingContext ctx) { String thePath = mountPoint == null ? path : mountPoint + path; String requestPath; if (useNormalisedPath) { // never null requestPath = ctx.normalisedPath(); } else { requestPath = ctx.request().path(); // can be null if (requestPath == null) { requestPath = "/"; } } if (exactPath) { return pathMatchesExact(requestPath, thePath); } else { if (thePath.endsWith("/") && requestPath.equals(removeTrailing(thePath))) { return true; } return requestPath.startsWith(thePath); } }
context.normalisedPath().equals(callback.getPath())) {
String normalizedDir = context.normalisedPath(); if (!normalizedDir.endsWith("/")) { normalizedDir += "/";
@Override public void handle(RoutingContext context) { String file = Utils.pathOffset(context.normalisedPath(), context); if (file.endsWith("/") && null != indexTemplate) { file += indexTemplate;
@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(JsonObject.class), eq("templates/about"), any()); }
@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(JsonObject.class), eq("templates/index"), any()); }
@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(JsonObject.class), eq("templates/home"), any()); }
@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(JsonObject.class), eq("templates/"), any()); }
@Override public String normalisedPath() { return delegate.normalisedPath(); }
@Test public void testRouteGetPathWithParamsInHandler() throws Exception { router.route("/foo/:id").handler(rc -> { assertEquals("/foo/123", rc.normalisedPath()); rc.response().end(); }); testRequest(HttpMethod.GET, "/foo/123", 200, "OK"); }
@Override public void handle(RoutingContext context) { HttpServerRequest request = context.request(); if (request.method() != HttpMethod.GET && request.method() != HttpMethod.HEAD) { if (log.isTraceEnabled()) log.trace("Not GET or HEAD so ignoring request"); context.next(); } else { String path = HttpUtils.removeDots(URIDecoder.decodeURIComponent(context.normalisedPath(), false)); // if the normalized path is null it cannot be resolved if (path == null) { log.warn("Invalid path: " + context.request().path()); context.next(); return; } // only root is known for sure to be a directory. all other directories must be identified as such. if (!directoryListing && "/".equals(path)) { path = indexPage; } // can be called recursive for index pages sendStatic(context, path); } }
@Test public void testGetWithPlusPath2() throws Exception { router.get("/:param1").useNormalisedPath(false).handler(rc -> { assertEquals("/some+path", rc.normalisedPath()); assertEquals("some+path", rc.pathParam("param1")); assertEquals("some query", rc.request().getParam("q1")); rc.response().setStatusMessage("foo").end(); }); testRequest(HttpMethod.GET, "/some+path?q1=some+query", 200, "foo"); }
@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(JsonObject.class), eq("templates/index"), any()); }
@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(JsonObject.class), eq("templates/about"), any()); }
@Override public void handle(RoutingContext event) { String path = event.request().path(); LOGGER.info("handling template for url " + event.normalisedPath() + " | " + path); if (path.endsWith("/")) { LOGGER.info("REROUTING TO: " + path); path += "index.html"; event.reroute(path); } else { templateHandler.handle(event); } }
@Test public void testRouteGetPathWithParamsInHandler() throws Exception { router.route("/foo/:id").handler(rc -> { assertEquals("/foo/123", rc.normalisedPath()); rc.response().end(); }); testRequest(HttpMethod.GET, "/foo/123", 200, "OK"); }
@Test public void testGetWithPlusPath2() throws Exception { router.get("/:param1").useNormalisedPath(false).handler(rc -> { assertEquals("/some+path", rc.normalisedPath()); assertEquals("some+path", rc.pathParam("param1")); assertEquals("some query", rc.request().getParam("q1")); rc.response().setStatusMessage("foo").end(); }); testRequest(HttpMethod.GET, "/some+path?q1=some+query", 200, "foo"); }