org.springframework.web.reactive.function.client.WebClient.method()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(243)

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

WebClient.method介绍

[英]Start building a request for the given HttpMethod.
[中]开始为给定的HttpMethod生成请求。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private RequestBodyUriSpec methodInternal(HttpMethod method) {
  return new DefaultRequestBodyUriSpec(this.webClient.method(method));
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private Mono<ClientResponse> sendRequest(WebClient webClient, String logId, Request request, HttpHeaders headers) {
  RequestBodySpec requestBodySpec = webClient.method(HttpMethod.valueOf(request.getMethod().toUpperCase())) //
      .uri(builder -> {

代码示例来源:origin: codecentric/spring-boot-admin

Supplier<BodyInserter<?, ? super ClientHttpRequest>> bodyInserter) {
WebClient.RequestBodySpec bodySpec = instanceWebClient.instance(instance)
                           .method(method)
                           .uri(uri)
                           .headers(h -> h.addAll(filterHeaders(headers)));

代码示例来源:origin: spring-cloud/spring-cloud-gateway

RequestBodySpec bodySpec = this.webClient.method(method)
    .uri(requestUrl)
    .headers(httpHeaders -> {

代码示例来源:origin: spring-cloud/spring-cloud-gateway

private Mono<ResponseEntity<T>> exchange(RequestEntity<?> requestEntity) {
  Type type = this.responseType;
  RequestBodySpec builder = rest.method(requestEntity.getMethod())
      .uri(requestEntity.getUrl())
      .headers(headers -> addHeaders(headers, requestEntity.getHeaders()));
  Mono<ClientResponse> result;
  if (requestEntity.getBody() instanceof Publisher) {
    @SuppressWarnings("unchecked")
    Publisher<Object> publisher = (Publisher<Object>) requestEntity.getBody();
    result = builder.body(publisher, Object.class).exchange();
  }
  else if (requestEntity.getBody() != null) {
    result = builder.body(BodyInserters.fromObject(requestEntity.getBody()))
        .exchange();
  }
  else {
    if (hasBody) {
      result = builder.headers(
          headers -> addHeaders(headers, exchange.getRequest().getHeaders()))
          .body(exchange.getRequest().getBody(), DataBuffer.class)
          .exchange();
    }
    else {
      result = builder.headers(
          headers -> addHeaders(headers, exchange.getRequest().getHeaders()))
          .exchange();
    }
  }
  return result.flatMap(response -> response.toEntity(ParameterizedTypeReference.forType(type)));
}

代码示例来源:origin: spring-projects/spring-integration

this.webClient.method(httpMethod)
    .uri(b -> uriSupplier.get())
    .headers(headers -> headers.putAll(httpRequest.getHeaders()));

代码示例来源:origin: apache/servicemix-bundles

private RequestBodyUriSpec methodInternal(HttpMethod method) {
  return new DefaultRequestBodyUriSpec(this.webClient.method(method));
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

private RequestBodyUriSpec methodInternal(HttpMethod method) {
  return new DefaultRequestBodyUriSpec(this.webClient.method(method));
}

代码示例来源:origin: kptfh/feign-reactive

@Override
public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) {
  return webClient.method(HttpMethod.valueOf(request.method()))
      .uri(request.uri())
      .headers(httpHeaders -> setUpHeaders(request, httpHeaders))
      .body(provideBody(request))
      .exchange()
      .onErrorMap(ex -> ex instanceof io.netty.handler.timeout.ReadTimeoutException,
          ReadTimeoutException::new)
      .map(response -> new WebReactiveHttpResponse(response, returnPublisherType, returnActualType));
}

代码示例来源:origin: org.springframework.vault/spring-vault-core

private Mono<Object> doHttpRequest(HttpRequestNode<Object> step, Object state) {
  HttpRequest<Object> definition = step.getDefinition();
  HttpEntity<?> entity = getEntity(definition.getEntity(), state);
  RequestBodySpec spec;
  if (definition.getUri() == null) {
    spec = webClient.method(definition.getMethod()).uri(
        definition.getUriTemplate(), (Object[]) definition.getUrlVariables());
  }
  else {
    spec = webClient.method(definition.getMethod()).uri(definition.getUri());
  }
  for (Entry<String, List<String>> header : entity.getHeaders().entrySet()) {
    spec = spec.header(header.getKey(), header.getValue().get(0));
  }
  if (entity.getBody() != null && !entity.getBody().equals(Undefinded.INSTANCE)) {
    return spec.syncBody(entity.getBody()).retrieve()
        .bodyToMono(definition.getResponseType());
  }
  return spec.retrieve().bodyToMono(definition.getResponseType());
}

代码示例来源:origin: io.github.reactivefeign/feign-reactive-core

@Override
public Publisher<Object> executeRequest(ReactiveHttpRequest request) {
  ReactiveHttpRequest requestPreprocessed = requestInterceptor.apply(request);
  logger.logRequest(methodTag, requestPreprocessed);
  long start = System.currentTimeMillis();
  WebClient.ResponseSpec response = webClient.method(requestPreprocessed.method())
      .uri(requestPreprocessed.uri())
      .headers(httpHeaders -> setUpHeaders(requestPreprocessed, httpHeaders))
      .body(provideBody(requestPreprocessed))
      .retrieve()
      .onStatus(httpStatus -> true, resp -> handleResponseStatus(metadata.configKey(), resp, start));
  if (returnPublisherType == Mono.class) {
    return response.bodyToMono(returnActualType).map(responseLogger(start));
  }
  else {
    return response.bodyToFlux(returnActualType).map(responseLogger(start));
  }
}

代码示例来源:origin: com.holon-platform.reactor/holon-reactor-spring

final RequestBodySpec spec = client.method(requestMethod).uri(ub -> {

代码示例来源:origin: wangguobo/demo-spring-webflux-api-gateway

String path = frontEndReq.getPath().pathWithinApplication().value();
HttpMethod httpMethod = frontEndReq.getMethod();
RequestBodySpec reqBodySpec = webClient.method(httpMethod).
    uri(backendServiceUrlPrefix.concat(path)).
    headers(httpHeaders ->

相关文章