Java Code Examples for org.springframework.web.reactive.function.client.WebClient#create()

The following examples show how to use org.springframework.web.reactive.function.client.WebClient#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebFluxIT.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    DisposableServer httpServer = HttpServer.create()
            .host("localhost")
            .port(port)
            .handle(new ReactorHttpHandlerAdapter(new MyHttpHandler()))
            .bind()
            .block();

    WebClient client = WebClient.create("http://localhost:" + port);
    client.get()
            .uri("/webflux/abc")
            .retrieve()
            .bodyToMono(String.class)
            .block();

    httpServer.dispose();
}
 
Example 2
Source File: CustomerIntegrationTest.java    From coditori with Apache License 2.0 5 votes vote down vote up
@Test
public void test2_add_customer_done() {
    WebClient webClient = WebClient.create("http://localhost:" + port);
    Customer customer = webClient.post().uri("/customers")
            .contentType(MediaType.APPLICATION_JSON)
            .body(BodyInserters.fromObject(newCustomer))
            .retrieve()
            .bodyToMono(Customer.class)
            .block();

    id = customer.getId();
    assertThat(customer.getName(), is(newCustomer.getName()));
}
 
Example 3
Source File: WebClientMain.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 5 votes vote down vote up
public void readFibonacciNumbers() {
    WebClient client = WebClient.create("http://localhost:8080");
    Flux<Long> result = client.get()
            .uri("/fibonacci").accept(MediaType.APPLICATION_JSON)
            .retrieve()
            .bodyToFlux(Long.class);

    result.subscribe( x-> System.out.println(x));
}
 
Example 4
Source File: ReactorMain.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 5 votes vote down vote up
public static void readFibonacciNumbers() {
    System.out.println("***************************** ");
    WebClient client = WebClient.create("http://localhost:8080");
    Flux<Long> result = client.get()
            .uri("/fibonacci")
            .retrieve()
            // .onStatus(HttpStatus::isError, x -> Mono.error(new RuntimeException("Invalid Response ")))
            .bodyToFlux(Long.class)
            .timeout(Duration.ofMillis(500), x-> Flux.just(-1L));
            //.onErrorResume( x -> Flux.just(-1L, -2L))
            //.limitRequest(10L);
    result.subscribe( x-> System.out.println(x));
}
 
Example 5
Source File: WebClientCrawler.java    From Spring-Blog with Apache License 2.0 5 votes vote down vote up
private static void crawlClient() {
    WebClient webClient = WebClient.create();
    Mono<String> resp = webClient
            .method(HttpMethod.GET)
            .uri("http://www.baidu.com/")
            .retrieve()
            .bodyToMono(String.class);

    logger.info("抓取结果:{}", resp.block());
}
 
Example 6
Source File: FilteredWebClientUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenNoUrlModifyingFilter_thenPathUnchanged() {
    stubFor(get(urlPathEqualTo(PATH)).willReturn(aResponse().withStatus(200)
        .withBody("done")));

    WebClient webClient = WebClient.create();
    String actual = sendGetRequest(webClient);

    assertThat(actual).isEqualTo("done");
    verify(getRequestedFor(urlPathEqualTo(PATH)));
}
 
Example 7
Source File: WebClientProducer.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public WebClient webClient(){
    return WebClient.create();
}
 
Example 8
Source File: AuthenticationStepsOperatorUnitTests.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
private Mono<VaultToken> login(AuthenticationSteps steps) {

		AuthenticationStepsOperator operator = new AuthenticationStepsOperator(steps, WebClient.create());
		return operator.getVaultToken();
	}
 
Example 9
Source File: WebClientProducer.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public WebClient webClient(){
    return WebClient.create();
}
 
Example 10
Source File: MultipartIntegrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Before
public void setup() throws Exception {
	super.setup();
	this.webClient = WebClient.create("http://localhost:" + this.port);
}
 
Example 11
Source File: ReactiveWebApplicationTests.java    From Learning-Path-Spring-5-End-to-End-Programming with MIT License 4 votes vote down vote up
@Before
public void setup() {
    this.webClient = WebClient.create("http://localhost:" + this.port);
}
 
Example 12
Source File: SseHandlerFunctionIntegrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Before
public void setup() throws Exception {
	super.setup();
	this.webClient = WebClient.create("http://localhost:" + this.port);
}
 
Example 13
Source File: WebClientProducer.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public WebClient webClient(){
    return WebClient.create();
}
 
Example 14
Source File: WebClientProducer.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public WebClient webClient(){
    return WebClient.create();
}
 
Example 15
Source File: WebClientProducer.java    From Spring-5.0-By-Example with MIT License 4 votes vote down vote up
@Bean
public WebClient webClient(){
    return WebClient.create();
}
 
Example 16
Source File: WebClientTest.java    From hellokoding-courses with MIT License 4 votes vote down vote up
@Test
public void createWebClient() {
    WebClient webClient1 = WebClient.create();
    WebClient webClient2 = WebClient.create("http://localhost:8080");
}
 
Example 17
Source File: MultipartIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Before
public void setup() throws Exception {
	super.setup();
	this.webClient = WebClient.create("http://localhost:" + this.port);
}
 
Example 18
Source File: TraceWebFluxTests.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
WebClient webClient() {
	return WebClient.create();
}
 
Example 19
Source File: SseHandlerFunctionIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Before
public void setup() throws Exception {
	super.setup();
	this.webClient = WebClient.create("http://localhost:" + this.port);
}
 
Example 20
Source File: FlushingIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Before
public void setup() throws Exception {
	super.setup();
	this.webClient = WebClient.create("http://localhost:" + this.port);
}