Ensure debug flag gets resolved in controller
This commit is contained in:
@@ -23,7 +23,6 @@ import java.util.function.Supplier;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.function.context.FunctionInspector;
|
||||
import org.springframework.cloud.function.web.flux.request.FluxRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -50,13 +49,16 @@ public class FunctionController {
|
||||
|
||||
private FunctionInspector inspector;
|
||||
|
||||
@Value("${debug:${DEBUG:false}}")
|
||||
private boolean debug = false;
|
||||
|
||||
public FunctionController(FunctionInspector inspector) {
|
||||
this.inspector = inspector;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/**")
|
||||
@ResponseBody
|
||||
public ResponseEntity<Flux<?>> post(
|
||||
@@ -65,7 +67,11 @@ public class FunctionController {
|
||||
@RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.input_single") Boolean single,
|
||||
@RequestBody FluxRequest<?> body) {
|
||||
if (function != null) {
|
||||
Flux<?> result = (Flux<?>) function.apply(body.flux());
|
||||
Flux<?> flux = body.flux();
|
||||
if (debug) {
|
||||
flux = flux.log();
|
||||
}
|
||||
Flux<?> result = function.apply(flux);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Handled POST with function");
|
||||
}
|
||||
@@ -73,6 +79,9 @@ public class FunctionController {
|
||||
}
|
||||
if (consumer != null) {
|
||||
Flux<?> flux = body.flux().cache(); // send a copy back to the caller
|
||||
if (debug) {
|
||||
flux = flux.log();
|
||||
}
|
||||
consumer.accept(flux);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Handled POST with consumer");
|
||||
|
||||
@@ -50,6 +50,9 @@ public class FunctionHandlerMapping extends RequestMappingHandlerMapping
|
||||
@Value("${spring.cloud.function.web.path:}")
|
||||
private String prefix = "";
|
||||
|
||||
@Value("${debug:${DEBUG:false}}")
|
||||
private boolean debug = false;
|
||||
|
||||
@Autowired
|
||||
public FunctionHandlerMapping(FunctionCatalog catalog, FunctionInspector inspector) {
|
||||
this.functions = catalog;
|
||||
@@ -61,6 +64,7 @@ public class FunctionHandlerMapping extends RequestMappingHandlerMapping
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
this.controller.setDebug(debug);
|
||||
detectHandlerMethods(controller);
|
||||
while (prefix.endsWith("/")) {
|
||||
prefix = prefix.substring(0, prefix.length() - 1);
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -65,7 +66,7 @@ public class RestApplicationTests {
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
@Autowired
|
||||
private TestConfiguration test;
|
||||
private ApplicationConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
@@ -389,8 +390,8 @@ public class RestApplicationTests {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
public static class TestConfiguration {
|
||||
@TestConfiguration
|
||||
public static class ApplicationConfiguration {
|
||||
|
||||
private List<String> list = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user