use of io.vertx.ext.web.Route in project earth-snow by justlive1.
the class RouteRegisterFactory method register.
/**
* 讲Route注册到vertx中
*/
private void register() {
for (Map.Entry<String, RouteWrap> entry : routeWraps.entrySet()) {
RouteWrap wrap = entry.getValue();
VertxRouteMapping routeMapping = wrap.getRouteMapping();
Route route = router.route().path(entry.getKey());
for (String consume : routeMapping.consumes()) {
route.consumes(consume);
}
for (String produce : routeMapping.produces()) {
route.produces(produce);
}
for (HttpMethod method : routeMapping.method()) {
route.method(method);
}
Handler<RoutingContext> handler = ctx -> executeWithArgs(wrap, ctx);
if (routeMapping.blocking()) {
route.blockingHandler(handler);
} else {
route.handler(handler);
}
if (log.isDebugEnabled()) {
log.debug("register url [{}]", entry.getKey());
}
}
}
use of io.vertx.ext.web.Route in project vertx-zero by silentbalanceyh.
the class ZeroHttpAgent method registryServer.
private void registryServer(final HttpServerOptions options, final Router router) {
final Integer port = options.getPort();
final AtomicInteger out = ZeroAtomic.HTTP_START_LOGS.get(port);
if (Values.ZERO == out.getAndIncrement()) {
// 1. Build logs for current server;
final String portLiteral = String.valueOf(port);
LOGGER.info(Info.HTTP_SERVERS, this.getClass().getSimpleName(), this.deploymentID(), portLiteral);
final List<Route> routes = router.getRoutes();
final Map<String, Set<Route>> routeMap = new TreeMap<>();
final Set<String> tree = new TreeSet<>();
for (final Route route : routes) {
// 2.Route
if (null != route.getPath()) {
// Initial tree set.
if (!routeMap.containsKey(route.getPath())) {
routeMap.put(route.getPath(), new HashSet<>());
}
routeMap.get(route.getPath()).add(route);
}
// 3.Tree only need path here.
final String path = null == route.getPath() ? "/*" : route.getPath();
if (!"/*".equals(path)) {
tree.add(path);
}
}
routeMap.forEach((path, routeSet) -> routeSet.forEach(route -> LOGGER.info(Info.MAPPED_ROUTE, this.getClass().getSimpleName(), path, route.toString())));
// 3. Endpoint Publish
final String address = MessageFormat.format("http://{0}:{1}/", Ut.netIPv4(), portLiteral);
LOGGER.info(Info.HTTP_LISTEN, this.getClass().getSimpleName(), address);
// 4. Send configuration to Event bus
final String name = SERVICES.get(port);
this.startRegistry(name, options, tree);
}
}
use of io.vertx.ext.web.Route in project mbed-cloud-sdk-java by ARMmbed.
the class TestServer method definePingRoute.
private void definePingRoute() {
Route route = router.route(HttpMethod.GET, "/ping").produces(APPLICATION_JSON);
route.handler(routingContext -> {
execute(200, routingContext, new ServerAction() {
@Override
public Object execute() throws Exception {
return engine.ping();
}
}, false);
});
}
use of io.vertx.ext.web.Route in project mbed-cloud-sdk-java by ARMmbed.
the class TestServer method defineInitialisationRoute.
// TODO remove when not used anymore
private void defineInitialisationRoute() {
Route route = router.route(HttpMethod.GET, "/_init").produces(APPLICATION_JSON);
route.handler(routingContext -> {
execute(200, routingContext, new ServerAction() {
@Override
public Object execute() throws Exception {
return null;
}
}, false);
});
}
use of io.vertx.ext.web.Route in project mbed-cloud-sdk-java by ARMmbed.
the class TestServer method defineListInstancesRoute.
private void defineListInstancesRoute() {
Route route = router.route(HttpMethod.GET, "/instances").produces(APPLICATION_JSON);
route.blockingHandler(routingContext -> {
execute(200, routingContext, new ServerAction() {
@Override
public Object execute() throws Exception {
return engine.listAllModuleInstances().stream().map(m -> m.toInstance()).collect(Collectors.toList());
}
}, false);
});
}
Aggregations