本文整理汇总了Java中io.vertx.ext.web.Route类的典型用法代码示例。如果您正苦于以下问题:Java Route类的具体用法?Java Route怎么用?Java Route使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Route类属于io.vertx.ext.web包,在下文中一共展示了Route类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpServerAndRoutes
import io.vertx.ext.web.Route; //导入依赖的package包/类
private HttpServer getHttpServerAndRoutes(final io.vertx.core.http.HttpServer vertxHttpServer, final Router router) {
/* Route everything under /v1 to QBit http server. */
final Route qbitRoute = router.route().path("/v1/*");
/*
* Use the VertxHttpServerBuilder which is a special builder for Vertx/Qbit integration.
*/
return VertxHttpServerBuilder.vertxHttpServerBuilder()
.setRoute(qbitRoute)
.setHttpServer(vertxHttpServer)
.setVertx(getVertx())
.setConfig(new HttpServerConfig()) //not needed in master branch of qbit workaround for bug
.build();
}
示例2: logRoutes
import io.vertx.ext.web.Route; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Router logRoutes(Router router) {
try {
for (Route route : router.getRoutes()) {
// path is public but methods are not, we use reflection to make that accessible
@SuppressWarnings("JavaReflectionMemberAccess")
Field f = route.getClass().getDeclaredField("methods");
f.setAccessible(true);
Set<HttpMethod> methods = (Set<HttpMethod>) f.get(route);
if (isNotBlank(route.getPath())) {
methods.forEach(httpMethod -> logger.info("Route: [{}] {}", httpMethod, route.getPath()));
}
}
} catch (Exception ex) {
logger.info("Could not list a route due to: {}!", ex.getMessage());
}
return router;
}
示例3: checkSecurity
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void checkSecurity(Router router, final RouteDefinition definition) {
Route route;
if (definition.pathIsRegEx()) {
route = router.routeWithRegex(definition.getMethod(), definition.getRoutePath());
} else {
route = router.route(definition.getMethod(), definition.getRoutePath());
}
route.order(definition.getOrder()); // same order as following handler
Handler<RoutingContext> securityHandler = getSecurityHandler(definition);
if (definition.isBlocking()) {
route.blockingHandler(securityHandler);
} else {
route.handler(securityHandler);
}
}
示例4: rootHandler
import io.vertx.ext.web.Route; //导入依赖的package包/类
/**
* Handler for the /api endpoint, listing out routes and loaded verticles
*
* @param ctx
*/
private void rootHandler(final RoutingContext ctx) {
ctx.response().putHeader(Constants.CONTENT_HEADER, Constants.CONTENT_TYPE_JSON);
final JsonObject result = new JsonObject().put("RunningSince", Utils.getDateString(this.startDate));
final JsonObject routeObject = new JsonObject();
for (final Route r : this.router.getRoutes()) {
final String p = r.getPath();
if (p != null) {
routeObject.put(p, String.valueOf(r));
}
}
result.put("Routes", routeObject);
final JsonArray verticleArray = new JsonArray(this.loadedVerticles);
result.put("Verticles", verticleArray);
ctx.response().end(result.encodePrettily());
}
示例5: configureRoute
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void configureRoute(Route route, Operation operation, EventBus eventBus) {
Optional.ofNullable(operation.getConsumes()).ifPresent(consumes -> consumes.forEach(route::consumes));
Optional.ofNullable(operation.getProduces()).ifPresent(produces -> produces.forEach(route::produces));
route.handler(context -> {
try {
JsonObject message = new JsonObject();
operation.getParameters().forEach( parameter -> {
String name = parameter.getName();
String value = PARAMETER_EXTRACTORS.get(parameter.getIn()).extract(name, parameter.getRequired(), context.request());
message.put(name, value);
});
eventBus.<JsonObject>send(operation.getOperationId(), message, operationResponse -> {
if (operationResponse.succeeded()) {
context.response().end(operationResponse.result().body().encode());
} else {
internalServerErrorEnd(context.response());
}
});
} catch (RuntimeException e) {
badRequestEnd(context.response());
}
});
}
示例6: createRoute
import io.vertx.ext.web.Route; //导入依赖的package包/类
/**
* Creates the route.
*
* @param router the router
* @param data the data
* @return the route
*/
protected Route createRoute(Router router, HandlerData data) {
Route route = router.route();
setOrder(data, route);
if (StringUtils.isNotEmpty(data.httpMethod())) {
setMethod(data, route);
}
if (StringUtils.isNotEmpty(data.path())) {
setPath(data, route);
}
if (StringUtils.isNotEmpty(data.consumes())) {
setConsumes(data, route);
}
if (StringUtils.isNotEmpty(data.produces())) {
setProduces(data, route);
}
return route;
}
示例7: registerEndPoints
import io.vertx.ext.web.Route; //导入依赖的package包/类
@Override
public void registerEndPoints() {
secureAll();
// TODO Add method that allows assigning languages from and to the project
Route createRoute = route("/:projectUuid/languages").method(POST).produces(APPLICATION_JSON);
createRoute.handler(rc -> {
throw new NotImplementedException("not implemented");
});
Route deleteRoute = route("/:projectUuid/languages").method(DELETE).produces(APPLICATION_JSON);
deleteRoute.handler(rc -> {
// Unassign languages should cause a batch process that removes the FieldContainers for the given language.
throw new NotImplementedException("not implemented");
});
Route getRoute = route("/:projectUuid/languages").method(GET).produces(APPLICATION_JSON);
getRoute.handler(rc -> {
throw new NotImplementedException("not implemented");
});
}
示例8: testFailureHandler
import io.vertx.ext.web.Route; //导入依赖的package包/类
@Test
public void testFailureHandler() throws Exception {
RoutingContext rc = mock(RoutingContext.class);
Route currentRoute = mock(RouteImpl.class);
when(currentRoute.getPath()).thenReturn("/blub");
when(rc.currentRoute()).thenReturn(currentRoute);
ParsedHeaderValues headerValues = mock(ParsedHeaderValues.class);
when(rc.parsedHeaders()).thenReturn(headerValues);
HttpServerRequest request = mock(HttpServerRequest.class);
when(request.query()).thenReturn("?blub");
when(request.method()).thenReturn(HttpMethod.GET);
when(request.uri()).thenReturn("");
when(rc.request()).thenReturn(request);
when(rc.normalisedPath()).thenReturn("/blub");
when(rc.queryParams()).thenReturn(new CaseInsensitiveHeaders());
storage.getRootRouter().handleFailure(rc);
}
示例9: prepareHandler
import io.vertx.ext.web.Route; //导入依赖的package包/类
/**
* Prepare handler.
*
* @param router the router
* @param data the data
*/
public static void prepareHandler(Router router, HandlerData data) {
log.debug("Mapping handler: {}", data.toStringLine());
Route route = router.route().order(data.order());
if (StringUtils.isNotEmpty(data.httpMethod())) {
setMethod(data, route);
}
if (StringUtils.isNotEmpty(data.patch())) {
setPatch(data, route);
}
if (StringUtils.isNotEmpty(data.consumes())) {
setConsumes(data, route);
}
if (StringUtils.isNotEmpty(data.produces())) {
setProduces(data, route);
}
setHandler(data, route);
}
示例10: initHttpAll
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void initHttpAll(
VxmsShared vxmsShared,
Router router,
Object service,
Method restMethod,
Path path,
Stream<Method> errorMethodStream,
Optional<Consumes> consumes) {
final Optional<Method> errorMethod = errorMethodStream.findFirst();
final Route route = router.route(URIUtil.cleanPath(path.value()));
final Vertx vertx = vxmsShared.getVertx();
final Context context = vertx.getOrCreateContext();
final String methodId =
path.value() + HTTP_ALL + ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
initHttpRoute(methodId, vxmsShared, service, restMethod, consumes, errorMethod, route);
}
示例11: initHttpDelete
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void initHttpDelete(
VxmsShared vxmsShared,
Router router,
Object service,
Method restMethod,
Path path,
Stream<Method> errorMethodStream,
Optional<Consumes> consumes) {
final Route route = router.delete(URIUtil.cleanPath(path.value()));
final Vertx vertx = vxmsShared.getVertx();
final Context context = vertx.getOrCreateContext();
final String methodId =
path.value()
+ DELETE.class.getName()
+ ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
initHttpOperation(
methodId,
vxmsShared,
service,
restMethod,
route,
errorMethodStream,
consumes,
DELETE.class);
}
示例12: initHttpPut
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void initHttpPut(
VxmsShared vxmsShared,
Router router,
Object service,
Method restMethod,
Path path,
Stream<Method> errorMethodStream,
Optional<Consumes> consumes) {
final Route route = router.put(URIUtil.cleanPath(path.value()));
final Vertx vertx = vxmsShared.getVertx();
final Context context = vertx.getOrCreateContext();
final String methodId =
path.value()
+ PUT.class.getName()
+ ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
initHttpOperation(
methodId, vxmsShared, service, restMethod, route, errorMethodStream, consumes, PUT.class);
}
示例13: initHttpOptions
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void initHttpOptions(
VxmsShared vxmsShared,
Router router,
Object service,
Method restMethod,
Path path,
Stream<Method> errorMethodStream,
Optional<Consumes> consumes) {
final Route route = router.options(URIUtil.cleanPath(path.value()));
final Vertx vertx = vxmsShared.getVertx();
final Context context = vertx.getOrCreateContext();
final String methodId =
path.value()
+ OPTIONS.class.getName()
+ ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
initHttpOperation(
methodId,
vxmsShared,
service,
restMethod,
route,
errorMethodStream,
consumes,
OPTIONS.class);
}
示例14: initHttpPost
import io.vertx.ext.web.Route; //导入依赖的package包/类
private static void initHttpPost(
VxmsShared vxmsShared,
Router router,
Object service,
Method restMethod,
Path path,
Stream<Method> errorMethodStream,
Optional<Consumes> consumes) {
final Route route = router.post(URIUtil.cleanPath(path.value()));
final Vertx vertx = vxmsShared.getVertx();
final Context context = vertx.getOrCreateContext();
final String methodId =
path.value()
+ POST.class.getName()
+ ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
initHttpOperation(
methodId, vxmsShared, service, restMethod, route, errorMethodStream, consumes, POST.class);
}
示例15: initHttpGet
import io.vertx.ext.web.Route; //导入依赖的package包/类
protected static void initHttpGet(
VxmsShared vxmsShared,
Router router,
Object service,
Method restMethod,
Path path,
Stream<Method> errorMethodStream,
Optional<Consumes> consumes) {
final Route route = router.get(URIUtil.cleanPath(path.value()));
final Vertx vertx = vxmsShared.getVertx();
final Context context = vertx.getOrCreateContext();
final String methodId =
path.value()
+ GET.class.getName()
+ ConfigurationUtil.getCircuitBreakerIDPostfix(context.config());
initHttpOperation(
methodId, vxmsShared, service, restMethod, route, errorMethodStream, consumes, GET.class);
}