io.vertx.reactivex.ext.web.client.HttpResponse.bodyAsString()方法的使用及代码示例

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

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

HttpResponse.bodyAsString介绍

暂无

代码示例

代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch

@Override
public Single<Integer> getVersion() throws ElasticsearchException {
  return httpClient
      .get(URL_ROOT)
      .rxSend()
      .doOnError(throwable -> logger.error("Unable to get a connection to Elasticsearch", throwable))
      .map(response -> mapper.readTree(response.bodyAsString()).path("version").path("number").asText())
      .map(sVersion -> {
        float result = Float.valueOf(sVersion.substring(0, 3));
        int version = Integer.valueOf(sVersion.substring(0, 1));
        if (result < 2) {
          logger.warn("Please upgrade to Elasticsearch 2 or later. version={}", version);
        }
        return version;
      });
}

代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch

/**
 * Get the cluster health
 *
 * @return the cluster health
 * @throws ElasticsearchException error occurs during ES call
 */
@Override
public Single<Health> getClusterHealth() {
  return httpClient
      .get(URL_STATE_CLUSTER)
      .rxSend()
      .map(response -> mapper.readValue(response.bodyAsString(), Health.class));
}

代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch

/**
 * Perform an HTTP search query
 * @param indexes indexes names. If null search on all indexes
 * @param type document type separated by comma. If null search on all types
 * @param query json body query
 * @return elasticsearch response
 */
public Single<SearchResponse> search(final String indexes, final String type, final String query) {
  // index can be null _search on all index
  final StringBuilder url = new StringBuilder()
      .append('/')
      .append(indexes);
  if (type != null) {
    url.append('/').append(type);
  }
  url.append(URL_SEARCH);
  return httpClient
      .post(url.toString())
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
      .rxSendBuffer(Buffer.buffer(query))
      .map(response -> {
        if (response.statusCode() != HttpStatusCode.OK_200) {
          logger.error("Unable to search: url[{}] status[{}] query[{}] response[{}]",
              url.toString(), response.statusCode(), query, response.body());
          throw new ElasticsearchException("Unable to search");
        }
        return mapper.readValue(response.bodyAsString(), SearchResponse.class);
      });
}

代码示例来源:origin: io.gravitee.elasticsearch/gravitee-common-elasticsearch

@Override
public Single<BulkResponse> bulk(final List<String> data) {
  if (data != null && !data.isEmpty()) {
    String content = data.stream().collect(Collectors.joining());
    return httpClient
        .post(URL_BULK)
        .putHeader(HttpHeaders.CONTENT_TYPE, "application/x-ndjson")
        .rxSendBuffer(Buffer.buffer(content))
        .map(response -> {
          if (response.statusCode() != HttpStatusCode.OK_200) {
            logger.error("Unable to bulk index data: status[{}] data[{}] response[{}]",
                response.statusCode(), content, response.body());
            throw new ElasticsearchException("Unable to bulk index data");
          }
          return mapper.readValue(response.bodyAsString(), BulkResponse.class);
        });
  }
  return Single.never();
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

private Maybe<String> authenticate(Authentication authentication) {
  // prepare body request parameters
  List<NameValuePair> urlParameters = new ArrayList<>();
  urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId()));
  urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret()));
  urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI)));
  urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials()));
  String bodyRequest = URLEncodedUtils.format(urlParameters);
  return client.postAbs(configuration.getAccessTokenUri())
      .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length()))
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
      .rxSendBuffer(Buffer.buffer(bodyRequest))
      .toMaybe()
      .map(httpResponse -> {
        if (httpResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpResponse.statusMessage());
        }
        Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString());
        return bodyResponse.get("access_token");
      });
}

代码示例来源:origin: io.gravitee.am.identityprovider/gravitee-am-identityprovider-github

private Maybe<String> authenticate(Authentication authentication) {
  // prepare body request parameters
  List<NameValuePair> urlParameters = new ArrayList<>();
  urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId()));
  urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret()));
  urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI)));
  urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials()));
  String bodyRequest = URLEncodedUtils.format(urlParameters);
  return client.postAbs(configuration.getAccessTokenUri())
      .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length()))
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
      .rxSendBuffer(Buffer.buffer(bodyRequest))
      .toMaybe()
      .map(httpResponse -> {
        if (httpResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpResponse.statusMessage());
        }
        Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString());
        return bodyResponse.get("access_token");
      });
}

代码示例来源:origin: Cognifide/knotx

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server.json")
public void whenRequestingPostGlobalPath_expectGlobalBC(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleKnot(vertx, "B-engine", "+B", "go-c");
 createSimpleKnot(vertx, "C-engine", "+C", null);
 testPostRequest(context, vertx, "/content/simple.html", resp -> {
  assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
  assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
  assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
    resp.getHeader(EXPECTED_RESPONSE_HEADER));
  assertEquals("global+B+C", resp.bodyAsString(),
    "Wrong engines processed request, expected 'global+B+C'");
 });
}

代码示例来源:origin: Cognifide/knotx

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server.json")
public void whenRequestingPostLocalPathWithAlternateTransition_expectLocalApostC(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleKnot(vertx, "A-post-engine", "+Apost", "go-c");
 createSimpleKnot(vertx, "C-engine", "+C", null);
 testPostRequest(context, vertx, "/content/local/simple.html",
   resp -> {
    assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
    assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
    assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
      resp.getHeader(EXPECTED_RESPONSE_HEADER));
    assertEquals("local+Apost+C", resp.bodyAsString(),
      "Wrong engines processed request, expected " + "local+Apost+C");
   });
}

代码示例来源:origin: Cognifide/knotx

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server.json")
public void whenRequestingPostLocalPathWithFirstTransition_expectLocalApostBC(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleKnot(vertx, "A-post-engine", "+Apost", "go-b");
 createSimpleKnot(vertx, "B-engine", "+B", "go-c");
 createSimpleKnot(vertx, "C-engine", "+C", null);
 testPostRequest(context, vertx, "/content/local/simple.html",
   resp -> {
    assertEquals(HttpResponseStatus.OK.code(), resp.statusCode());
    assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER));
    assertEquals(EXPECTED_XSERVER_HEADER_VALUE,
      resp.getHeader(EXPECTED_RESPONSE_HEADER));
    assertEquals("local+Apost+B+C", resp.bodyAsString(),
      "Wrong engines processed request, expected " + "local+Apost+B+C");
   });
}

相关文章