Codota Logo
ClientResponse$Builder.build
Code IndexAdd Codota to your IDE (free)

How to use
build
method
in
org.springframework.web.reactive.function.client.ClientResponse$Builder

Best Java code snippets using org.springframework.web.reactive.function.client.ClientResponse$Builder.build (Showing top 12 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: codecentric/spring-boot-admin

protected Mono<ClientResponse> forward(String instanceId,
                    URI uri,
                    HttpMethod method,
                    HttpHeaders headers,
                    Supplier<BodyInserter<?, ? super ClientHttpRequest>> bodyInserter) {
  log.trace("Proxy-Request for instance {} with URL '{}'", instanceId, uri);
  return registry.getInstance(InstanceId.of(instanceId))
          .flatMap(instance -> forward(instance, uri, method, headers, bodyInserter))
          .switchIfEmpty(Mono.fromSupplier(() -> ClientResponse.create(HttpStatus.SERVICE_UNAVAILABLE, strategies).build()));
}
origin: codecentric/spring-boot-admin

private static Function<ClientResponse, Mono<ClientResponse>> convertClientResponse(Function<Flux<DataBuffer>, Flux<DataBuffer>> bodConverter,
                                          MediaType contentType) {
  return response -> {
    ClientResponse convertedResponse = ClientResponse.from(response).headers(headers -> {
      headers.replace(HttpHeaders.CONTENT_TYPE, singletonList(contentType.toString()));
      headers.remove(HttpHeaders.CONTENT_LENGTH);
    }).body(response.bodyToFlux(DataBuffer.class).transform(bodConverter)).build();
    return Mono.just(convertedResponse);
  };
}
origin: spring-projects/spring-framework

/**
 * Consume up to the specified number of bytes from the response body and
 * cancel if any more data arrives.
 * <p>Internally delegates to {@link DataBufferUtils#takeUntilByteCount}.
 * @param maxByteCount the limit as number of bytes
 * @return the filter to limit the response size with
 * @since 5.1
 */
public static ExchangeFilterFunction limitResponseSize(long maxByteCount) {
  return (request, next) ->
      next.exchange(request).map(response -> {
        Flux<DataBuffer> body = response.body(BodyExtractors.toDataBuffers());
        body = DataBufferUtils.takeUntilByteCount(body, maxByteCount);
        return ClientResponse.from(response).body(body).build();
      });
}
origin: spring-projects/spring-framework

@Test
public void normal() {
  Flux<DataBuffer> body = Flux.just("baz")
      .map(s -> s.getBytes(StandardCharsets.UTF_8))
      .map(dataBufferFactory::wrap);
  ClientResponse response = ClientResponse.create(HttpStatus.BAD_GATEWAY, ExchangeStrategies.withDefaults())
      .header("foo", "bar")
      .cookie("baz", "qux")
      .body(body)
      .build();
  assertEquals(HttpStatus.BAD_GATEWAY, response.statusCode());
  HttpHeaders responseHeaders = response.headers().asHttpHeaders();
  assertEquals("bar", responseHeaders.getFirst("foo"));
  assertNotNull("qux", response.cookies().getFirst("baz"));
  assertEquals("qux", response.cookies().getFirst("baz").getValue());
  StepVerifier.create(response.bodyToFlux(String.class))
      .expectNext("baz")
      .verifyComplete();
}
origin: spring-projects/spring-framework

@Test
public void from() {
  Flux<DataBuffer> otherBody = Flux.just("foo", "bar")
      .map(s -> s.getBytes(StandardCharsets.UTF_8))
      .map(dataBufferFactory::wrap);
  ClientResponse other = ClientResponse.create(HttpStatus.BAD_REQUEST, ExchangeStrategies.withDefaults())
      .header("foo", "bar")
      .cookie("baz", "qux")
      .body(otherBody)
      .build();
  Flux<DataBuffer> body = Flux.just("baz")
      .map(s -> s.getBytes(StandardCharsets.UTF_8))
      .map(dataBufferFactory::wrap);
  ClientResponse result = ClientResponse.from(other)
      .headers(httpHeaders -> httpHeaders.set("foo", "baar"))
      .cookies(cookies -> cookies.set("baz", ResponseCookie.from("baz", "quux").build()))
      .body(body)
      .build();
  assertEquals(HttpStatus.BAD_REQUEST, result.statusCode());
  assertEquals(1, result.headers().asHttpHeaders().size());
  assertEquals("baar", result.headers().asHttpHeaders().getFirst("foo"));
  assertEquals(1, result.cookies().size());
  assertEquals("quux", result.cookies().getFirst("baz").getValue());
  StepVerifier.create(result.bodyToFlux(String.class))
      .expectNext("baz")
      .verifyComplete();
}
origin: spring-projects/spring-framework

@Test
public void limitResponseSize() {
  DefaultDataBufferFactory bufferFactory = new DefaultDataBufferFactory();
  DataBuffer b1 = dataBuffer("foo", bufferFactory);
  DataBuffer b2 = dataBuffer("bar", bufferFactory);
  DataBuffer b3 = dataBuffer("baz", bufferFactory);
  ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
  ClientResponse response = ClientResponse.create(HttpStatus.OK).body(Flux.just(b1, b2, b3)).build();
  Mono<ClientResponse> result = ExchangeFilterFunctions.limitResponseSize(5)
      .filter(request, req -> Mono.just(response));
  StepVerifier.create(result.flatMapMany(res -> res.body(BodyExtractors.toDataBuffers())))
      .consumeNextWith(buffer -> assertEquals("foo", string(buffer)))
      .consumeNextWith(buffer -> assertEquals("ba", string(buffer)))
      .expectComplete()
      .verify();
}
origin: spring-cloud/spring-cloud-sleuth

@Override
public void onNext(ClientResponse response) {
  this.done = true;
  try {
    // decorate response body
    this.actual
        .onNext(ClientResponse.from(response)
            .body(response.bodyToFlux(DataBuffer.class)
                .transform(this.scopePassingTransformer))
            .build());
  }
  finally {
    terminateSpan(response, null);
  }
}
origin: spring-projects/spring-data-elasticsearch

.onErrorReturn(ConnectException.class, ClientResponse.create(HttpStatus.SERVICE_UNAVAILABLE).build());
origin: org.springframework.cloud/spring-cloud-commons

@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
  URI originalUrl = request.url();
  String serviceId = originalUrl.getHost();
  if(serviceId == null) {
    String msg = String.format("Request URI does not contain a valid hostname: %s", originalUrl.toString());
    logger.warn(msg);
    return Mono.just(ClientResponse.create(HttpStatus.BAD_REQUEST).body(msg).build());
  }
  //TODO: reactive lb client
  ServiceInstance instance = this.loadBalancerClient.choose(serviceId);
  if(instance == null) {
    String msg = String.format("Load balancer does not contain an instance for the service %s", serviceId);
    logger.warn(msg);
    return Mono.just(ClientResponse.create(HttpStatus.SERVICE_UNAVAILABLE).body(msg).build());
  }
  URI uri = this.loadBalancerClient.reconstructURI(instance, originalUrl);
  ClientRequest newRequest = ClientRequest.method(request.method(), uri)
      .headers(headers -> headers.addAll(request.headers()))
      .cookies(cookies -> cookies.addAll(request.cookies()))
      .attributes(attributes -> attributes.putAll(request.attributes()))
      .body(request.body())
      .build();
  return next.exchange(newRequest);
}
origin: org.springframework.cloud/spring-cloud-sleuth-core

@Override
public void onNext(ClientResponse response) {
  this.done = true;
  try {
    // decorate response body
    this.actual
        .onNext(ClientResponse.from(response)
            .body(response.bodyToFlux(DataBuffer.class)
                .transform(this.scopePassingTransformer))
            .build());
  }
  finally {
    terminateSpan(response, null);
  }
}
origin: spring-cloud/spring-cloud-commons

@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
  URI originalUrl = request.url();
  String serviceId = originalUrl.getHost();
  if(serviceId == null) {
    String msg = String.format("Request URI does not contain a valid hostname: %s", originalUrl.toString());
    logger.warn(msg);
    return Mono.just(ClientResponse.create(HttpStatus.BAD_REQUEST).body(msg).build());
  }
  //TODO: reactive lb client
  ServiceInstance instance = this.loadBalancerClient.choose(serviceId);
  if(instance == null) {
    String msg = String.format("Load balancer does not contain an instance for the service %s", serviceId);
    logger.warn(msg);
    return Mono.just(ClientResponse.create(HttpStatus.SERVICE_UNAVAILABLE).body(msg).build());
  }
  URI uri = this.loadBalancerClient.reconstructURI(instance, originalUrl);
  ClientRequest newRequest = ClientRequest.method(request.method(), uri)
      .headers(headers -> headers.addAll(request.headers()))
      .cookies(cookies -> cookies.addAll(request.cookies()))
      .attributes(attributes -> attributes.putAll(request.attributes()))
      .body(request.body())
      .build();
  return next.exchange(newRequest);
}
origin: codecentric/spring-boot-admin

  return ClientResponse.create(HttpStatus.GATEWAY_TIMEOUT, strategies).build();
})).onErrorResume(ResolveEndpointException.class, ex -> Mono.fromSupplier(() -> {
  log.trace("No Endpoint found for Proxy-Request for instance {} with URL '{}'", instance.getId(), uri);
  return ClientResponse.create(HttpStatus.NOT_FOUND, strategies).build();
})).onErrorResume(IOException.class, ex -> Mono.fromSupplier(() -> {
  log.trace("Proxy-Request for instance {} with URL '{}' errored", instance.getId(), uri, ex);
  return ClientResponse.create(HttpStatus.BAD_GATEWAY, strategies).build();
})).onErrorResume(ConnectException.class, ex -> Mono.fromSupplier(() -> {
  log.trace("Connect for Proxy-Request for instance {} with URL '{}' failed", instance.getId(), uri, ex);
  return ClientResponse.create(HttpStatus.BAD_GATEWAY, strategies).build();
}));
org.springframework.web.reactive.function.clientClientResponse$Builderbuild

Javadoc

Build the response.

Popular methods of ClientResponse$Builder

  • body
  • headers
    Manipulate this response's headers with the given consumer. The headers provided to the consumer are
  • cookie
    Add a cookie with the given name and value(s).
  • cookies
    Manipulate this response's cookies with the given consumer. The map provided to the consumer is "liv
  • header
    Add the given header value(s) under the given name.

Popular in Java

  • Running tasks concurrently on multiple threads
  • compareTo (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Timer (java.util)
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be s
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now