io.vertx.core.http.HttpClient.getAbs()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.4k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中io.vertx.core.http.HttpClient.getAbs()方法的一些代码示例,展示了HttpClient.getAbs()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.getAbs()方法的具体详情如下:
包路径:io.vertx.core.http.HttpClient
类名称:HttpClient
方法名:getAbs

HttpClient.getAbs介绍

[英]Create an HTTP GET request to send to the server using an absolute URI
[中]使用绝对URI创建要发送到服务器的HTTP GET请求

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testClientSynchronousConnectFailures() {
 System.setProperty("vertx.disableDnsResolver", "true");
 Vertx vertx = Vertx.vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setQueryTimeout(100)));
 try {
  int poolSize = 2;
  HttpClient client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(poolSize));
  AtomicInteger failures = new AtomicInteger();
  vertx.runOnContext(v -> {
   for (int i = 0; i < (poolSize + 1); i++) {
    AtomicBoolean f = new AtomicBoolean();
    client.getAbs("http://invalid-host-name.foo.bar", onFailure(resp -> {
     if (f.compareAndSet(false, true)) {
      if (failures.incrementAndGet() == poolSize + 1) {
       testComplete();
      }
     }
    })).end();
   }
  });
  await();
 } finally {
  vertx.close();
  System.setProperty("vertx.disableDnsResolver", "false");
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

private void proxyTest(int error, String username, String url, Handler<AsyncResult<HttpClientResponse>> assertResponse) throws Exception {
 startProxy(error, username);
 final HttpClientOptions options = new HttpClientOptions()
   .setSsl(url.startsWith("https"))
   .setProxyOptions(new ProxyOptions()
     .setType(ProxyType.HTTP)
     .setHost("localhost")
     .setPort(proxy.getPort()));
 HttpClient client = vertx.createHttpClient(options);
 client.getAbs(url, assertResponse).end();
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

HttpClientRequest clientRequest = client.getAbs(uri, ar -> {
 if (ar.succeeded()) {
  HttpClientResponse resp = ar.result();

代码示例来源:origin: eclipse-vertx/vert.x

Future<HttpClientRequest> fut = Future.future();
vertx.setTimer(25, id -> {
 HttpClientRequest req = client.getAbs(scheme + "://localhost:" + port + "/custom");
 req.putHeader("foo", "foo_another");
 req.setHost("localhost:" + port);

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testHttpProxyFtpRequest() throws Exception {
 startProxy(null, ProxyType.HTTP);
 client.close();
 client = vertx.createHttpClient(new HttpClientOptions()
   .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort())));
 final String url = "ftp://ftp.gnu.org/gnu/";
 proxy.setForceUri("http://localhost:8080/");
 server.requestHandler(req -> {
  req.response().end();
 });
 server.listen(onSuccess(s -> {
  HttpClientRequest clientReq = client.getAbs(url, onSuccess(resp -> {
   assertEquals(200, resp.statusCode());
   assertEquals("request did sent the expected url", url, proxy.getLastUri());
   testComplete();
  }));
  clientReq.exceptionHandler(this::fail);
  clientReq.end();
 }));
 await();
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testClientSynchronousConnectFailures() {
 System.setProperty("vertx.disableDnsResolver", "true");
 Vertx vertx = Vertx.vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setQueryTimeout(100)));
 try {
  int poolSize = 2;
  HttpClient client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(poolSize));
  AtomicInteger failures = new AtomicInteger();
  vertx.runOnContext(v -> {
   for (int i = 0; i < (poolSize + 1); i++) {
    HttpClientRequest clientRequest = client.getAbs("http://invalid-host-name.foo.bar", resp -> fail());
    AtomicBoolean f = new AtomicBoolean();
    clientRequest.exceptionHandler(e -> {
     if (f.compareAndSet(false, true)) {
      if (failures.incrementAndGet() == poolSize + 1) {
       testComplete();
      }
     }
    });
    clientRequest.end();
   }
  });
  await();
 } finally {
  vertx.close();
  System.setProperty("vertx.disableDnsResolver", "false");
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create an HTTP GET request to send to the server using an absolute URI
 * @param absoluteURI the absolute URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.core.http.HttpClientRequest getAbs(String absoluteURI) { 
 io.vertx.rxjava.core.http.HttpClientRequest ret = io.vertx.rxjava.core.http.HttpClientRequest.newInstance(delegate.getAbs(absoluteURI));
 return ret;
}

代码示例来源:origin: io.vertx/vertx-core

HttpClientRequest clientRequest = client.getAbs(uri, resp -> {
 for (String name : resp.headers().names()) {
  request.response().putHeader(name, resp.headers().getAll(name));

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Create an HTTP GET request to send to the server using an absolute URI
 * @param absoluteURI the absolute URI
 * @return an HTTP client request object
 */
public io.vertx.rxjava.core.http.HttpClientRequest getAbs(String absoluteURI) { 
 io.vertx.rxjava.core.http.HttpClientRequest ret = io.vertx.rxjava.core.http.HttpClientRequest.newInstance(delegate.getAbs(absoluteURI));
 return ret;
}

代码示例来源:origin: io.vertx/vertx-core

Future<HttpClientRequest> fut = Future.future();
vertx.setTimer(25, id -> {
 HttpClientRequest req = client.getAbs(scheme + "://localhost:" + port + "/custom");
 req.putHeader("foo", "foo_another");
 req.setHost("localhost:" + port);

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Create an HTTP GET request to send to the server using an absolute URI, specifying a response handler to receive
 * the response
 * @param absoluteURI the absolute URI
 * @param responseHandler the response handler
 * @return an HTTP client request object
 */
@Deprecated()
public io.vertx.rxjava.core.http.HttpClientRequest getAbs(String absoluteURI, Handler<io.vertx.rxjava.core.http.HttpClientResponse> responseHandler) { 
 io.vertx.rxjava.core.http.HttpClientRequest ret = io.vertx.rxjava.core.http.HttpClientRequest.newInstance(delegate.getAbs(absoluteURI, new Handler<io.vertx.core.http.HttpClientResponse>() {
  public void handle(io.vertx.core.http.HttpClientResponse event) {
   responseHandler.handle(io.vertx.rxjava.core.http.HttpClientResponse.newInstance(event));
  }
 }));
 return ret;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Create an HTTP GET request to send to the server using an absolute URI, specifying a response handler to receive
 * the response
 * @param absoluteURI the absolute URI
 * @param responseHandler the response handler
 * @return an HTTP client request object
 */
public io.vertx.rxjava.core.http.HttpClientRequest getAbs(String absoluteURI, Handler<AsyncResult<io.vertx.rxjava.core.http.HttpClientResponse>> responseHandler) { 
 io.vertx.rxjava.core.http.HttpClientRequest ret = io.vertx.rxjava.core.http.HttpClientRequest.newInstance(delegate.getAbs(absoluteURI, new Handler<AsyncResult<io.vertx.core.http.HttpClientResponse>>() {
  public void handle(AsyncResult<io.vertx.core.http.HttpClientResponse> ar) {
   if (ar.succeeded()) {
    responseHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.http.HttpClientResponse.newInstance(ar.result())));
   } else {
    responseHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
   }
  }
 }));
 return ret;
}

代码示例来源:origin: io.vertx/vertx-core

@Test
public void testHttpProxyFtpRequest() throws Exception {
 startProxy(null, ProxyType.HTTP);
 client.close();
 client = vertx.createHttpClient(new HttpClientOptions()
   .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(proxy.getPort())));
 final String url = "ftp://ftp.gnu.org/gnu/";
 proxy.setForceUri("http://localhost:8080/");
 HttpClientRequest clientReq = client.getAbs(url);
 server.requestHandler(req -> {
  req.response().end();
 });
 server.listen(onSuccess(s -> {
  clientReq.handler(resp -> {
   assertEquals(200, resp.statusCode());
   assertEquals("request did sent the expected url", url, proxy.getLastUri());
   testComplete();
  });
  clientReq.exceptionHandler(this::fail);
  clientReq.end();
 }));
 await();
}

代码示例来源:origin: io.vertx/vertx-core

private void proxyTest(int error, String username, String url, Handler<HttpClientResponse> assertResponse, boolean completeOnException) throws Exception {
 startProxy(error, username);
 final HttpClientOptions options = new HttpClientOptions()
   .setSsl(url.startsWith("https"))
   .setProxyOptions(new ProxyOptions()
     .setType(ProxyType.HTTP)
     .setHost("localhost")
     .setPort(proxy.getPort()));
 HttpClient client = vertx.createHttpClient(options);
 client.getAbs(url, assertResponse)
 .exceptionHandler(e -> {
  if (completeOnException) {
   testComplete();
  } else {
   fail(e);
  }
 })
 .end();
 await();
}

代码示例来源:origin: cdelmas/microservices-comparison

@Override
public void authenticate(JsonObject credentials, Handler<AsyncResult<User>> resultHandler) {
  String token = credentials.getString("token");
  httpClient.getAbs("https://graph.facebook.com:443/v2.4/me?access_token=" + token)
      .handler(response ->
          response.bodyHandler(buffer -> {
            JsonObject json = new JsonObject(buffer.toString());
            if (response.statusCode() != 200) {
              String message = json.getJsonObject("error").getString("message");
              resultHandler.handle(Future.failedFuture(message));
            } else {
              resultHandler.handle(Future.succeededFuture(
                  new MyUser(Long.parseLong(json.getString("id")),
                      json.getString("name"),
                      token)));
            }
          }))
      .exceptionHandler(error ->
          resultHandler.handle(Future.failedFuture(error.getMessage())))
      .end();
}

代码示例来源:origin: folio-org/okapi

private void getContainerLog(Handler<AsyncResult<Void>> future) {
 final String url = dockerUrl + "/containers/" + containerId
  + "/logs?stderr=1&stdout=1&follow=1";
 HttpClientRequest req = client.getAbs(url, res -> {
  if (res.statusCode() == 200) {
   // stream OK. Continue other work but keep fetching!
   // remove 8 bytes of binary data and final newline
   res.handler(this::logHandler);
   future.handle(Future.succeededFuture());
  } else {
   String m = "getContainerLog HTTP error "
    + Integer.toString(res.statusCode());
   logger.error(m);
   future.handle(Future.failedFuture(m));
  }
 });
 req.exceptionHandler(d -> future.handle(Future.failedFuture(d.getCause())));
 req.end();
}

代码示例来源:origin: folio-org/okapi

private void getUrl(String url, Handler<AsyncResult<JsonObject>> future) {
 HttpClientRequest req = client.getAbs(url, res -> {
  Buffer body = Buffer.buffer();
  res.exceptionHandler(d -> {
   logger.warn(url + ": " + d.getMessage());
   future.handle(Future.failedFuture(url + ": " + d.getMessage()));
  });
  res.handler(body::appendBuffer);
  res.endHandler(d -> {
   if (res.statusCode() == 200) {
    JsonObject b = body.toJsonObject();
    logger.info(b.encodePrettily());
    future.handle(Future.succeededFuture(b));
   } else {
    String m = url + " HTTP error "
     + Integer.toString(res.statusCode()) + "\n"
     + body.toString();
    logger.error(m);
    future.handle(Future.failedFuture(m));
   }
  });
 });
 req.exceptionHandler(d -> {
  logger.warn(url + ": " + d.getMessage());
  future.handle(Future.failedFuture(url + ": " + d.getMessage()));
 });
 req.end();
}

代码示例来源:origin: folio-org/okapi

private void getList(String urlBase,
 Handler<ExtendedAsyncResult<ModuleDescriptor[]>> fut) {
 String url = urlBase;
 if (!url.endsWith("/")) {
  url += "/";
 }
 url += "_/proxy/modules";
 final Buffer body = Buffer.buffer();
 HttpClientRequest req = httpClient.getAbs(url, res -> {
  res.handler(body::appendBuffer);
  res.endHandler(x -> {
   if (res.statusCode() != 200) {
    fut.handle(new Failure<>(ErrorType.USER, body.toString()));
   } else {
    ModuleDescriptor[] ml = Json.decodeValue(body.toString(),
     ModuleDescriptor[].class);
    fut.handle(new Success<>(ml));
   }
  });
  res.exceptionHandler(x
   -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
 });
 req.exceptionHandler(x
  -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
 req.end();
}

代码示例来源:origin: cdelmas/microservices-comparison

public void hello(RoutingContext routingContext) {
    httpClient.getAbs("https://localhost:8090/cars")
        .putHeader("Accept", "application/json")
        .putHeader("Authorization", "Bearer " + routingContext.user().principal().getString("token"))
        .handler(response ->
            response.bodyHandler(buffer -> {
              if (response.statusCode() == 200) {
                List<Car> cars = new ArrayList<>(asList(Json.decodeValue(buffer.toString(), Car[].class)));
                routingContext.response()
                    .putHeader("content-type", "test/plain")
                    .setChunked(true)
                    .write(cars.stream().map(Car::getName).collect(toList()).toString())
                    .write(", and then Hello World from Vert.x-Web!")
                    .end();
              } else {
                routingContext.response()
                    .setStatusCode(response.statusCode())
                    .putHeader("content-type", "test/plain")
                    .setChunked(true)
                    .write("Oops, something went wrong: " + response.statusMessage())
                    .end();
              }
            }))
        .end();
  }
}

代码示例来源:origin: folio-org/okapi

fut.handle(new Success<>(hd));
} else {
 HttpClientRequest req = httpClient.getAbs(url, res -> {
  res.endHandler(res1 -> {
   hd.setHealthMessage("OK");

相关文章