當前位置: 首頁>>代碼示例>>Java>>正文


Java Router類代碼示例

本文整理匯總了Java中io.vertx.ext.web.Router的典型用法代碼示例。如果您正苦於以下問題:Java Router類的具體用法?Java Router怎麽用?Java Router使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Router類屬於io.vertx.ext.web包,在下文中一共展示了Router類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Override
public void start() throws Exception {
	Router router = Router.router(vertx);
	int serverPort = Config.getIntValue("serverPort");
	
	router.route().handler(BodyHandler.create().setUploadsDirectory("files"));
	router.route().handler(CookieHandler.create());
	router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
	router.route().handler(CORSHandler.create());
	router.route().handler(LogHandler.create());
	Routing.route(router, "com.planb.restful");
	
	router.route().handler(StaticHandler.create());
	
	Log.info("Server Started At : " + serverPort);
	vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
 
開發者ID:JoMingyu,項目名稱:Server-Quickstart-Vert.x,代碼行數:18,代碼來源:MainVerticle.java

示例2: handleRequest

import io.vertx.ext.web.Router; //導入依賴的package包/類
/**
 * This is a handler method called by the AWS Lambda runtime
 */
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {

    // Lambda function is allowed write access to /tmp only
    System.setProperty("vertx.cacheDirBase", "/tmp/.vertx");

    Vertx vertx = Vertx.vertx();

    router = Router.router(vertx);

    router.route().handler(rc -> {
        LocalDateTime now = LocalDateTime.now();
        rc.response().putHeader("content-type", "text/html").end("Hello from Lambda at " + now);
    });

    // create a LambdaServer which will process a single HTTP request
    LambdaServer server = new LambdaServer(vertx, context, input, output);

    // trigger the HTTP request processing
    server.requestHandler(this::handleRequest).listen();

    // block the main thread until the request has been fully processed
    waitForResponseEnd();
}
 
開發者ID:noseka1,項目名稱:vertx-aws-lambda,代碼行數:28,代碼來源:SampleApp.java

示例3: extendedContentTypeTest

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Test
public void extendedContentTypeTest(TestContext context) {

	RestRouter.getReaders().register(Dummy.class, DummyBodyReader.class);

	TestReaderRest testRest = new TestReaderRest();

	Router router = RestRouter.register(vertx, testRest);

	vertx.createHttpServer()
	     .requestHandler(router::accept)
	     .listen(PORT);

	final Async async = context.async();
	client.post("/read/normal/dummy", response -> {

		context.assertEquals(200, response.statusCode());

		response.handler(body -> {
			context.assertEquals("one=dummy", body.toString()); // returns sorted list of unique words
			async.complete();
		});
	}).putHeader("Content-Type", "application/json;charset=UTF-8")
	      .end(JsonUtils.toJson(new Dummy("one", "dummy")));
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:26,代碼來源:CustomReaderTest.java

示例4: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
  super.start();

  // 如果本地未配置地址,則表示不必監聽,隻需要作為客戶端使用即可
  if (endpointObject == null) {
    LOGGER.warn("rest listen address is not configured, will not start.");
    startFuture.complete();
    return;
  }

  Router mainRouter = Router.router(vertx);
  mountAccessLogHandler(mainRouter);
  initDispatcher(mainRouter);

  HttpServer httpServer = createHttpServer();
  httpServer.requestHandler(mainRouter::accept);

  startListen(httpServer, startFuture);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:21,代碼來源:RestServerVerticle.java

示例5: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Override
public void start(final Future<Void> startFuture) throws Exception {

    HttpServer http = vertx.createHttpServer();

    Router router = Router.router(vertx);
    router.get("/hello").handler(ctx -> ctx.response().end("World " + System.currentTimeMillis()));

    http.requestHandler(router::accept).listen(11011, result -> {
        if(result.succeeded()){
            System.out.println("Listening on port 11011");
        } else {
            throw new RuntimeException("Server start failed");
        }
    });

}
 
開發者ID:gmuecke,項目名稱:grafana-vertx-datasource,代碼行數:18,代碼來源:BackupVerticle.java

示例6: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Before
public void start(TestContext context) {

	super.before(context);

	Router router = new RestBuilder(vertx)
		.register(TestMultiProducesRest.class)
		.writer(MediaType.APPLICATION_XML, TestXmlResponseWriter.class)
		.writer(MediaType.APPLICATION_JSON, TestJsonResponseWriter.class)
		.build();


	vertx.createHttpServer()
		.requestHandler(router::accept)
		.listen(PORT);
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:17,代碼來源:RouteWithMultiProducesTest.java

示例7: dynamicPages

import io.vertx.ext.web.Router; //導入依賴的package包/類
private void dynamicPages(Router router) {
  HandlebarsTemplateEngine hbsEngine = new ClasspathAwareHandlebarsTemplateEngine();

  hbsEngine.setMaxCacheSize(applicationConfiguration.getViewTemplateCacheSize());

  TemplateHandler templateHandler = TemplateHandler.create(hbsEngine);

  if (applicationConfiguration.isAuthenticationEnabled()) {
    router.get(WebServerUtils.withApplicationName("dataset/*")).handler(this::fromSession);
    router.get(WebServerUtils.withApplicationName("management/*")).handler(this::fromSession);
  }

  router
      .getWithRegex(".+\\.hbs")
      .handler(
          context -> {
            final Session session = context.session();
            WebServerUtils.assignUserToRoutingContext(context);
            context.next();
          });

  router.getWithRegex(".+\\.hbs").handler(templateHandler);
}
 
開發者ID:glytching,項目名稱:dragoman,代碼行數:24,代碼來源:WebServerVerticle.java

示例8: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Before
public void start(TestContext context) {

	super.before(context);

	TestContextRest testRest = new TestContextRest();

	Router router = RestRouter.register(vertx, testRest);
	//RestRouter.provide(router, TokenProvider.class);

	RestRouter.addProvider(Dummy.class, request -> new Dummy("test", "name"));
	RestRouter.addProvider(TokenProvider.class);

	vertx.createHttpServer()
	     .requestHandler(router::accept)
	     .listen(PORT);
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:18,代碼來源:RouteWithContextProviderTest.java

示例9: testCustomInput_2

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Test
public void testCustomInput_2(TestContext context) {

	RestRouter.getReaders()
	          .register(List.class,
	                    CustomWordListReader.class); // all arguments that are List<> go through this reader ... (reader returns List<String> as output)

	Router router = RestRouter.register(vertx, TestReaderRest.class);
	vertx.createHttpServer()
	     .requestHandler(router::accept)
	     .listen(PORT);


	// call and check response
	final Async async = context.async();

	client.post("/read/registered", response -> {

		context.assertEquals(200, response.statusCode());

		response.handler(body -> {
			context.assertEquals("brown,dog,fox,jumps,over,quick,red,the", body.toString()); // returns sorted list of unique words
			async.complete();
		});
	}).end("The quick brown fox jumps over the red dog!");
}
 
開發者ID:zandero,項目名稱:rest.vertx,代碼行數:27,代碼來源:CustomReaderTest.java

示例10: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Override
public void start(final Future<Void> startFuture) throws Exception {
    final Router router = router();

    new Endpoints(vertx, router).initialize();

    final int port = config().getInteger("http.port", 8080);
    vertx.createHttpServer()
            .requestHandler(router::accept)
            .listen(port,
                    result -> {
                        if (result.succeeded()) {
                            LOG.info("Started API on port " + port);
                            startFuture.complete();
                        } else {
                            startFuture.fail(result.cause());
                        }
                    });
}
 
開發者ID:yyunikov,項目名稱:vertx-gradle-starter,代碼行數:20,代碼來源:ApiVerticle.java

示例11: initialize

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Override
protected void initialize() {
	
	discovery = discoveryHolder.getServiceDiscovery();
	circuitBreaker = circuitBreakerHolder.getCircuitBreaker();

	Router router = router();
	enableHeartbeatCheck(router);

	String address = getAddress();
	Integer port = getApiPort();
	
	setup();
	
	HttpServerBuilder.create(vertx).router(router).httpServerOptions(httpServerOptions()).build().listen(port, address,
			this::onHttpServer);
}
 
開發者ID:pflima92,項目名稱:jspare-vertx-ms-blueprint,代碼行數:18,代碼來源:RestAPIVerticle.java

示例12: setUp

import io.vertx.ext.web.Router; //導入依賴的package包/類
@Before
public void setUp() throws Exception {

    vertx = Vertx.vertx();
    JsonObject config = vertx.getOrCreateContext().config();
    Router router = Router.router(vertx);
    configuration = new VertxConfiguration(config);
    configuration.put(SSL_CONFIGURATION_KEY, FALSE);
    configuration.put(SSL_JKS_PATH, TEST_JKS_PATH);
    configuration.put(SSL_JKS_SECRET, TEST_JKS_SECRET);
    configuration.put(HTTPS_PORT, DEFAULT_HTTPS_PORT);
    options = new HttpServerOptions();
    context = VertxContext.VertxContextBuilder.vertx(vertx)
            .router(router)
            .serverConfiguration(configuration)
            .vertxServiceDiscovery(new VertxServiceDiscovery(vertx)).build();
}
 
開發者ID:GwtDomino,項目名稱:domino,代碼行數:18,代碼來源:JksServerConfiguratorTest.java

示例13: start

import io.vertx.ext.web.Router; //導入依賴的package包/類
public void start() {
    sdk = null;
    config = null;
    if (server == null) {
        Vertx vertx = Vertx
                .vertx(new VertxOptions().setWorkerPoolSize(40).setBlockedThreadCheckInterval(1000L * 60L * 10L)
                        .setMaxWorkerExecuteTime(1000L * 1000L * 1000L * 60L * 10L));
        HttpServerOptions options = new HttpServerOptions();
        options.setMaxInitialLineLength(HttpServerOptions.DEFAULT_MAX_INITIAL_LINE_LENGTH * 2);
        server = vertx.createHttpServer(options);
        router = Router.router(vertx);
    }
    retrieveConfig();
    if (config == null || config.isApiKeyEmpty()) {
        logError("Unable to find " + String.valueOf(ENVVAR_MBED_CLOUD_API_KEY) + " environment variable");
        System.exit(1);
    }
    defineInitialisationRoute();
    defineModuleMethodTestRoute();
    logInfo("Starting Java SDK test server on port " + String.valueOf(port) + "...");
    server.requestHandler(router::accept).listen(port);
}
 
開發者ID:ARMmbed,項目名稱:mbed-cloud-sdk-java,代碼行數:23,代碼來源:TestServer.java

示例14: register

import io.vertx.ext.web.Router; //導入依賴的package包/類
/**
 * Register this but also register the {@link CorsHandler}. The
 * {@link CorsHandler} will deal with the normal CORS headers after it has been
 * processed initially by this handler. {@inheritDoc}
 */
@Override
public void register(final Router router) {

    router.route().handler(this);

    router.route().handler(CorsHandler.create(".+")
        .maxAgeSeconds(600)
        .allowedMethod(HttpMethod.GET)
        .allowedMethod(HttpMethod.POST)
        .allowedMethod(HttpMethod.PUT)
        .allowedMethod(HttpMethod.DELETE)
        .allowedMethod(HttpMethod.OPTIONS)
        .allowedHeader("Content-Type")
        .allowedHeader("Accept")
        .allowedHeader("Accept-Language")
        .allowedHeader("Authorization"));

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:24,代碼來源:AuthenticatedClientValidator.java

示例15: startHttpServer

import io.vertx.ext.web.Router; //導入依賴的package包/類
private Future<Void> startHttpServer() {
  Future<Void> future = Future.future();
  HttpServer server = vertx.createHttpServer();   // <1>

  Router router = Router.router(vertx);   // <2>
  router.get("/").handler(this::indexHandler);
  router.get("/wiki/:page").handler(this::pageRenderingHandler); // <3>
  router.post().handler(BodyHandler.create());  // <4>
  router.post("/save").handler(this::pageUpdateHandler);
  router.post("/create").handler(this::pageCreateHandler);
  router.post("/delete").handler(this::pageDeletionHandler);

  server
    .requestHandler(router::accept)   // <5>
    .listen(8080, ar -> {   // <6>
      if (ar.succeeded()) {
        LOGGER.info("HTTP server running on port 8080");
        future.complete();
      } else {
        LOGGER.error("Could not start a HTTP server", ar.cause());
        future.fail(ar.cause());
      }
    });

  return future;
}
 
開發者ID:vert-x3,項目名稱:vertx-guide-for-java-devs,代碼行數:27,代碼來源:MainVerticle.java


注:本文中的io.vertx.ext.web.Router類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。