Revise HttpRequestFunctionConfiguration configuration (#295)

Fixes #286
This commit is contained in:
sunny151091
2022-07-16 05:31:30 +05:30
committed by GitHub
parent 2289afa967
commit 5b5fb8fd0f
2 changed files with 8 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@ import java.util.function.Function;
import reactor.core.publisher.Flux;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,11 +33,14 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilderFactory;
/**
* Configuration for a {@link Function} that makes HTTP requests to a resource and for
* each request, returns a {@link ResponseEntity}.
*
* @author David Turanski
* @author Sunny Hemdev
*
**/
@Configuration
@@ -46,17 +48,8 @@ import org.springframework.web.util.UriBuilderFactory;
public class HttpRequestFunctionConfiguration {
@Bean
@ConditionalOnMissingBean(WebClient.class)
public WebClient webClient(HttpRequestFunctionProperties properties) {
return WebClient.builder()
.codecs(clientCodecConfigurer ->
clientCodecConfigurer.defaultCodecs().maxInMemorySize(properties.getMaximumBufferSize()))
.build();
}
@Bean
public HttpRequestFunction httpRequestFunction(WebClient webClient, HttpRequestFunctionProperties properties) {
return new HttpRequestFunction(webClient, properties);
public HttpRequestFunction httpRequestFunction(WebClient.Builder webClientBuilder, HttpRequestFunctionProperties properties) {
return new HttpRequestFunction(webClientBuilder.build(), properties);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 the original author or authors.
* Copyright 2015-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.cloud.fn.http.request;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.expression.Expression;
@@ -35,6 +34,7 @@ import org.springframework.validation.annotation.Validated;
* @author Christian Tzolov
* @author Artem Bilan
* @author David Turanski
* @author Sunny Hemdev
*/
@Validated
@ConfigurationProperties("http.request")
@@ -52,13 +52,6 @@ public class HttpRequestFunctionProperties {
*/
private long timeout = 30_000;
/**
* Maximum buffer size in bytes allocated for input stream buffers. Defaults to 256k.
* Increase, as necessary, for posting or getting large binary content.
*/
private int maximumBufferSize = 256 * 1024;
/**
* A SpEL expression against incoming message to determine the URL to use.
*/
@@ -119,15 +112,6 @@ public class HttpRequestFunctionProperties {
this.timeout = timeout;
}
@Positive
public int getMaximumBufferSize() {
return maximumBufferSize;
}
public void setMaximumBufferSize(int maximumBufferSize) {
this.maximumBufferSize = maximumBufferSize;
}
public Expression getBodyExpression() {
return bodyExpression;
}