本文整理汇总了Java中io.vertx.ext.web.Route.handler方法的典型用法代码示例。如果您正苦于以下问题:Java Route.handler方法的具体用法?Java Route.handler怎么用?Java Route.handler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.Route
的用法示例。
在下文中一共展示了Route.handler方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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());
}
});
}
示例3: 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");
});
}
示例4: buildRoutesFor
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
public <T extends Annotation> void buildRoutesFor(String prefix, Class<T> anot, RoutingMethod method, RequestWrapper requestWrapper) throws IllegalArgumentException, InvalidRouteConfiguration {
for (Route r : pathsForAnnotation(prefix, anot)
.flatMap(s -> getRoutes(method, s))
.collect(Collectors.toList()))
if (isFailHandler())
r.failureHandler(getHandler(requestWrapper));
else
r.handler(getHandler(requestWrapper));
}
示例5: start
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
HttpServer httpServer = vertx.createHttpServer();
Router router = Router.router(vertx);
Route route = router.route();
route.handler(BodyHandler.create());
route = router.route(HttpMethod.POST, "/actions");
route.handler(this::_handle);
httpServer.requestHandler(router::accept);
httpServer.listen(
_PORT,
result -> {
if (result.succeeded()) {
startFuture.complete();
}
else {
startFuture.fail(result.cause());
}
});
}
示例6: setHandler
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
/**
* Sets the handler.
*
* @param router the router
* @param data the data
*/
protected void setHandler(Router router, HandlerData data) {
// Create auth handler if is setted
if (data.authHandler() != null) {
Route authRoute = createRoute(router, data);
authRoute.handler(data.authHandler());
}
// Create route handler
Route hdRegRoute = createRoute(router, data);
Route route = createRoute(router, data);
hdRegRoute.order(Integer.MIN_VALUE).handler(ctx -> {
ctx.put(HANDLER_DATA, data);
ctx.next();
});
if (HandlerType.HANDLER.equals(data.handlerType())) {
route.handler(prepareHandler(data));
} else if (HandlerType.FAILURE_HANDLER.equals(data.handlerType())) {
route.failureHandler(prepareHandler(data));
} else if (HandlerType.BLOCKING_HANDLER.equals(data.handlerType())) {
route.blockingHandler(prepareHandler(data), false);
} else if (HandlerType.SOCKETJS_HANDLER.equals(data.handlerType())) {
route.handler(prepareSockJsHandler(data));
}
}
示例7: setHandler
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
/**
* Sets the handler.
*
* @param data the data
* @param route the route
*/
protected static void setHandler(HandlerData data, Route route) {
if (HandlerType.HANDLER.equals(data.handlerType())) {
route.handler(prepareHandler(data));
} else if (HandlerType.FAILURE_HANDLER.equals(data.handlerType())) {
route.failureHandler(prepareHandler(data));
} else if (HandlerType.BLOCKING_HANDLER.equals(data.handlerType())) {
route.blockingHandler(prepareHandler(data), false);
}
}
示例8: initHttpRoute
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
private static void initHttpRoute(
String methodId,
VxmsShared vxmsShared,
Object service,
Method restMethod,
Optional<Consumes> consumes,
Optional<Method> errorMethod,
Route route) {
route.handler(
routingContext ->
handleRESTRoutingContext(
methodId, vxmsShared, service, restMethod, errorMethod, routingContext));
updateHttpConsumes(consumes, route);
}
示例9: configureRoute
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
private static void configureRoute(Route route, String serviceId, Operation operation, EventBus eventBus, Function<RoutingContext, DeliveryOptions> configureMessage) {
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();
Object value = PARAMETER_EXTRACTORS.get(parameter.getIn()).extract(name, parameter, context);
message.put(name, value);
});
// callback to configure message e.g. provide message header values
DeliveryOptions deliveryOptions = configureMessage != null ? configureMessage.apply(context) : new DeliveryOptions();
addAuthUserHeader(context, deliveryOptions);
context.request().headers().forEach(entry -> deliveryOptions.addHeader(entry.getKey(), entry.getValue()));
eventBus.<String> send(serviceId, message, deliveryOptions, operationResponse -> {
if (operationResponse.succeeded()) {
manageHeaders(context.response(), operationResponse.result().headers());
if (operationResponse.result().body() != null) {
context.response().end(operationResponse.result().body());
} else {
context.response().end();
}
} else {
vertxLogger.error("Internal Server Error", operationResponse.cause());
manageError((ReplyException)operationResponse.cause(), context.response());
}
});
} catch (Exception e) {
vertxLogger.error("sending Bad Request", e);
badRequestEnd(context.response());
}
});
}
示例10: setupCallback
import io.vertx.ext.web.Route; //导入方法依赖的package包/类
@Override
public OAuth2AuthHandler setupCallback(Route route) {
callback = route;
if (callbackPath != null && !"".equals(callbackPath)) {
// no matter what path was provided we will make sure it is the correct one
callback.path(callbackPath);
}
callback.method(HttpMethod.GET);
route.handler(ctx -> {
// Handle the callback of the flow
final String code = ctx.request().getParam("code");
// code is a require value
if (code == null) {
ctx.fail(400);
return;
}
final String state = ctx.request().getParam("state");
final JsonObject config = new JsonObject()
.put("code", code);
if (host != null) {
config.put("redirect_uri", host + callback.getPath());
}
if (extraParams != null) {
config.mergeIn(extraParams);
}
authProvider.authenticate(config, res -> {
if (res.failed()) {
ctx.fail(res.cause());
} else {
ctx.setUser(res.result());
Session session = ctx.session();
if (session != null) {
// the user has upgraded from unauthenticated to authenticated
// session should be upgraded as recommended by owasp
session.regenerateId();
// we should redirect the UA so this link becomes invalid
ctx.response()
// disable all caching
.putHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate")
.putHeader("Pragma", "no-cache")
.putHeader(HttpHeaders.EXPIRES, "0")
// redirect (when there is no state, redirect to home
.putHeader(HttpHeaders.LOCATION, state != null ? state : "/")
.setStatusCode(302)
.end("Redirecting to " + (state != null ? state : "/") + ".");
} else {
// there is no session object so we cannot keep state
ctx.reroute(state != null ? state : "/");
}
}
});
});
return this;
}