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


Java HttpResponse类代码示例

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


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

示例1: hello7

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("7")
@GET
public CompletionStage<String> hello7(@Context Vertx vertx){
	io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	CompletableFuture<String> ret = new CompletableFuture<>();
	responseHandler.subscribe(body -> {
		System.err.println("Got body");
		ret.complete(body.body().toString());
	});
	
	System.err.println("Created client");
	return ret;
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java

示例2: getShoppingList

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
private void getShoppingList(RoutingContext rc) {
    Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();

    HttpServerResponse serverResponse = rc.response()
        .setChunked(true);

    list.subscribe(
        response -> {
            JsonObject body = response.bodyAsJsonObject();
            Observable.from(body)
                .flatMap(entry ->
                    retrievePrice(pricer, entry).toObservable())
                .subscribe(
                    product -> writeProductLine(serverResponse, product),
                    rc::fail,
                    serverResponse::end
                );
        },
        rc::fail);
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:21,代码来源:MyShoppingList.java

示例3: getShoppingListWithCB

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
private void getShoppingListWithCB(RoutingContext rc) {
    Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();

    HttpServerResponse serverResponse = rc.response()
        .setChunked(true);

    list.subscribe(
        response -> {
            JsonObject body = response.bodyAsJsonObject();
            Observable.from(body)
                .flatMap(entry ->
                    circuit.executeWithFallback(
                        future -> retrievePrice(pricer, entry, future),
                        t -> getFallbackPrice(entry)
                    )
                        .rxSetHandler().toObservable())
                .subscribe(
                    product -> writeProductLine(serverResponse, product),
                    rc::fail,
                    serverResponse::end
                );
        },
        rc::fail);
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:25,代码来源:MyShoppingList.java

示例4: hello6

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("6")
@GET
public void hello6(@Suspended final AsyncResponse asyncResponse,
	      // Inject the Vertx instance
	      @Context Vertx vertx){
	io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	responseHandler.subscribe(body -> {
		System.err.println("Got body");
		asyncResponse.resume(Response.ok(body.body().toString()).build());
	});
	
	System.err.println("Created client");
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java

示例5: hello7Error

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("7error")
@GET
public CompletionStage<String> hello7Error(@Context Vertx vertx){
	io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	CompletableFuture<String> ret = new CompletableFuture<>();
	responseHandler.subscribe(body -> {
		System.err.println("Got body");
		
		ret.completeExceptionally(new MyException());
	});
	System.err.println("Created client");
	return ret;
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java

示例6: hello8

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.rxjava.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		return body.body().toString();
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:20,代码来源:MyResource.java

示例7: hello8User

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("8user")
@Produces("text/json")
@GET
public Single<DataClass> hello8User(@Context io.vertx.rxjava.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		return new DataClass(body.body().toString());
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:21,代码来源:MyResource.java

示例8: hello8Error

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("8error")
@GET
public Single<String> hello8Error(@Context io.vertx.rxjava.core.Vertx rxVertx){
	System.err.println("Creating client");
	WebClientOptions options = new WebClientOptions();
	options.setSsl(true);
	options.setTrustAll(true);
	options.setVerifyHost(false);
	WebClient client = WebClient.create(rxVertx, options);
	Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
			"www.google.com", 
			"/robots.txt").rxSend();

	System.err.println("Created client");
	return responseHandler.map(body -> {
		System.err.println("Got body");
		throw new MyException();
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:20,代码来源:MyResource.java

示例9: helloAsync

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
@Path("coroutines/1")
@GET
public Single<Response> helloAsync(@Context io.vertx.rxjava.core.Vertx rxVertx){
	return Fibers.fiber(() -> {
		System.err.println("Creating client");
		WebClientOptions options = new WebClientOptions();
		options.setSsl(true);
		options.setTrustAll(true);
		options.setVerifyHost(false);
		WebClient client = WebClient.create(rxVertx, options);
		Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
				"www.google.com", 
				"/robots.txt").rxSend();

		System.err.println("Got response");

		HttpResponse<io.vertx.rxjava.core.buffer.Buffer> httpResponse = Fibers.await(responseHandler);
		System.err.println("Got body");
		
		return Response.ok(httpResponse.body().toString()).build();
	});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:23,代码来源:MyResource.java

示例10: get

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
private void get(String uri, CacheItem<JsonObject> cache, Future<JsonObject> future, Retryable retryable) {
    client.get(HTTPS, ENDPOINT, apikey + uri)
            .timeout(5000L)
            .as(jsonObject())
            .send((AsyncResult<HttpResponse<JsonObject>> ar) -> {
                System.out.println("STATUSCODE ------------ " + ar.cause());
                check(ar.succeeded(),
                        () -> check(ar.result().statusCode() == OK,
                                () -> future.complete(cache.set(ar.result().body())),
                                () -> future.fail("OMDB API returned code: " + ar.result().statusCode() +
                                        "; message: " + ar.result().statusMessage())),
                        () -> retryable.retry(
                                () -> vertx.setTimer(DEFAULT_DELAY, timer -> get(uri, cache, future, retryable)),
                                () -> future.fail("Too many failures.")));
            });
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:17,代码来源:OmdbServiceImpl.java

示例11: get

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的package包/类
private void get(String uri, CacheItem<JsonObject> cache, Future<JsonObject> future, Retryable retryable) {
    client.get(HTTPS, ENDPOINT, uri).timeout(5000L).as(BodyCodec.jsonObject()).send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<JsonObject> res = ar.result();
            if (res.statusCode() == OK) {
                future.complete(cache.set(res.body()));
            } else if (res.statusCode() == RATE_LIMIT) {
                retryable.retry(
                        () -> vertx.setTimer(getTimeTillReset(res), timer -> get(uri, cache, future, retryable)),
                        () -> future.fail("Too many retries."));
            } else {
                future.fail("TMDB API returned code: " + res.statusCode() +
                        "; message: " + res.statusMessage());
            }
        } else {
            retryable.retry(
                    () -> vertx.setTimer(DEFAULT_DELAY, timer -> get(uri, cache, future, retryable)),
                    () -> future.fail("Too many failures."));
        }
    });
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:22,代码来源:TmdbServiceImpl.java

示例12: testGet

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的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

示例13: testPost

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的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

示例14: testResponseMissingBody

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的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

示例15: testResponseBodyAsAsJsonMapped

import io.vertx.rxjava.ext.web.client.HttpResponse; //导入依赖的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


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