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


Java HttpServer.listen方法代码示例

本文整理汇总了Java中io.vertx.core.http.HttpServer.listen方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.listen方法的具体用法?Java HttpServer.listen怎么用?Java HttpServer.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.http.HttpServer的用法示例。


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

示例1: startListen

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
private void startListen(HttpServer server, Future<Void> startFuture) {
  server.listen(endpointObject.getPort(), endpointObject.getHostOrIp(), ar -> {
    if (ar.succeeded()) {
      LOGGER.info("rest listen success. address={}:{}",
          endpointObject.getHostOrIp(),
          ar.result().actualPort());
      startFuture.complete();
      return;
    }

    String msg = String.format("rest listen failed, address=%s:%d",
        endpointObject.getHostOrIp(),
        endpointObject.getPort());
    LOGGER.error(msg, ar.cause());
    startFuture.fail(ar.cause());
  });
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源: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: testValidJWT

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testValidJWT(TestContext context) throws URISyntaxException {
    HttpServer openIdMockServer = this.createOpenIdMockServer(CERTS_VALID);
    Async openIdStarted = context.async();
    openIdMockServer.listen(TestConfig.OPENID_PORT, context.asyncAssertSuccess(i -> openIdStarted.complete()));
    openIdStarted.awaitSuccess(5000);
    JsonObject config = TestConfig.getApiConfig();
    config.getJsonObject("auth").put("enable", true);
    deployApiVerticle(context, config);

    createSslRequest("/api/v1.0/pr/latest")
            .putHeader("Authorization", "Bearer " + JWT_TOKEN)
            .send(context.asyncAssertSuccess(res ->
                    context.assertEquals(200, res.statusCode())
            ));
    openIdMockServer.close(context.asyncAssertSuccess());
}
 
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:18,代码来源:AuthTest.java

示例4: 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

示例5: 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

示例6: testDeployFromAuthenticatedRepo

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testDeployFromAuthenticatedRepo(TestContext context) {
  System.setProperty(HttpServiceFactory.AUTH_USERNAME_PROPERTY, "the_username");
  System.setProperty(HttpServiceFactory.AUTH_PASSWORD_PROPERTY, "the_password");
  vertx = Vertx.vertx();
  HttpServer server = new RepoBuilder().setVerticle(verticleWithMain).setAuthenticated(true).build();
  Async async = context.async();
  server.listen(
      8080,
      context.asyncAssertSuccess(s -> {
        vertx.deployVerticle("http://localhost:8080/the_verticle.zip", ar -> {
          context.assertTrue(ar.failed());
          async.complete();
        });
      })
  );
}
 
开发者ID:vert-x3,项目名称:vertx-http-service-factory,代码行数:18,代码来源:DeploymentTest.java

示例7: 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

示例8: start

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
    //TODO: Fix a better way of configuration other than system properties?
    Integer port = Integer.getInteger("websocket.port", 5556);

    ObservableFuture<HttpServer> httpServerObservable = RxHelper.observableFuture();
    HttpServer httpServer = vertx.createHttpServer(new HttpServerOptions().setPort(port));
    httpServerObservable.subscribe(
            a -> log.info("Starting web socket listener..."),
            e -> log.error("Could not start web socket listener at port " + port, e),
            () -> log.info("Started web socket listener on port " + port)
    );

    Observable<Tup2<ServerWebSocket, Func1<Event, Boolean>>> eventObservable = EventObservable.convertFromWebSocketObservable(RxHelper.toObservable(httpServer.websocketStream()));
    eventObservable.subscribe(new EventToJsonAction(Riemann.getEvents(vertx), WebSocketFrameImpl::new), e -> {
        log.error(e);
        //TODO: Fix proper error handling
    });

    httpServer.listen(httpServerObservable.asHandler());
}
 
开发者ID:blakepettersson,项目名称:reactmann,代码行数:22,代码来源:WebSocketVerticle.java

示例9: 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

示例10: testHttpToHttp

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testHttpToHttp(TestContext ctx) throws Exception {
  Async async = ctx.async();
  Router router = Router.router(vertx);
  HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
  Flow flow = Flow.flow(vertx)
    .withDiscovery(discovery);
  flow.route(router.get("/foo"), httpFlow -> {
    httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertSuccess(req -> {
      req.send(ctx.asyncAssertSuccess(resp -> {
        ctx.assertEquals(200, resp.statusCode());
        httpFlow.response().end(resp.body());
        async.complete();
      }));
    }));
  });
  Async listenAsync = ctx.async();
  server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
  listenAsync.awaitSuccess(10000);
  startBackendBlocking(ctx);
  publishBackendBlocking(ctx);
  client
    .get(8080, "localhost", "/foo")
    .send(ctx.asyncAssertSuccess(resp -> {
      ctx.assertEquals(200, resp.statusCode());
      ctx.assertEquals("Hello World", resp.bodyAsString());
    }));
}
 
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:29,代码来源:FlowTest.java

示例11: testCircuitBreakerOpen

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testCircuitBreakerOpen(TestContext ctx) throws Exception {
  Async async = ctx.async();
  Router router = Router.router(vertx);
  HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
  Flow flow = Flow.flow(vertx)
    .withDiscovery(discovery);
  flow.route(router.get("/foo"), httpFlow -> {
    AtomicInteger count = new AtomicInteger(6);
    doRec(6, fut -> {
      httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertFailure(v1 -> {
        CircuitBreakerState state = flow.breaker("hello-service").state();
        int val = count.decrementAndGet();
        if (val == 0) {
          ctx.assertEquals(CircuitBreakerState.OPEN, state);
          httpFlow.response().end("failed");
          async.complete();
        } else if (val == 1) {
          ctx.assertEquals(CircuitBreakerState.OPEN, state);
        } else {
          ctx.assertEquals(CircuitBreakerState.CLOSED, state);
        }
        fut.complete();
      }));
    });
  });
  Async listenAsync = ctx.async();
  server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
  listenAsync.awaitSuccess(10000);
  client
    .get(8080, "localhost", "/foo")
    .send(ctx.asyncAssertSuccess(resp -> {
      ctx.assertEquals(200, resp.statusCode());
      ctx.assertEquals("failed", resp.bodyAsString());
    }));
}
 
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:37,代码来源:FlowTest.java

示例12: testCircuitBreakerLookupFail

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
@Test
public void testCircuitBreakerLookupFail(TestContext ctx) throws Exception {
  Async async = ctx.async();
  Router router = Router.router(vertx);
  HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
  Flow flow = Flow.flow(vertx)
    .withDiscovery(discovery)
    .withBreaker(new CircuitBreakerOptions());
  flow.route(router.get("/foo"), httpFlow -> {
    httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertFailure(v1 -> {
      publishBackend(ctx, v2 -> {
        httpFlow.httpRequest(new JsonObject().put("name", "hello-service"), HttpMethod.GET, "/", ctx.asyncAssertSuccess(req -> {
          req.send(ctx.asyncAssertSuccess(resp -> {
            ctx.assertEquals(200, resp.statusCode());
            httpFlow.response().end(resp.body());
            async.complete();
          }));
        }));
      });
    }));
  });
  Async listenAsync = ctx.async();
  server.listen(8080, ctx.asyncAssertSuccess(v -> listenAsync.complete()));
  listenAsync.awaitSuccess(10000);
  startBackendBlocking(ctx);
  client
    .get(8080, "localhost", "/foo")
    .send(ctx.asyncAssertSuccess(resp -> {
      ctx.assertEquals(200, resp.statusCode());
      ctx.assertEquals("Hello World", resp.bodyAsString());
    }));
}
 
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:33,代码来源:FlowTest.java

示例13: 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

示例14: 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

示例15: testFailingAuth

import io.vertx.core.http.HttpServer; //导入方法依赖的package包/类
private void testFailingAuth(TestContext context, HttpServer openIdServer, String jwtToken) {
    Async openIdStarted = context.async();
    openIdServer.listen(TestConfig.OPENID_PORT, context.asyncAssertSuccess(i -> openIdStarted.complete()));
    openIdStarted.awaitSuccess(5000);
    JsonObject config = TestConfig.getApiConfig();
    config.getJsonObject("auth").put("enable", true);
    deployApiVerticle(context, config);

    createSslRequest("/api/v1.0/am/latest")
            .putHeader("Authorization", "Bearer " + jwtToken)
            .send(context.asyncAssertSuccess(res ->
                    context.assertEquals(401, res.statusCode())
            ));
    openIdServer.close(context.asyncAssertSuccess());
}
 
开发者ID:Deutsche-Boerse-Risk,项目名称:DAVe,代码行数:16,代码来源:AuthTest.java


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