Java 类org.springframework.http.client.reactive.ClientHttpRequest 实例源码

项目:spring-webflux-client    文件:RequestTemplate.java   
private BodyInserter<?, ? super ClientHttpRequest> buildBody(Object[] args) {
    if (bodyIndex == null) {
        return BodyInserters.empty();
    }

    Object body = args[bodyIndex];
    if (isDataBufferPublisher(requestBodyType)) {
        return BodyInserters.fromDataBuffers((Publisher<DataBuffer>) body);
    } else if (isPublisher(requestBodyType)) {
        return BodyInserters.fromPublisher((Publisher) body, requestBodyType.getGeneric(0).getRawClass());
    } else if (isResource(requestBodyType)) {
        return BodyInserters.fromResource((Resource) body);
    } else if (isFormData(requestBodyType)) {
        return BodyInserters.fromFormData((MultiValueMap<String, String>) body);
    } else {
        return BodyInserters.fromObject(body);
    }
}
项目:spring-vault    文件:AuthenticationStepsOperatorUnitTests.java   
@Test
public void justLoginRequestShouldLogin() {

    ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST,
            "/auth/cert/login");
    MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
    response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
    response.setBody("{"
            + "\"auth\":{\"client_token\":\"my-token\", \"renewable\": true, \"lease_duration\": 10}"
            + "}");
    ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(
            Mono.just(response));

    WebClient webClient = WebClient.builder().clientConnector(connector).build();

    AuthenticationSteps steps = AuthenticationSteps.just(post("/auth/{path}/login",
            "cert").as(VaultResponse.class));

    StepVerifier.create(login(steps, webClient))
            .expectNext(VaultToken.of("my-token")).verifyComplete();
}
项目:spring-vault    文件:AuthenticationStepsOperatorUnitTests.java   
@Test
public void justLoginShouldFail() {

    ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST,
            "/auth/cert/login");
    MockClientHttpResponse response = new MockClientHttpResponse(
            HttpStatus.BAD_REQUEST);
    ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(
            Mono.just(response));

    WebClient webClient = WebClient.builder().clientConnector(connector).build();

    AuthenticationSteps steps = AuthenticationSteps.just(post("/auth/{path}/login",
            "cert").as(VaultResponse.class));

    StepVerifier.create(login(steps, webClient)).expectError().verify();
}
项目:spring-webflux-client    文件:RequestTemplate.java   
private BodyInserter<?, ? super ClientHttpRequest> buildBody(Object[] args) {
    if (bodyIndex == null) {
        return BodyInserters.empty();
    }

    Object body = args[bodyIndex];
    if (isDataBufferPublisher(requestBodyType)) {
        return BodyInserters.fromDataBuffers((Publisher<DataBuffer>) body);
    } else if (isPublisher(requestBodyType)) {
        return BodyInserters.fromPublisher((Publisher) body, requestBodyType.getGeneric(0).getRawClass());
    } else if (isResource(requestBodyType)) {
        return BodyInserters.fromResource((Resource) body);
    } else if (isFormData(requestBodyType)) {
        return BodyInserters.fromFormData((MultiValueMap<String, String>) body);
    } else {
        return BodyInserters.fromObject(body);
    }
}
项目:spring-webflux-client    文件:DefaultRequest.java   
public DefaultRequest(UriBuilder uriBuilder,
                      HttpMethod httpMethod,
                      HttpHeaders httpHeaders,
                      Map<String, Object> variables,
                      BodyInserter<?, ? super ClientHttpRequest> bodyInserter) {

    this.uriBuilder = uriBuilder;
    this.httpMethod = httpMethod;
    this.bodyInserter = bodyInserter;
    this.variables = new HashMap<>();
    this.variables.putAll(variables);
    this.httpHeaders = new HttpHeaders();
    this.httpHeaders.putAll(httpHeaders);
}
项目:spring-webflux-client    文件:DefaultRequest.java   
public DefaultRequest(UriBuilder uriBuilder,
                      HttpMethod httpMethod,
                      HttpHeaders httpHeaders,
                      Map<String, Object> variables,
                      BodyInserter<?, ? super ClientHttpRequest> bodyInserter) {

    this.uriBuilder = uriBuilder;
    this.httpMethod = httpMethod;
    this.bodyInserter = bodyInserter;
    this.variables = new HashMap<>();
    this.variables.putAll(variables);
    this.httpHeaders = new HttpHeaders();
    this.httpHeaders.putAll(httpHeaders);
}
项目:spring-boot-admin    文件:AbstractInstancesProxyController.java   
protected Mono<ClientResponse> forward(String instanceId,
                                       URI uri,
                                       HttpMethod method,
                                       HttpHeaders headers,
                                       Supplier<BodyInserter<?, ? super ClientHttpRequest>> bodyInserter) {
    log.trace("Proxy-Request for instance {} / {}", instanceId, uri);

    WebClient.RequestBodySpec bodySpec = instanceWebClient.instance(registry.getInstance(InstanceId.of(instanceId)))
                                                          .method(method)
                                                          .uri(uri)
                                                          .headers(instanceHeaders -> instanceHeaders.addAll(
                                                                  filterHeaders(headers)));

    WebClient.RequestHeadersSpec<?> headersSpec = bodySpec;
    if (requiresBody(method)) {
        try {
            headersSpec = bodySpec.body(bodyInserter.get());
        } catch (Exception ex) {
            return Mono.error(ex);
        }
    }

    return headersSpec.exchange()
                      .onErrorMap(InstanceWebClientException.class,
                              error -> new ResponseStatusException(HttpStatus.BAD_REQUEST, null, error))
                      .onErrorMap(ConnectException.class,
                              error -> new ResponseStatusException(HttpStatus.BAD_GATEWAY, null, error));
}
项目:spring-webflux-client    文件:DefaultRequest.java   
@Override
public BodyInserter<?, ? super ClientHttpRequest> bodyInserter() {
    return bodyInserter;
}
项目:spring-webflux-client    文件:MockRequest.java   
@Override
public BodyInserter<?, ? super ClientHttpRequest> bodyInserter() {
    return bodyInserter;
}
项目:spring-webflux-client    文件:DefaultRequest.java   
@Override
public BodyInserter<?, ? super ClientHttpRequest> bodyInserter() {
    return bodyInserter;
}
项目:spring-webflux-client    文件:MockRequest.java   
@Override
public BodyInserter<?, ? super ClientHttpRequest> bodyInserter() {
    return bodyInserter;
}
项目:spring-webflux-client    文件:Request.java   
BodyInserter<?, ? super ClientHttpRequest> bodyInserter();
项目:spring-webflux-client    文件:Request.java   
BodyInserter<?, ? super ClientHttpRequest> bodyInserter();