当前位置: 首页>>代码示例>>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;未经允许,请勿转载。