io.vertx.ext.web.Route.getPath()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中io.vertx.ext.web.Route.getPath方法的一些代码示例,展示了Route.getPath的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Route.getPath方法的具体详情如下:
包路径:io.vertx.ext.web.Route
类名称:Route
方法名:getPath

Route.getPath介绍

暂无

代码示例

代码示例来源:origin: openzipkin/brave

@Override public void handle(Void aVoid) {
  if (!finished.compareAndSet(false, true)) return;
  VertxHttpServerAdapter.setCurrentMethodAndPath(
    context.request().rawMethod(),
    context.currentRoute().getPath()
  );
  try {
   serverHandler.handleSend(context.response(), context.failure(), span);
  } finally {
   VertxHttpServerAdapter.setCurrentMethodAndPath(null, null);
  }
 }
}

代码示例来源:origin: vert-x3/vertx-web

private String getAndCheckRoutePath(RoutingContext ctx) {
 Route currentRoute = ctx.currentRoute();
 String path = currentRoute.getPath();
 if (path == null) {
  throw new IllegalStateException("Sub routers must be mounted on constant paths (no regex or patterns)");
 }
 return path;
}

代码示例来源:origin: vert-x3/vertx-web

public static String pathOffset(String path, RoutingContext context) {
 int prefixLen = 0;
 String mountPoint = context.mountPoint();
 if (mountPoint != null) {
  prefixLen = mountPoint.length();
 }
 String routePath = context.currentRoute().getPath();
 if (routePath != null) {
  prefixLen += routePath.length();
  // special case we need to verify if a trailing slash  is present and exclude
  if (routePath.charAt(routePath.length() - 1) == '/') {
   prefixLen--;
  }
 }
 return prefixLen != 0 ? path.substring(prefixLen) : path;
}

代码示例来源:origin: vert-x3/vertx-web

private String authURI(String redirectURL) {
 final JsonObject config = new JsonObject()
  .put("state", redirectURL);
 if (host != null) {
  config.put("redirect_uri", host + callback.getPath());
 }
 if (extraParams != null) {
  config.mergeIn(extraParams);
 }
 if (scopes.size() > 0) {
  JsonArray _scopes = new JsonArray();
  // scopes are passed as an array because the auth provider has the knowledge on how to encode them
  for (String authority : scopes) {
   _scopes.add(authority);
  }
  config.put("scopes", _scopes);
 }
 return ((OAuth2Auth) authProvider).authorizeURL(config);
}

代码示例来源:origin: vert-x3/vertx-web

context.normalisedPath().equals(callback.getPath())) {

代码示例来源:origin: vert-x3/vertx-web

@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());
}

代码示例来源:origin: vert-x3/vertx-web

@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());
}

代码示例来源:origin: vert-x3/vertx-web

@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());
}

代码示例来源:origin: vert-x3/vertx-web

@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());
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testRouteGetPath() throws Exception {
 assertEquals("/foo", router.route("/foo").getPath());
 assertEquals("/foo/:id", router.route("/foo/:id").getPath());
}

代码示例来源:origin: vert-x3/vertx-web

config.put("redirect_uri", host + route.getPath());

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testFixedContent() {
 Buffer buffer = new JsonObject().put("toto", "titi").toBuffer();
 testRoute.produces("application/json").handler(rc -> rc.response().end(buffer));
 client.get(testRoute.getPath(), onSuccess(resp -> {
  assertEquals("application/json", contentType(resp));
  assertEquals(Integer.valueOf(buffer.length()), contentLength(resp));
  resp.bodyHandler(buf -> {
   assertEquals(buffer, buf);
   testComplete();
  });
 })).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testNoContent() {
 testRoute.produces("application/json").handler(rc -> rc.response().end());
 client.get(testRoute.getPath(), onSuccess(resp -> {
  assertNull(contentType(resp));
  assertEquals(Integer.valueOf(0), contentLength(resp));
  testComplete();
 })).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testDisableFlag() {
 Random random = new Random();
 byte[] bytes = new byte[128];
 random.nextBytes(bytes);
 Buffer buffer = Buffer.buffer(bytes);
 testRoute.produces("application/json").handler(rc -> {
  rc.put(ResponseContentTypeHandler.DEFAULT_DISABLE_FLAG, true);
  rc.response().end(buffer);
 });
 client.get(testRoute.getPath(), onSuccess(resp -> {
  assertNull(contentType(resp));
  assertEquals(Integer.valueOf(buffer.length()), contentLength(resp));
  resp.bodyHandler(buf -> {
   assertEquals(buffer, buf);
   testComplete();
  });
 })).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testNoMatch() {
 testRoute.handler(rc -> rc.response().end());
 client.get(testRoute.getPath(), onSuccess(resp -> {
  assertNull(contentType(resp));
  testComplete();
 })).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testChunkedContent() {
 Buffer buffer = new JsonObject().put("toto", "titi").toBuffer();
 testRoute.produces("application/json").handler(rc -> rc.response().setChunked(true).end(buffer));
 client.get(testRoute.getPath(), onSuccess(resp -> {
  assertEquals("application/json", contentType(resp));
  assertNull(contentLength(resp));
  resp.bodyHandler(buf -> {
   assertEquals(buffer, buf);
   testComplete();
  });
 })).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

代码示例来源:origin: vert-x3/vertx-web

@Test
public void testExistingHeader() {
 testRoute.produces("application/json").handler(rc -> rc.response().putHeader(CONTENT_TYPE, "text/plain").end());
 client.get(testRoute.getPath(), onSuccess(resp -> {
  assertEquals("text/plain", contentType(resp));
  testComplete();
 })).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

代码示例来源:origin: io.vertx/vertx-web

@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());
}

代码示例来源:origin: vert-x3/vertx-web

assertEquals("blah2", rc.get("key2"));
 assertEquals("blah3", rc.get("key3"));
 rc.response().setStatusMessage(rc.currentRoute().getPath()).end();
});

代码示例来源:origin: io.vertx/vertx-web

@Test
public void testNoMatch() {
 testRoute.handler(rc -> rc.response().end());
 client.get(testRoute.getPath(), resp -> {
  assertNull(contentType(resp));
  testComplete();
 }).putHeader(HttpHeaders.ACCEPT, "application/json").end();
 await();
}

相关文章