Example usage for org.springframework.web.reactive.function.client WebClient create

List of usage examples for org.springframework.web.reactive.function.client WebClient create

Introduction

In this page you can find the example usage for org.springframework.web.reactive.function.client WebClient create.

Prototype

static WebClient create(String baseUrl) 

Source Link

Document

Variant of #create() that accepts a default base URL.

Usage

From source file:org.springframework.cloud.gateway.test.BaseWebClientTests.java

@Before
public void setup() {
    //TODO: how to set new ReactorClientHttpConnector()
    baseUri = "http://localhost:" + port;
    this.webClient = WebClient.create(baseUri);
}

From source file:org.springframework.cloud.gateway.test.sse.SseIntegrationTests.java

@Before
public void setup() throws Exception {
    this.server = new ReactorHttpServer();
    this.server.setHandler(createHttpHandler());
    this.server.afterPropertiesSet();
    this.server.start();

    // Set dynamically chosen port
    this.serverPort = this.server.getPort();
    logger.info("SSE Port: " + this.serverPort);

    this.gatewayContext = new SpringApplicationBuilder(GatewayConfig.class)
            .properties("sse.server.port:" + this.serverPort, "server.port=0", "spring.jmx.enabled=false")
            .run();//from  w ww  .j  a  v a 2 s  .  c o m

    ConfigurableEnvironment env = this.gatewayContext.getBean(ConfigurableEnvironment.class);
    this.gatewayPort = Integer.valueOf(env.getProperty("local.server.port"));

    this.webClient = WebClient.create("http://localhost:" + this.gatewayPort + "/sse");

    logger.info("Gateway Port: " + this.gatewayPort);
}

From source file:org.springframework.cloud.netflix.hystrix.HystrixWebfluxControllerTests.java

@Test
public void hystrixStreamWorks() {
    String url = "http://localhost:" + port;
    // you have to hit a Hystrix circuit breaker before the stream sends anything
    WebTestClient testClient = WebTestClient.bindToServer().baseUrl(url).build();
    testClient.get().uri("/").exchange().expectStatus().isOk();

    WebClient client = WebClient.create(url);

    Flux<String> result = client.get().uri(BASE_PATH + "/hystrix.stream").accept(MediaType.TEXT_EVENT_STREAM)
            .exchange().flatMapMany(res -> res.bodyToFlux(Map.class)).take(5)
            .filter(map -> "HystrixCommand".equals(map.get("type"))).map(map -> (String) map.get("type"));

    StepVerifier.create(result).expectNext("HystrixCommand").thenCancel().verify();
}