GH-1025 Add POST tests and cleanup
This commit is contained in:
@@ -62,7 +62,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Mono<ResponseEntity<?>> form(ServerWebExchange request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return request.getFormData().doOnSuccess(params -> wrapper.getParams().addAll(params))
|
||||
.then(Mono.defer(() -> (Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper
|
||||
.processRequest(wrapper, wrapper.getParams(), false)));
|
||||
@@ -78,7 +78,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Mono<ResponseEntity<?>> multipart(ServerWebExchange request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return request.getMultipartData()
|
||||
.doOnSuccess(params -> wrapper.getParams().addAll(multi(params)))
|
||||
.then(Mono.defer(() -> (Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper
|
||||
@@ -95,7 +95,7 @@ public class FunctionController {
|
||||
public Mono<ResponseEntity<?>> post(ServerWebExchange request,
|
||||
@RequestBody(required = false) String body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return (Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper.processRequest(wrapper, body, false);
|
||||
}
|
||||
else {
|
||||
@@ -109,7 +109,7 @@ public class FunctionController {
|
||||
public Mono<ResponseEntity<?>> put(ServerWebExchange request,
|
||||
@RequestBody(required = false) String body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("PUT", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("PUT", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return (Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper.processRequest(wrapper, body, false);
|
||||
}
|
||||
else {
|
||||
@@ -123,7 +123,7 @@ public class FunctionController {
|
||||
public Mono<ResponseEntity<?>> delete(ServerWebExchange request,
|
||||
@RequestBody(required = false) String body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("DELETE", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("DELETE", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return (Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper.processRequest(wrapper, body, false);
|
||||
}
|
||||
else {
|
||||
@@ -135,7 +135,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Publisher<?> postStream(ServerWebExchange request, @RequestBody(required = false) Flux<String> body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return FunctionWebRequestProcessingHelper.processRequest(wrapper, body, true);
|
||||
}
|
||||
else {
|
||||
@@ -148,7 +148,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Publisher<?> getStream(ServerWebExchange request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return FunctionWebRequestProcessingHelper.processRequest(wrapper, wrapper.getArgument(), true);
|
||||
}
|
||||
else {
|
||||
@@ -161,7 +161,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Mono<ResponseEntity<?>> get(ServerWebExchange request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return (Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper.processRequest(wrapper, wrapper.getArgument(), false);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -75,7 +75,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Object form(WebRequest request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (((ServletWebRequest) request).getRequest() instanceof StandardMultipartHttpServletRequest) {
|
||||
MultiValueMap<String, MultipartFile> multiFileMap = ((StandardMultipartHttpServletRequest) ((ServletWebRequest) request)
|
||||
.getRequest()).getMultiFileMap();
|
||||
@@ -109,7 +109,7 @@ public class FunctionController {
|
||||
@RequestBody(required = false) String body) {
|
||||
String argument = StringUtils.hasText(body) ? body : "";
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return ((Mono<ResponseEntity<?>>) FunctionWebRequestProcessingHelper.processRequest(wrapper, argument, true)).map(response -> ResponseEntity.ok()
|
||||
.headers(response.getHeaders()).body((Publisher<?>) response.getBody()));
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Publisher<?> getStream(WebRequest request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return FunctionWebRequestProcessingHelper.processRequest(wrapper, wrapper.getArgument(), true);
|
||||
}
|
||||
else {
|
||||
@@ -134,7 +134,8 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Object post(WebRequest request, @RequestBody(required = false) String body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("POST", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
Assert.isTrue(!wrapper.getFunction().isSupplier(), "'POST' can only be mapped to Function or Consumer");
|
||||
return FunctionWebRequestProcessingHelper.processRequest(wrapper, body, false);
|
||||
}
|
||||
else {
|
||||
@@ -146,7 +147,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Object put(WebRequest request, @RequestBody(required = false) String body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("PUT", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("PUT", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return FunctionWebRequestProcessingHelper.processRequest(wrapper, body, false);
|
||||
}
|
||||
else {
|
||||
@@ -155,10 +156,10 @@ public class FunctionController {
|
||||
}
|
||||
|
||||
@DeleteMapping(path = "/**")
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void delete(WebRequest request, @RequestBody(required = false) String body) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("DELETE", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("DELETE", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
Assert.isTrue(wrapper.getFunction().isConsumer(), "'DELETE' can only be mapped to Consumer");
|
||||
FunctionWebRequestProcessingHelper.processRequest(wrapper, wrapper.getArgument(), false);
|
||||
}
|
||||
@@ -171,7 +172,7 @@ public class FunctionController {
|
||||
@ResponseBody
|
||||
public Object get(WebRequest request) {
|
||||
FunctionWrapper wrapper = wrapper(request);
|
||||
if (FunctionWebRequestProcessingHelper.isValidFunction("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
if (FunctionWebRequestProcessingHelper.isFunctionValidForMethod("GET", wrapper.getFunction().getFunctionDefinition(), this.functionHttpProperties)) {
|
||||
return FunctionWebRequestProcessingHelper.processRequest(wrapper, wrapper.getArgument(), false);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class FunctionWebRequestProcessingHelper {
|
||||
return postProcessResult(result, isMessage);
|
||||
}
|
||||
|
||||
public static boolean isValidFunction(String httpMethod, String functionDefinition, FunctionHttpProperties functionHttpProperties) {
|
||||
public static boolean isFunctionValidForMethod(String httpMethod, String functionDefinition, FunctionHttpProperties functionHttpProperties) {
|
||||
String functionDefinitions = null;
|
||||
switch (httpMethod) {
|
||||
case "GET":
|
||||
@@ -92,7 +92,7 @@ public final class FunctionWebRequestProcessingHelper {
|
||||
if (StringUtils.hasText(functionDefinitions)) {
|
||||
return Arrays.asList(functionDefinitions.split(";")).contains(functionDefinition);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String buildBadMappingErrorMessage(String httpMethod, String functionDefinition) {
|
||||
@@ -135,7 +135,7 @@ public final class FunctionWebRequestProcessingHelper {
|
||||
Mono.from((Publisher) result).subscribe();
|
||||
}
|
||||
return "DELETE".equals(wrapper.getMethod()) ?
|
||||
Mono.empty() : Mono.just(ResponseEntity.ok().headers(HeaderUtils.sanitize(headers)).build());
|
||||
Mono.empty() : Mono.just(ResponseEntity.accepted().headers(HeaderUtils.sanitize(headers)).build());
|
||||
}
|
||||
|
||||
BodyBuilder responseOkBuilder = ResponseEntity.ok().headers(HeaderUtils.sanitize(headers));
|
||||
|
||||
Reference in New Issue
Block a user