Java Code Examples for org.springframework.web.reactive.function.server.RouterFunctions#route()

The following examples show how to use org.springframework.web.reactive.function.server.RouterFunctions#route() . 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: StudentRouterHandlerCombined.java    From Spring-5.0-Projects with MIT License 5 votes vote down vote up
@Bean
RouterFunction<ServerResponse> returnAllStudentWithCombineFun(){
	
       HandlerFunction<ServerResponse> studentHandler = 
               serverRequest -> 
            	  ServerResponse.ok().body(studentMongoRepository.findAll(), Student.class);
	
	RouterFunction<ServerResponse> studentResponse =
   		RouterFunctions.route(RequestPredicates.GET("/api/f/combine/getAllStudent"),
   				studentHandler);
	
	return studentResponse;
   }
 
Example 2
Source File: Chapter5ReactiveApplication.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routerFunction(
	SensorReadingRepository sensorReadingRepository
) {
	return RouterFunctions
		.route(
			GET("/"),
			serverRequest -> ServerResponse
				.ok()
				.contentType(MediaType.APPLICATION_STREAM_JSON)
				.body(sensorReadingRepository.findBy(), SensorsReadings.class));
}
 
Example 3
Source File: CityRouter.java    From springboot-learning-example with Apache License 2.0 5 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routeCity(CityHandler cityHandler) {
    return RouterFunctions
            .route(RequestPredicates.GET("/hello")
                            .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                    cityHandler::helloCity);
}
 
Example 4
Source File: GatewaySampleApplication.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> testWhenMetricPathIsNotMeet() {
	RouterFunction<ServerResponse> route = RouterFunctions.route(
			RequestPredicates.path("/actuator/metrics/gateway.requests"),
			request -> ServerResponse.ok().body(BodyInserters
					.fromValue(HELLO_FROM_FAKE_ACTUATOR_METRICS_GATEWAY_REQUESTS)));
	return route;
}
 
Example 5
Source File: WebFluxServerDsl.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
/**
 * Configure routes via {@link RouterFunctions.Builder}.
 * @see org.springframework.fu.jafu.BeanDefinitionDsl#bean(Class, BeanDefinitionCustomizer...)
 */
public WebFluxServerDsl router(Consumer<RouterFunctions.Builder> routerDsl) {
	RouterFunctions.Builder builder = RouterFunctions.route();
	context.registerBean(BeanDefinitionReaderUtils.uniqueBeanName(RouterFunction.class.getName(), context), RouterFunction.class, () -> {
		routerDsl.accept(builder);
		return builder.build();
	});
	return this;
}
 
Example 6
Source File: RouterConfiguration.java    From chaos-monkey-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> route(HelloComponent greetingHandler) {

  return RouterFunctions.route(
      RequestPredicates.GET("/hello").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
      greetingHandler::hello);
}
 
Example 7
Source File: Router1.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routeRequest1(Handler1 handler) {
    return RouterFunctions.route(RequestPredicates.GET("/api/endpoint1")
        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), handler::handleRequest1);
}
 
Example 8
Source File: RoutingConfiguration.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routerFunction(TestHandler testHandler) {
    return RouterFunctions.route(GET("/testcase/route/{test}"), testHandler::test);
}
 
Example 9
Source File: StudentRouter.java    From Spring-5.0-Projects with MIT License 4 votes vote down vote up
@Bean
RouterFunction<ServerResponse> returnAllStudent() {
    return RouterFunctions.route(RequestPredicates.GET("/api/f/getAllStudent"),
    		studentHandler::getAllStudent);
}
 
Example 10
Source File: ExampleRouter.java    From webflux-streaming-demo with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> findByGender(ExampleHandler exampleHandler) {
    return RouterFunctions.route(RequestPredicates
            .GET("/functional/user/{gender}")
            .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), exampleHandler::findByGender);
}
 
Example 11
Source File: ExampleRouter.java    From webflux-streaming-demo with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> listAll(ExampleHandler exampleHandler) {
    return RouterFunctions.route(RequestPredicates
            .GET("/functional/user/list")
            .and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), exampleHandler::findAll);
}
 
Example 12
Source File: CorsRouterFunctions.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> corsGlobalRouter(@Autowired CorsGlobalFunctionalHandler handler) {
    return RouterFunctions.route(RequestPredicates.PUT("/global-config-on-functional/cors-disabled-functional-endpoint"), handler::useHandler);
}
 
Example 13
Source File: AppConfig.java    From pf4j-spring-tutorial with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> route() {
    return RouterFunctions.route(GET("/hello")
                    .and(accept(MediaType.TEXT_PLAIN)),
            req -> ServerResponse.ok().body(Mono.just("Reactive endpoint on contaainer"), String.class));
}
 
Example 14
Source File: CorsWithWebFilterRouterFunctions.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> corsWebfilterRouter(@Autowired CorsWithWebFilterHandler handler) {
    return RouterFunctions.route(RequestPredicates.PUT("/web-filter-on-functional/functional-endpoint"), handler::useHandler);
}
 
Example 15
Source File: Router5.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routeRequest5(Handler5 handler) {
    return RouterFunctions.route(RequestPredicates.GET("/api/endpoint5")
        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), handler::handleRequest5);
}
 
Example 16
Source File: HelloWorldRouter.java    From journaldev with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routeHelloWorld(HelloWorldHandler helloWorldHandler) {

	return RouterFunctions
		.route(RequestPredicates.GET("/helloWorld").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), helloWorldHandler::helloWorld);
}
 
Example 17
Source File: JsonExceptionHandler.java    From sophia_scaffolding with Apache License 2.0 4 votes vote down vote up
/**
 * 指定响应处理方法为JSON处理的方法
 * @param errorAttributes
 */
@Override
protected RouterFunction<ServerResponse> getRoutingFunction(ErrorAttributes errorAttributes) {
    return RouterFunctions.route(RequestPredicates.all(), this::renderErrorResponse);
}
 
Example 18
Source File: CityRouter.java    From springboot-learning-example with Apache License 2.0 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routeCity(CityHandler cityHandler) {
    return RouterFunctions.route(RequestPredicates.GET("/hello").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), cityHandler::helloCity);
}
 
Example 19
Source File: GlobalErrorWebExceptionHandler.java    From springboot-learning-example with Apache License 2.0 4 votes vote down vote up
@Override
protected RouterFunction<ServerResponse> getRoutingFunction(final ErrorAttributes errorAttributes) {
    return RouterFunctions.route(RequestPredicates.all(), this::renderErrorResponse);
}
 
Example 20
Source File: Router2.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routeRequest2(Handler2 handler) {
    return RouterFunctions.route(RequestPredicates.GET("/api/endpoint2")
        .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), handler::handleRequest2);
}