• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HttpServer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: delayToObservable

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
public void delayToObservable(HttpServer server) {
  server.requestHandler(request -> {
    if (request.method() == HttpMethod.POST) {

      // Stop receiving buffers
      request.pause();

      checkAuth(res -> {

        // Now we can receive buffers again
        request.resume();

        if (res.succeeded()) {
          Observable<Buffer> observable = request.toObservable();
          observable.subscribe(buff -> {
            // Get buffers
          });
        }
      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:23,代码来源:RxifiedExamples.java


示例2: testDeploy

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testDeploy() throws Exception {
  AtomicInteger count = new AtomicInteger();
  vertx.deployVerticle(new AbstractVerticle() {
    @Override
    public void start() throws Exception {
      HttpServer s1 = vertx.createHttpServer(new HttpServerOptions().setPort(8080)).requestHandler(req -> {
      });
      HttpServer s2 = vertx.createHttpServer(new HttpServerOptions().setPort(8081)).requestHandler(req -> {
      });
      Observable<HttpServer> f1 = s1.listenObservable();
      Observable<HttpServer> f2 = s2.listenObservable();
      Action1<HttpServer> done = server -> {
        if (count.incrementAndGet() == 2) {
          testComplete();
        }
      };
      f1.subscribe(done);
      f2.subscribe(done);
    }
  });
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:24,代码来源:CoreRxifiedApiTest.java


示例3: testObserverToFuture

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testObserverToFuture() {
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080)).requestHandler(req -> {});
  AtomicInteger count = new AtomicInteger();
  Observer<HttpServer> observer = new Observer<HttpServer>() {
    @Override
    public void onCompleted() {
      server.close();
      assertEquals(1, count.get());
      testComplete();
    }

    @Override
    public void onError(Throwable e) {
      fail(e.getMessage());
    }

    @Override
    public void onNext(HttpServer httpServer) {
      count.incrementAndGet();
    }
  };
  Observable<HttpServer> onListen = server.listenObservable();
  onListen.subscribe(observer);
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:27,代码来源:CoreApiTest.java


示例4: testHttpClient

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testHttpClient() {
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> {
    req.response().setChunked(true).end("some_content");
  });
  try {
    server.listen(ar -> {
      HttpClient client = vertx.createHttpClient(new HttpClientOptions());
      client.request(HttpMethod.GET, 8080, "localhost", "/the_uri", resp -> {
        Buffer content = Buffer.buffer();
        Observable<Buffer> observable = resp.toObservable();
        observable.forEach(content::appendBuffer, err -> fail(), () -> {
          assertEquals("some_content", content.toString("UTF-8"));
          testComplete();
        });
      }).end();
    });
    await();
  } finally {
    server.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:24,代码来源:CoreApiTest.java


示例5: testWebsocketClient

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testWebsocketClient() {
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.websocketStream().handler(ws -> {
    ws.write(Buffer.buffer("some_content"));
    ws.close();
  });
  server.listen(ar -> {
    HttpClient client = vertx.createHttpClient(new HttpClientOptions());
    client.websocket(8080, "localhost", "/the_uri", ws -> {
      Buffer content = Buffer.buffer();
      Observable<Buffer> observable = ws.toObservable();
      observable.forEach(content::appendBuffer, err -> fail(), () -> {
        server.close();
        assertEquals("some_content", content.toString("UTF-8"));
        testComplete();
      });
    });
  });
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:22,代码来源:CoreApiTest.java


示例6: testWebsocketClientFlatMap

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testWebsocketClientFlatMap() {
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.websocketStream().handler(ws -> {
    ws.write(Buffer.buffer("some_content"));
    ws.close();
  });
  server.listen(ar -> {
    HttpClient client = vertx.createHttpClient(new HttpClientOptions());
    Buffer content = Buffer.buffer();
    client.
        websocketStream(8080, "localhost", "/the_uri").
        toObservable().
        flatMap(WebSocket::toObservable).
        forEach(content::appendBuffer, err -> fail(), () -> {
          server.close();
          assertEquals("some_content", content.toString("UTF-8"));
          testComplete();
        });
  });
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:23,代码来源:CoreApiTest.java


示例7: testGet

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testGet() {
  int times = 5;
  waitFor(times);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.response().setChunked(true).end("some_content"));
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Single<HttpResponse<Buffer>> single = client
        .get(8080, "localhost", "/the_uri")
        .as(BodyCodec.buffer())
        .rxSend();
      for (int i = 0; i < times; i++) {
        single.subscribe(resp -> {
          Buffer body = resp.body();
          assertEquals("some_content", body.toString("UTF-8"));
          complete();
        }, this::fail);
      }
    });
    await();
  } finally {
    server.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:27,代码来源:RxTest.java


示例8: testPost

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testPost() {
  int times = 5;
  waitFor(times);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.bodyHandler(buff -> {
    assertEquals("onetwothree", buff.toString());
    req.response().end();
  }));
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
      Single<HttpResponse<Buffer>> single = client
        .post(8080, "localhost", "/the_uri")
        .rxSendStream(stream);
      for (int i = 0; i < times; i++) {
        single.subscribe(resp -> complete(), this::fail);
      }
    });
    await();
  } finally {
    server.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:RxTest.java


示例9: testResponseMissingBody

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testResponseMissingBody() throws Exception {
  int times = 5;
  waitFor(times);
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.response().setStatusCode(403).end());
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Single<HttpResponse<Buffer>> single = client
        .get(8080, "localhost", "/the_uri")
        .rxSend();
      for (int i = 0; i < times; i++) {
        single.subscribe(resp -> {
          assertEquals(403, resp.statusCode());
          assertNull(resp.body());
          complete();
        }, this::fail);
      }
    });
    await();
  } finally {
    server.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:RxTest.java


示例10: testResponseBodyAsAsJsonMapped

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
  JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
  server.requestStream().handler(req -> req.response().end(expected.encode()));
  try {
    server.listen(ar -> {
      client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
      Single<HttpResponse<WineAndCheese>> single = client
        .get(8080, "localhost", "/the_uri")
        .as(BodyCodec.json(WineAndCheese.class))
        .rxSend();
      single.subscribe(resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
        testComplete();
      }, this::fail);
    });
    await();
  } finally {
    server.close();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:24,代码来源:RxTest.java


示例11: initHttpServer

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
private Single<HttpServer> initHttpServer(Router router, JDBCClient client) {
  store = new JdbcProductStore(client);
  // Create the HTTP server and pass the "accept" method to the request handler.
  return vertx
    .createHttpServer()
    .requestHandler(router::accept)
    .rxListen(8080);
}
 
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:9,代码来源:CrudApplication.java


示例12: start

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) {
  // deploy the web server
  HttpServerOptions options = new HttpServerOptions()
      .setCompressionSupported(true);
  HttpServer server = vertx.createHttpServer(options);
  server.requestHandler(this::onRequest);
  server.listenObservable(8080) // listen on port 8080
    .subscribe(v -> startFuture.complete(), startFuture::fail);
}
 
开发者ID:michel-kraemer,项目名称:actson,代码行数:11,代码来源:WebServiceExample.java


示例13: configureTheHTTPServer

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
private Single<HttpServer> configureTheHTTPServer() {
  //----
  // Use a Vert.x Web router for this REST API.
  Router router = Router.router(vertx);
  router.get("/").handler(this::retrieveOperations);
  HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
  Integer port = config().getInteger("http.port", 0);
  return server.rxListen(port);
  //----
}
 
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:11,代码来源:AuditVerticle.java


示例14: configureTheHTTPServer

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
private Single<HttpServer> configureTheHTTPServer() {

    //TODO
    //----
    Single<HttpServer> httpServerSingle = Single.error(new UnsupportedOperationException("not yet implemented"));
    //----

    return httpServerSingle;
  }
 
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:10,代码来源:AuditVerticle.java


示例15: websocketServer

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
public void websocketServer(HttpServer server) {
  Observable<ServerWebSocket> socketObservable = server.websocketStream().toObservable();
  socketObservable.subscribe(
      socket -> System.out.println("Web socket connect"),
      failure -> System.out.println("Should never be called"),
      () -> {
        System.out.println("Subscription ended or server closed");
      }
  );
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:11,代码来源:RxifiedExamples.java


示例16: httpServerRequestObservableUnmarshall

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
public void httpServerRequestObservableUnmarshall(HttpServer server) {
  Observable<HttpServerRequest> requestObservable = server.requestStream().toObservable();
  requestObservable.subscribe(request -> {
    Observable<MyPojo> observable = request.
        toObservable().
        lift(io.vertx.rxjava.core.RxHelper.unmarshaller(MyPojo.class));
  });
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:9,代码来源:RxifiedExamples.java


示例17: testGetHelper

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Test
public void testGetHelper() throws Exception {
  CountDownLatch listenLatch = new CountDownLatch(1);
  HttpServer server = vertx.createHttpServer();
  AtomicInteger count = new AtomicInteger();
  server.requestHandler(req -> {
    req.response().end(Buffer.buffer("request=" + count.getAndIncrement()));
  }).listen(8080, onSuccess(s -> {
    listenLatch.countDown();
  }));
  awaitLatch(listenLatch);
  HttpClient client = vertx.createHttpClient();
  Observable<HttpClientResponse> obs = io.vertx.rxjava.core.RxHelper.get(client, 8080, "localhost", "/foo");
  List<Buffer> bodies = Collections.synchronizedList(new ArrayList<>());
  CountDownLatch reqLatch = new CountDownLatch(1);
  obs.subscribe(resp -> {
    resp.toObservable().subscribe(bodies::add, this::fail, reqLatch::countDown);
  }, this::fail);
  awaitLatch(reqLatch);
  obs.subscribe(resp -> {
    resp.toObservable().subscribe(bodies::add, this::fail, () -> {
      assertEquals(Arrays.asList("request=0", "request=1"), bodies.stream().map(Buffer::toString).collect(Collectors.toList()));
      testComplete();
    });
  }, this::fail);
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:28,代码来源:CoreApiTest.java


示例18: start

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {

  String wikiDbQueue = config().getString(CONFIG_WIKIDB_QUEUE, "wikidb.queue");
  dbService = io.vertx.guides.wiki.database.WikiDatabaseService.createProxy(vertx.getDelegate(), wikiDbQueue);

  HttpServer server = vertx.createHttpServer();

  Router router = Router.router(vertx);

  router.route().handler(CookieHandler.create());
  router.route().handler(BodyHandler.create());
  router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));

  // tag::sockjs-handler-setup[]
  SockJSHandler sockJSHandler = SockJSHandler.create(vertx); // <1>
  BridgeOptions bridgeOptions = new BridgeOptions()
    .addInboundPermitted(new PermittedOptions().setAddress("app.markdown"))  // <2>
    .addOutboundPermitted(new PermittedOptions().setAddress("page.saved")); // <3>
  sockJSHandler.bridge(bridgeOptions); // <4>
  router.route("/eventbus/*").handler(sockJSHandler); // <5>
  // end::sockjs-handler-setup[]

  // tag::eventbus-markdown-consumer[]
  vertx.eventBus().<String>consumer("app.markdown", msg -> {
    String html = Processor.process(msg.body());
    msg.reply(html);
  });
  // end::eventbus-markdown-consumer[]

  router.get("/app/*").handler(StaticHandler.create().setCachingEnabled(false));
  router.get("/").handler(context -> context.reroute("/app/index.html"));

  router.get("/api/pages").handler(this::apiRoot);
  router.get("/api/pages/:id").handler(this::apiGetPage);
  router.post().handler(BodyHandler.create());
  router.post("/api/pages").handler(this::apiCreatePage);
  router.put().handler(BodyHandler.create());
  router.put("/api/pages/:id").handler(this::apiUpdatePage);
  router.delete("/api/pages/:id").handler(this::apiDeletePage);

  int portNumber = config().getInteger(CONFIG_HTTP_SERVER_PORT, 8080);
  server
    .requestHandler(router::accept)
    .rxListen(portNumber)
    .subscribe(s -> {
      LOGGER.info("HTTP server running on port " + portNumber);
      startFuture.complete();
    }, t -> {
      LOGGER.error("Could not start a HTTP server", t);
      startFuture.fail(t);
    });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:54,代码来源:HttpServerVerticle.java


示例19: start

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {

  String wikiDbQueue = config().getString(CONFIG_WIKIDB_QUEUE, "wikidb.queue");
  dbService = io.vertx.guides.wiki.database.WikiDatabaseService.createProxy(vertx.getDelegate(), wikiDbQueue);

  HttpServer server = vertx.createHttpServer();

  Router router = Router.router(vertx);

  router.route().handler(CookieHandler.create());
  router.route().handler(BodyHandler.create());
  router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));

  // tag::static-assets[]
  router.get("/app/*").handler(StaticHandler.create().setCachingEnabled(false)); // <1> <2>
  router.get("/").handler(context -> context.reroute("/app/index.html"));
  // end::static-assets[]

  // tag::preview-rendering[]
  router.post("/app/markdown").handler(context -> {
    String html = Processor.process(context.getBodyAsString());
    context.response()
      .putHeader("Content-Type", "text/html")
      .setStatusCode(200)
      .end(html);
  });
  // end::preview-rendering[]

  // tag::routes[]
  router.get("/api/pages").handler(this::apiRoot);
  router.get("/api/pages/:id").handler(this::apiGetPage);
  router.post().handler(BodyHandler.create());
  router.post("/api/pages").handler(this::apiCreatePage);
  router.put().handler(BodyHandler.create());
  router.put("/api/pages/:id").handler(this::apiUpdatePage);
  router.delete("/api/pages/:id").handler(this::apiDeletePage);
  // end::routes[]

  int portNumber = config().getInteger(CONFIG_HTTP_SERVER_PORT, 8080);
  server
    .requestHandler(router::accept)
    .rxListen(portNumber)
    .subscribe(s -> {
      LOGGER.info("HTTP server running on port " + portNumber);
      startFuture.complete();
    }, t -> {
      LOGGER.error("Could not start a HTTP server", t);
      startFuture.fail(t);
    });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:52,代码来源:HttpServerVerticle.java


示例20: start

import io.vertx.rxjava.core.http.HttpServer; //导入依赖的package包/类
@Override
public void start() throws Exception {

	Injector injector = Guice.createInjector(new LoggerModule(),
												new AopModule(),
												new ContextModule(),
												new HandlerModule(),
												new ServiceModule()
								);

	// URL routing
	Router router = Router.router(vertx);

	router.options("/*")
			.handler(context -> {
				context.response()
						.putHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*")
						.putHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "*")
						.putHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "*")
						.setStatusCode(200)
						.end();
			});

	router.get("/")
			.handler(context -> {
				context.response()
						.setStatusCode(303)
						.putHeader(HttpHeaders.LOCATION, "/alive")
						.end();
			});

	router.get("/hello")
			.handler(context -> {
				JsonObject json = new JsonObject().put("message",
														"Hello! Vert.x 3.x JSON");

				Buffer buffer = Buffer.buffer(json.toString());

				context.response()
						.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
						.putHeader(HttpHeaders.CONTENT_LENGTH, Objects.toString(buffer.length()))
						.write(buffer)
						.end();
			});

	router.get("/alive")
			.handler(injector.getInstance(AliveHandler.class));

	HttpServerOptions serverOption = new HttpServerOptions().setAcceptBacklog(10000)
															.setCompressionSupported(true);
	HttpServer server = vertx.createHttpServer(serverOption);

	server.requestHandler(router::accept)
			.listenObservable(8080)
			.subscribe(result -> logger.info("start.server"),
						error -> logger.error("failed.start.server"),
						() -> logger.info("complete.ini.server"));

	// server.requestStream()
	// .toObservable()
	// .subscribe(req -> {
	// req.response()
	// .putHeader("content-type", "text/html")
	// .end("<html><body><h1>Hello from vert.x!</h1></body></html>");
	// });
}
 
开发者ID:takecy,项目名称:vertx3-api-server,代码行数:67,代码来源:HttpVerticle.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PsiExpressionStatement类代码示例发布时间:2022-05-23
下一篇:
Java Region类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap