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

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

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

HttpRequest.putHeader介绍

暂无

代码示例

代码示例来源:origin: io.knotx.acme/acme-forms-adapter-http

private void overrideRequestHeaders(HttpRequest<Buffer> request, HttpFormsSettings metadata) {
 if (metadata.getAdditionalHeaders() != null) {
  metadata.getAdditionalHeaders().forEach(entry -> {
   request.putHeader(entry.getKey(), entry.getValue().toString());
  });
 }
}

代码示例来源:origin: io.knotx/knotx-databridge-adapter-http

private void overrideRequestHeaders(HttpRequest<Buffer> request, HttpDataSourceSettings metadata) {
 if (metadata.getAdditionalHeaders() != null) {
  metadata.getAdditionalHeaders().forEach(entry -> {
   request.putHeader(entry.getKey(), entry.getValue().toString());
  });
 }
}

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

private void overrideRequestHeaders(HttpRequest<Buffer> request, ServiceSettings metadata) {
 if (metadata.getAdditionalHeaders() != null) {
  metadata.getAdditionalHeaders().forEach(entry -> {
   request.putHeader(entry.getKey(), entry.getValue().toString());
  });
 }
}

代码示例来源: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: FroMage/redpipe

.put("code", code);
HttpResponse<JsonObject> response = await(webClient.post(443, "github.com", "/login/oauth/access_token") 
    .putHeader("Accept", "application/json") 
    .putHeader("Content-Type", "application/json")
    .as(BodyCodec.jsonObject())
    .rxSendJsonObject(payload));

代码示例来源:origin: FroMage/redpipe

.put("code", code);
HttpResponse<JsonObject> response = await(webClient.post(443, "github.com", "/login/oauth/access_token") 
    .putHeader("Accept", "application/json") 
    .putHeader("Content-Type", "application/json")
    .as(BodyCodec.jsonObject())
    .rxSendJsonObject(payload));

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

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()));
  urlParameters.add(new BasicNameValuePair(GRANT_TYPE, "authorization_code"));
  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());
        }
        return httpResponse.bodyAsJsonObject().getString("access_token");
      });
}

代码示例来源: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()));
  urlParameters.add(new BasicNameValuePair(GRANT_TYPE, "authorization_code"));
  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());
        }
        return httpResponse.bodyAsJsonObject().getString("access_token");
      });
}

代码示例来源:origin: FroMage/redpipe

.setUserAgent("vert-x3"));
HttpResponse<JsonObject> response = await(webClient.post(443, "api.github.com", "/gists") 
    .putHeader("Accept", "application/vnd.github.v3+json") 
    .putHeader("Content-Type", "application/json")
    .putHeader("Authorization", "token "+token)
    .as(BodyCodec.jsonObject())
    .rxSendJsonObject(gistPayload));

代码示例来源: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: FroMage/redpipe

.setUserAgent("vert-x3"));
HttpResponse<JsonObject> response = await(webClient.post(443, "api.github.com", "/gists") 
    .putHeader("Accept", "application/vnd.github.v3+json") 
    .putHeader("Content-Type", "application/json")
    .putHeader("Authorization", "token "+token)
    .as(BodyCodec.jsonObject())
    .rxSendJsonObject(gistPayload));

代码示例来源: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.elasticsearch/gravitee-common-elasticsearch

@Override
public Completable putPipeline(String pipelineName, String pipeline) {
  return httpClient
      .put(URL_INGEST + '/' + pipelineName)
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
      .rxSendBuffer(Buffer.buffer(pipeline))
      .flatMapCompletable(response -> {
        switch (response.statusCode()) {
          case HttpStatusCode.OK_200:
            return Completable.complete();
          case HttpStatusCode.BAD_REQUEST_400:
            logger.warn("Unable to create ES pipeline: {}", pipelineName);
            break;
          default:
            logger.error("Unable to put pipeline: status[{}] pipeline[{}] response[{}]",
                response.statusCode(), pipeline, response.body());
            break;
        }
        return Completable.error(new ElasticsearchException("Unable to create ES pipeline: " + pipelineName));
      });
}

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

@Override
public Completable putTemplate(String templateName, String template) {
  return httpClient
      .put(URL_TEMPLATE + '/' + templateName)
      .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
      .rxSendBuffer(Buffer.buffer(template))
      .flatMapCompletable(response -> {
        if (response.statusCode() != HttpStatusCode.OK_200) {
          logger.error("Unable to put template mapping: status[{}] template[{}] response[{}]",
              response.statusCode(), template, response.body());
          return Completable.error(new ElasticsearchException("Unable to put template mapping"));
        }
        return Completable.complete();
      });
}

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

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

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

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

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

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

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

private Maybe<User> profile(String accessToken) {
  return client.getAbs(configuration.getUserProfileUri())
      .putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken)
      .rxSend()
      .toMaybe()
      .map(httpClientResponse -> {
        if (httpClientResponse.statusCode() != 200) {
          throw new BadCredentialsException(httpClientResponse.statusMessage());
        }
        return createUser(httpClientResponse.bodyAsJsonObject());
      });
}

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

@Test
@KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json")
public void whenDoPostSecureWithCSRF_expectOK(
  VertxTestContext context, Vertx vertx) {
 createPassThroughKnot(vertx, "test-splitter");
 createPassThroughKnot(vertx, "test-assembler");
 createSimpleKnot(vertx, "some-knot", "test", null);
 MultiMap body = MultiMap.caseInsensitiveMultiMap().add("field", "value");
 WebClient client = WebClient.create(vertx);
 client.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").send(
   ar -> {
    if (ar.succeeded()) {
     String token = getToken(ar.result().cookies());
     client.post(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html")
       .putHeader(CSRFHandler.DEFAULT_HEADER_NAME, token)
       .putHeader(HttpHeaderNames.COOKIE.toString(),
         CSRFHandler.DEFAULT_COOKIE_NAME + "=" + token)
       .sendForm(body, res -> {
        if (res.succeeded()) {
         assertEquals(HttpResponseStatus.OK.code(), res.result().statusCode());
         context.completeNow();
        } else {
         context.failNow(ar.cause());
        }
       });
    } else {
     context.failNow(ar.cause());
    }
   });
}

相关文章