Created
November 6, 2017 09:02
-
-
Save alexcheng1982/ece6a063de6c7cfe175c5a3ecd53b036 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class Config { | |
@Bean | |
@Autowired | |
public RouterFunction<ServerResponse> routerFunction(final CalculatorHandler calculatorHandler) { | |
return RouterFunctions.route(RequestPredicates.path("/calculator"), request -> | |
request.queryParam("operator").map(operator -> | |
Mono.justOrEmpty( | |
ReflectionUtils.findMethod(CalculatorHandler.class, operator, ServerRequest.class)) | |
.flatMap(method -> (Mono<ServerResponse>) ReflectionUtils | |
.invokeMethod(method, calculatorHandler, request)) | |
.switchIfEmpty(ServerResponse.badRequest().build()) | |
.onErrorResume( | |
ex -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build())) | |
.orElse(ServerResponse.badRequest().build())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment