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


Java HttpServer.requestHandler方法代碼示例

本文整理匯總了Java中io.vertx.core.http.HttpServer.requestHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServer.requestHandler方法的具體用法?Java HttpServer.requestHandler怎麽用?Java HttpServer.requestHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.http.HttpServer的用法示例。


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

示例1: start

import io.vertx.core.http.HttpServer; //導入方法依賴的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

示例2: testSyncAndWaitFiveSecondsForTimeOut

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
@Test
public void testSyncAndWaitFiveSecondsForTimeOut() throws Exception {
  // Create a server that will take a long time to reply to a request.
  final HttpServer timeOutHttpServer = vertx.createHttpServer();
  timeOutHttpServer.requestHandler(
      e -> {
        try {
          Thread.sleep(100000);
        } catch (InterruptedException ex) {
          ex.printStackTrace();
        }
      });
  timeOutHttpServer.listen(TIMEOUT_SERVER_PORT);

  // Send a request synchronously and wait 5 seconds for a response.
  doSync(e -> vertx.createHttpClient().getNow(TIMEOUT_SERVER_PORT, HOST, URI, e::complete), 5);
}
 
開發者ID:StephenFox1995,項目名稱:vertx-sync,代碼行數:18,代碼來源:SyncTest.java

示例3: async_05

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
public static void async_05(TestContext context, Vertx vertx, Handler<HttpServerRequest> requestHandler) {
  Async async = context.async(2);
  HttpServer server = vertx.createHttpServer();
  server.requestHandler(requestHandler);
  server.listen(8080, ar -> {
    context.assertTrue(ar.succeeded());
    async.countDown();
  });

  vertx.setTimer(1000, id -> {
    async.complete();
  });

  // Wait until completion of the timer and the http request
  async.awaitSuccess();

  // Do something else
}
 
開發者ID:vert-x3,項目名稱:vertx-unit,代碼行數:19,代碼來源:Examples.java

示例4: testRedirect

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
private void testRedirect(TestContext context, int responseStatus) {
  vertx = Vertx.vertx();
  HttpServer redirectServer = vertx.createHttpServer();
  redirectServer.requestHandler(req -> {
    HttpServerResponse resp = req.response();
    resp.setStatusCode(responseStatus);
    resp.putHeader("Location", "http://localhost:8080/the_verticle.zip");
    resp.end();
  });
  HttpServer server = new RepoBuilder().setVerticle(verticleWithMain).build();
  redirectServer.listen(8081, context.asyncAssertSuccess(r -> {
    server.listen(
        8080,
        context.asyncAssertSuccess(s -> {
          vertx.deployVerticle("http://localhost:8081/the_verticle.zip", context.asyncAssertSuccess());
        })
    );
  }));
}
 
開發者ID:vert-x3,項目名稱:vertx-http-service-factory,代碼行數:20,代碼來源:DeploymentTest.java

示例5: start

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
   HttpServer server = vertx.createHttpServer();
   
   server.requestHandler(request -> {
      LOG.info("Web request arrived");
      
      
      if (request.path().endsWith("index.html")) {
         request.response().putHeader("content-type", "text/html");
         request.response().sendFile("src/main/webroot/index.html");
      } else {
         request.response().setChunked(true);
         request.response().putHeader("content-type", "text/plain");
         request.response().write("No such file!!");
         request.response().setStatusCode(404);
         request.response().end();
      }
   });
   
   server.listen();
   super.start();
}
 
開發者ID:chuidiang,項目名稱:chuidiang-ejemplos,代碼行數:24,代碼來源:WebServerVerticle.java

示例6: testTLS

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
private void testTLS(WebClientOptions clientOptions, HttpServerOptions serverOptions, Function<WebClient, HttpRequest<Buffer>> requestProvider, Consumer<HttpServerRequest> serverAssertions) throws Exception {
  WebClient sslClient = WebClient.create(vertx, clientOptions);
  HttpServer sslServer = vertx.createHttpServer(serverOptions);
  sslServer.requestHandler(req -> {
    assertEquals(serverOptions.isSsl(), req.isSSL());
    if (serverAssertions != null) {
      serverAssertions.accept(req);
    }
    req.response().end();
  });
  try {
    startServer(sslServer);
    HttpRequest<Buffer> builder = requestProvider.apply(sslClient);
    builder.send(onSuccess(resp -> testComplete()));
    await();
  } finally {
    sslClient.close();
    sslServer.close();
  }
}
 
開發者ID:vert-x3,項目名稱:vertx-web,代碼行數:21,代碼來源:WebClientTest.java

示例7: start

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
public void start() throws Exception {

		JsonObject conf = vertx.getOrCreateContext().config();
		
		HttpServerOptions options =  new HttpServerOptions();
		options.setCompressionSupported(true);		
		
		HttpServer server = vertx.createHttpServer(options);
				
		/*
		    <property name="inside.host">172.18.7.20</property>
   			<property name="inside.port">8999</property>
		 */
		String host = conf.getString("inside.host");
		String port = conf.getString("inside.port");		
		
		if(S.isBlank(host) || S.isBlank(port))
			return;

		// ============初始化======================

		this.upload_dir = conf.getString("upload.dir");

		this.webclient = WebClient.create(vertx);

		this.appContain = gsetting.getAppContain(vertx,this.webclient);
						 
		this.initRoutes();
		
		server.requestHandler(router::accept);
		server.listen(Integer.parseInt(port), host,ar -> {
			if (ar.succeeded()) {
				log.info("InsideServer listen on " + port);
			} else {
				log.error("InsideServer Failed to start!", ar.cause());
			}
		});		

	}
 
開發者ID:troopson,項目名稱:etagate,代碼行數:40,代碼來源:InsideServerVerticle.java

示例8: start

import io.vertx.core.http.HttpServer; //導入方法依賴的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());
			}
		});
}
 
開發者ID:Ithildir,項目名稱:actions-on-google-vertx-sample,代碼行數:28,代碼來源:NumbersGameVerticle.java

示例9: main

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
public static void main(String[] args) {
    System.out.println("Here we go!");
    final Vertx vertx = Vertx.vertx();
    HttpServer httpServer = vertx.createHttpServer();
    httpServer.requestHandler(request -> {
        System.out.println(request.absoluteURI());
        System.out.println(request.method());
        vertx.eventBus().send("latest-news", "Request Received to: " + request.path());
        HttpServerResponse response = request.response();
        response.end("Message Received");
    });
    httpServer.listen(8082, httpServerAsyncResult -> {
        if (httpServerAsyncResult.succeeded()) {
            System.out.println("Server is bound: " + httpServerAsyncResult.result().actualPort());
        } else if (httpServerAsyncResult.failed()) {
            System.out.println("Unable to set up server");
            httpServerAsyncResult.cause().printStackTrace();
        }
    });
    vertx.deployVerticle(new MyVerticle(), event -> {
        if(event.succeeded()) {
            System.out.println("Verticle deployed");
        } else if (event.failed()) {
            System.out.println("No Verticle deployed");
            event.cause().printStackTrace();
        }
    });
}
 
開發者ID:dhinojosa,項目名稱:intro_to_reactive,代碼行數:29,代碼來源:VertxHttpServer.java

示例10: prepareServer

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
HttpServer prepareServer(Vertx vertx) {
    HttpServer server = vertx.createHttpServer();

    Router router = Router.router(vertx);
    router.route().handler(LoggerHandler.create());
    router.get("/speech").handler(this::speechHandler);
    router.get().handler(StaticHandler.create("static"));

    server.requestHandler(router::accept);
    return server;
}
 
開發者ID:amdw,項目名稱:boilerplate,代碼行數:12,代碼來源:VertxWebApp.java

示例11: createServer

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
@Override
protected TermServer createServer(TestContext context, HttpTermOptions options) {
  HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  Router router = Router.router(vertx);
  Router subRouter = Router.router(vertx);
  router.mountSubRouter("/sub", subRouter);
  httpServer.requestHandler(router::accept);
  Async async = context.async();
  httpServer.listen(8080, context.asyncAssertSuccess(s -> {
    async.complete();
  }));
  async.awaitSuccess(20000);
  return TermServer.createHttpTermServer(vertx, subRouter, options);
}
 
開發者ID:vert-x3,項目名稱:vertx-shell,代碼行數:15,代碼來源:HttpTermServerSubRouterTest.java

示例12: async_04

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
public static void async_04(TestContext context, Vertx vertx, Handler<HttpServerRequest> requestHandler) {
  Async async = context.async();
  HttpServer server = vertx.createHttpServer();
  server.requestHandler(requestHandler);
  server.listen(8080, ar -> {
    context.assertTrue(ar.succeeded());
    async.complete();
  });

  // Wait until completion
  async.awaitSuccess();

  // Do something else
}
 
開發者ID:vert-x3,項目名稱:vertx-unit,代碼行數:15,代碼來源:Examples.java

示例13: start

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
@Override
public void start() throws Exception {
    super.start();
    HttpServer server = getVertx().createHttpServer(new HttpServerOptions().setPort(8080));
    server.requestHandler(req -> req.response().end(responseBody(req)));
    server.listen();
}
 
開發者ID:millross,項目名稱:simple-vertx3,代碼行數:8,代碼來源:DemoVerticle.java

示例14: testPreventRedirectLoop

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
@Test
public void testPreventRedirectLoop(TestContext context) {
  vertx = Vertx.vertx();
  HttpServer redirectServer = vertx.createHttpServer();
  redirectServer.requestHandler(req -> {
    HttpServerResponse resp = req.response();
    resp.setStatusCode(301);
    resp.putHeader("Location", "http://localhost:8080/the_verticle.zip");
    resp.end();
  });
  redirectServer.listen(8080, context.asyncAssertSuccess(r -> {
    vertx.deployVerticle("http://localhost:8080/the_verticle.zip", context.asyncAssertFailure());
  }));
}
 
開發者ID:vert-x3,項目名稱:vertx-http-service-factory,代碼行數:15,代碼來源:DeploymentTest.java

示例15: testMetricsCleanupedOnVertxClose

import io.vertx.core.http.HttpServer; //導入方法依賴的package包/類
@Test
public void testMetricsCleanupedOnVertxClose() throws Exception {
  CountDownLatch latch1 = new CountDownLatch(1);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestHandler(req -> {});
  server.listen(onSuccess(res -> {
    latch1.countDown();
  }));
  awaitLatch(latch1);
  HttpClient client = vertx.createHttpClient(new HttpClientOptions());
  CountDownLatch latch2 = new CountDownLatch(1);
  NetServer nServer = vertx.createNetServer(new NetServerOptions().setPort(1234));
  nServer.connectHandler(conn -> {});
  nServer.listen(res -> {
    latch2.countDown();
  });
  awaitLatch(latch2);
  NetClient nClient = vertx.createNetClient(new NetClientOptions());
  DatagramSocket sock = vertx.createDatagramSocket(new DatagramSocketOptions());
  EventBus eb = vertx.eventBus();
  assertFalse(metricsService.getMetricsSnapshot(vertx).isEmpty());
  assertFalse(metricsService.getMetricsSnapshot(server).isEmpty());
  assertFalse(metricsService.getMetricsSnapshot(client).isEmpty());
  assertFalse(metricsService.getMetricsSnapshot(nServer).isEmpty());
  assertFalse(metricsService.getMetricsSnapshot(nClient).isEmpty());
  assertFalse(metricsService.getMetricsSnapshot(sock).isEmpty());
  assertFalse(metricsService.getMetricsSnapshot(eb).isEmpty());
  vertx.close(res -> {
    assertTrue(metricsService.getMetricsSnapshot(vertx).isEmpty());
    assertTrue(metricsService.getMetricsSnapshot(server).isEmpty());
    assertTrue(metricsService.getMetricsSnapshot(client).isEmpty());
    assertTrue(metricsService.getMetricsSnapshot(nServer).isEmpty());
    assertTrue(metricsService.getMetricsSnapshot(nClient).isEmpty());
    assertTrue(metricsService.getMetricsSnapshot(sock).isEmpty());
    assertTrue(metricsService.getMetricsSnapshot(eb).isEmpty());
    testComplete();
  });
  await();
  vertx = null;
}
 
開發者ID:vert-x3,項目名稱:vertx-dropwizard-metrics,代碼行數:41,代碼來源:MetricsTest.java


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