当前位置: 首页>>代码示例>>Java>>正文


Java Router类代码示例

本文整理汇总了Java中io.vertx.rxjava.ext.web.Router的典型用法代码示例。如果您正苦于以下问题:Java Router类的具体用法?Java Router怎么用?Java Router使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Router类属于io.vertx.rxjava.ext.web包,在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
public void start(Future<Void> future) throws Exception {
  super.start();
  // TODO: 21.08.2017 use circuit breaker etc..
  String host = config().getString("http.host", "localhost");
  int port = config().getInteger("http.port", 8080);

  Router router = Router.router(vertx);
  enableLocalSession(router);
  router.route().handler(BodyHandler.create());
  router.get("/api/v").handler(this::apiVersion);

  // TODO: 23.08.2017 pac4j auth handlers

  // TODO: 23.08.2017 login, logout, auth callback, eventbus, etc..

  router.route("/api/*").handler(this::dispatchRequests);
  router.route("/*").handler(Status::notFound);

  // TODO: 23.08.2017 https? -> only if used without nginx

  createHttpServer(router, host, port)
      .flatMap(v -> publishApiGateway(host, port))
      .subscribe(toSubscriber(future));
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:26,代码来源:GatewayVerticle.java

示例2: enableCorsSupport

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
protected void enableCorsSupport(Router router) {
  Set<String> allowHeaders = new HashSet<>();
  allowHeaders.add("x-requested-with");
  allowHeaders.add("Access-Control-Allow-Origin");
  allowHeaders.add("origin");
  allowHeaders.add("Content-Type");
  allowHeaders.add("accept");
  router.route().handler(CorsHandler.create("*")
    .allowedHeaders(allowHeaders)
    .allowedMethod(HttpMethod.GET)
    .allowedMethod(HttpMethod.POST)
    .allowedMethod(HttpMethod.PUT)
    .allowedMethod(HttpMethod.DELETE)
    .allowedMethod(HttpMethod.PATCH)
    .allowedMethod(HttpMethod.OPTIONS)
  );
}
 
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:18,代码来源:RestAPIRxVerticle.java

示例3: RouteRegistrarCodeGenerator

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
public RouteRegistrarCodeGenerator(Models models) {
    this.models = models;
    Elements elementsUtil = models.getElemsUtil();
    stringType = elementsUtil.getTypeElement(String.class.getCanonicalName()).asType();
    routingCtxType = elementsUtil.getTypeElement(RoutingContext.class.getCanonicalName()).asType();
    routingCtxTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.RoutingContext.class.getCanonicalName()).asType();
    reqType = elementsUtil.getTypeElement(HttpServerRequest.class.getCanonicalName()).asType();
    reqTypeCore = elementsUtil.getTypeElement(io.vertx.core.http.HttpServerRequest.class.getCanonicalName()).asType();
    respType = elementsUtil.getTypeElement(HttpServerResponse.class.getCanonicalName()).asType();
    respTypeCore = elementsUtil.getTypeElement(io.vertx.core.http.HttpServerResponse.class.getCanonicalName()).asType();
    routeType = elementsUtil.getTypeElement(Route.class.getCanonicalName()).asType();
    routeTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.Route.class.getCanonicalName()).asType();
    routerType = elementsUtil.getTypeElement(Router.class.getCanonicalName()).asType();
    routerTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.Router.class.getCanonicalName()).asType();
    sessionType = elementsUtil.getTypeElement(Session.class.getCanonicalName()).asType();
    sessionTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.Session.class.getCanonicalName()).asType();
}
 
开发者ID:egopulse,项目名称:java-code-gen,代码行数:18,代码来源:RouteRegistrarCodeGenerator.java

示例4: start

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
public void start(Future<Void> future) throws Exception {

    Router router = Router.router(vertx);

    circuit = CircuitBreaker.create("circuit-breaker", vertx, new CircuitBreakerOptions()
        .setFallbackOnFailure(true)
        .setMaxFailures(3)
        .setResetTimeout(5000)
        .setTimeout(1000)
    );

    router.get("/").handler(this::getShoppingList);

    ServiceDiscovery.create(vertx, discovery -> {

        Single<WebClient> s1 = HttpEndpoint.rxGetWebClient(discovery,
            rec -> rec.getName().equals("shopping-backend"));
        Single<WebClient> s2 = HttpEndpoint.rxGetWebClient(discovery,
            rec -> rec.getName().equals("pricer-service"));

        Single.zip(s1, s2, (x, y) -> {
            shopping = x;
            pricer = y;
            return vertx.createHttpServer()
                .requestHandler(router::accept)
                .listen(8080);
        }).subscribe();
    });

}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:32,代码来源:MyShoppingList.java

示例5: start

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
public void start() {
    circuit = CircuitBreaker.create("circuit-breaker", vertx,
        new CircuitBreakerOptions()
            .setFallbackOnFailure(true)
            .setMaxFailures(3)
            .setResetTimeout(5000)
            .setTimeout(1000)
    );


    Router router = Router.router(vertx);
    router.route("/health").handler(rc ->
        rc.response().end("OK"));
    router.route("/").handler(this::getShoppingList);

    ServiceDiscovery.create(vertx, discovery -> {
        // Get pricer-service
        Single<WebClient> s1 = HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("pricer-service"));

        // Get shopping-backend
        Single<WebClient> s2 = HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("shopping-backend"));

        Single.zip(s1, s2, (p, s) -> {
            pricer = p;
            shopping = s;

            return vertx.createHttpServer()
                .requestHandler(router::accept)
                .listen(8080);
        }).subscribe();

        // When both are done...

    });
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:37,代码来源:MyShoppingList.java

示例6: start

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
public void start() {
    circuit = CircuitBreaker.create("circuit-breaker", vertx,
        new CircuitBreakerOptions()
            .setFallbackOnFailure(true)
            .setMaxFailures(3)
            .setResetTimeout(5000)
            .setTimeout(1000)
    );

    Router router = Router.router(vertx);
    router.route("/health").handler(rc -> rc.response().end("OK"));
    router.route("/").handler(this::getShoppingList);

    ServiceDiscovery.create(vertx, discovery -> {
        // Get pricer-service
        Single<WebClient> s1 = HttpEndpoint.rxGetWebClient(discovery,
            svc -> svc.getName().equals("pricer-service"));

        // Get shopping-backend
        Single<WebClient> s2 = HttpEndpoint.rxGetWebClient(discovery,
            svc -> svc.getName().equals("shopping-backend"));

        // When both are done...
        Single.zip(s1, s2, (p, s) -> {
            pricer = p;
            shopping = s;

            return vertx.createHttpServer()
                .requestHandler(router::accept)
                .listen(8080);
        })
            .subscribe();
    });


}
 
开发者ID:cescoffier,项目名称:vertx-rhsummit-2017,代码行数:38,代码来源:MyShoppingList.java

示例7: setupAuthenticationRoutes

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
protected AuthProvider setupAuthenticationRoutes() {
	JsonObject keycloackConfig = AppGlobals.get().getConfig().getJsonObject("keycloack");
	OAuth2Auth authWeb = KeycloakAuth.create(AppGlobals.get().getVertx(), keycloackConfig);
	OAuth2Auth authApi = KeycloakAuth.create(AppGlobals.get().getVertx(), OAuth2FlowType.PASSWORD, keycloackConfig);
	
	// FIXME: URL
	OAuth2AuthHandler authHandler = OAuth2AuthHandler.create((OAuth2Auth) authWeb, "http://localhost:9000/callback");
	Router router = AppGlobals.get().getRouter();
	// FIXME: crazy!!
	AuthProvider authProvider = AuthProvider.newInstance(authWeb.getDelegate());
	router.route().handler(UserSessionHandler.create(authProvider));

	authHandler.setupCallback(router.get("/callback"));
	
	JWTAuth jwtAuth = JWTAuth.create(AppGlobals.get().getVertx(), new JWTAuthOptions(new JsonObject()
			.put("keyStore", AppGlobals.get().getConfig().getJsonObject("keystore"))));
	AppGlobals.get().setGlobal(JWTAuth.class, jwtAuth);
	
	JWTAuthHandler jwtAuthHandler = JWTAuthHandler.create(jwtAuth, "/wiki/api/token");

	// FIXME: just use different routers
	router.route().handler(ctx -> {
		if(!ctx.request().uri().startsWith("/wiki/api/"))
			authHandler.handle(ctx);
		else
			jwtAuthHandler.handle(ctx);
	});
	
	return AuthProvider.newInstance(authApi.getDelegate());
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:32,代码来源:WikiServer.java

示例8: startVertx

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
private Single<Void> startVertx(JsonObject config, VertxResteasyDeployment deployment) {
	Router router = Router.router(vertx);
	AppGlobals.get().setRouter(router);
	
	VertxPluginRequestHandler resteasyHandler = new VertxPluginRequestHandler(vertx, deployment, plugins);
	
	return doOnPlugins(plugin -> plugin.preRoute())
			.map(v -> {
				setupRoutes(router);
				router.route().handler(routingContext -> {
					ResteasyProviderFactory.pushContext(RoutingContext.class, routingContext);
					resteasyHandler.handle(routingContext.request());
				});
				return null;
			}).flatMap(v -> doOnPlugins(plugin -> plugin.postRoute()))
			.flatMap(v -> {
				return Single.<Void>create(sub -> {
					// Start the front end server using the Jax-RS controller
					vertx.createHttpServer()
					.requestHandler(router::accept)
					.listen(config.getInteger("http_port", 9000), ar -> {
						if(ar.failed()){
							ar.cause().printStackTrace();
							sub.onError(ar.cause());
						}else {
							System.out.println("Server started on port "+ ar.result().actualPort());
							sub.onSuccess(null);
						}
					});
				});
			});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:33,代码来源:Server.java

示例9: setupRoutes

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
protected void setupRoutes(Router router) {
	router.route().handler(CookieHandler.create());
	
	SessionHandler sessionHandler = SessionHandler.create(LocalSessionStore.create(vertx));
	router.route().handler(sessionHandler);

	AuthProvider auth = setupAuthenticationRoutes();
	
	router.route().handler(context -> {
		ResteasyProviderFactory.pushContext(AuthProvider.class, auth);
		ResteasyProviderFactory.pushContext(User.class, context.user());
		ResteasyProviderFactory.pushContext(Session.class, context.session());
		context.next();
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:16,代码来源:Server.java

示例10: createHttpServer

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
protected final Single<Void> createHttpServer(Router router, String host, int port) {
  return vertx.createHttpServer(new HttpServerOptions()
      .setCompressionSupported(true)
      .setCompressionLevel(3))
              .requestHandler(router::accept)
              .rxListen(port, host)
              .map(server -> null);
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:9,代码来源:RestApiRxVerticle.java

示例11: RestRouter

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
private RestRouter(Vertx vertx, String serviceAddress, Class serviceClass, boolean mapRequestsToEventbus) {
  this.router = Router.router(vertx).exceptionHandler(thr -> log.error("EventbusRouter error", thr));
  this.vertx = vertx;
  this.address = serviceAddress;
  this.mapRequestsToEventbus = mapRequestsToEventbus;
  ifTrue(mapRequestsToEventbus, () -> serviceMethods.addAll(findServiceMethods(serviceClass)));
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:8,代码来源:RestApiRxVerticle.java

示例12: start

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
/**
 * Creates service for interacting with database.
 * Creates service for interacting with TheMovieDatabase API.
 * Creates service for interacting with bankLink application.
 * Creates service for interacting with mail server.
 * Creates Pac4j security engine configuration.
 * <p>
 * Creates authentication for routes.
 * Creates external API for TheMovieDatabase services.
 * Creates external API for bankLink services.
 * Creates Eventbus (aka Websocket for browsers) addresses for various services.
 * Creates external API for database services.
 * Creates external API for mail services.
 * Creates routes for UI rendering.
 * <p>
 * Starts the HTTP server.
 */
@Override
public void start(Future<Void> future) throws Exception {
  Router router = Router.router(vertx);
  database = createIfMissing(database, () -> DatabaseService.create(vertx, config()));
  tmdb = createIfMissing(tmdb, () -> TmdbService.create(vertx, config(), database));
  omdb = createIfMissing(omdb, () -> OmdbService.create(vertx, config(), database));
  bankLink = createIfMissing(bankLink, () -> BankLinkService.create(vertx, config()));
  mail = createIfMissing(mail, () -> MailService.create(vertx, database));
  recommend = createIfMissing(recommend, () -> RecommendService.create(vertx));
  securityConfig = createIfMissing(securityConfig, () -> new SecurityConfig(vertx, config(), database));
  Arrays.asList(
      new AuthRouter(vertx, config(), securityConfig),
      new TmdbRouter(vertx, tmdb),
      new OmdbRouter(vertx, omdb),
      new BankLinkRouter(vertx, bankLink),
      new DatabaseRouter(vertx, config(), securityConfig, database, mail),
      new MailRouter(vertx, mail),
      new RecommendRouter(recommend),
      new UiRouter(vertx, securityConfig)).forEach(routable -> routable.route(router));
  startEventbus(router, vertx);
  vertx.createHttpServer(new HttpServerOptions()
      .setCompressionSupported(true)
      .setCompressionLevel(3))
      .requestHandler(router::accept)
      .rxListen(config().getInteger(HTTP_PORT, DEFAULT_PORT), config().getString(HTTP_HOST, DEFAULT_HOST))
      .subscribe(res -> future.complete(), future::fail);
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:45,代码来源:ServerVerticle.java

示例13: route

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
/**
 * Enables UI routes.
 * Enables static files.
 */
@Override
public void route(Router router) {
  router.get(UI_INDEX).handler(this::handleLogin);
  router.get(UI_HOME).handler(this::handleHome);
  router.get(UI_LOGIN).handler(this::handleLogin);
  router.get(UI_FORM_LOGIN).handler(this::handleFormLogin);
  router.get(UI_FORM_REGISTER).handler(this::handleFormRegister);
  router.get(UI_IDCARDLOGIN).handler(this::handleIdCardLogin);
  router.get(UI_MOVIES).handler(this::handleMovies);
  router.get(UI_SERIES).handler(this::handleSeries);
  router.get(UI_HISTORY).handler(this::handleHistory);
  router.get(UI_STATISTICS).handler(this::handleStatistics);
  router.get(UI_DISCOVER).handler(this::handleDiscover);
  router.get(UI_LISTS).handler(this::handleLists);
  router.post(UI_DONATE_SUCCESS).handler(this::handleDonateSuccess);
  router.post(UI_DONATE_FAILURE).handler(this::handleDonateFailure);
  router.get(UI_RECOMMENDER).handler(this::handleRecommender);
  router.get(UI_DESC_TO_GENRE).handler(this::handleDescToGenre);

  boolean isProductionEnv = isRunningFromJar();
  String staticFilesPath = isProductionEnv ? STATIC_FOLDER : RESOURCES.resolve(STATIC_FOLDER).toString();
  router.get(STATIC_PATH).handler(StaticHandler.create(staticFilesPath)
      .setCachingEnabled(isProductionEnv)
      .setMaxAgeSeconds(DAYS.toSeconds(7))
      .setIncludeHidden(false));

  router.route("/fail").handler(ctx -> ctx.fail(555)); // TODO: 20.05.2017 remove
  router.route().failureHandler(this::handleFailure);
  router.get().last().handler(this::handleNotFound);
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:35,代码来源:UiRouter.java

示例14: route

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
public void route(Router router) {
    router.get(API_USER_INFO).handler(this::handleUserInfo);
    router.get(API_USERS_COUNT).handler(this::handleUsersCount);
    router.post(API_USERS_FORM_INSERT).handler(this::handleUsersFormInsert);
    router.get(API_HISTORY).handler(this::handleGetHistory);
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:8,代码来源:DatabaseRouter.java

示例15: route

import io.vertx.rxjava.ext.web.Router; //导入依赖的package包/类
@Override
public void route(Router router) {
    router.get(API_TMDB_GET_SEARCH).handler(this::handleApiGetSearch);
    router.get(API_TMDB_GET_MOVIE).handler(this::handleApiGetMovie);
    router.get(API_TMDB_GET_TV_SEARCH).handler(this::handleApiGetTVSearch);
    router.get(API_TMDB_GET_TV).handler(this::handleApiGetTV);
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:8,代码来源:TmdbRouter.java


注:本文中的io.vertx.rxjava.ext.web.Router类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。