当前位置: 首页>>代码示例>>Java>>正文


Java RouterFunction类代码示例

本文整理汇总了Java中org.springframework.web.reactive.function.server.RouterFunction的典型用法代码示例。如果您正苦于以下问题:Java RouterFunction类的具体用法?Java RouterFunction怎么用?Java RouterFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RouterFunction类属于org.springframework.web.reactive.function.server包,在下文中一共展示了RouterFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stubResponse

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
private RouterFunction<ServerResponse> stubResponse(File baseDirectory) throws IOException {
    log.info("Scanning files in {}", baseDirectory.getAbsolutePath());
    val exceptions = new ArrayList<Exception>();
    val functions = Files.walk(baseDirectory.toPath())
        .filter(path -> path.toFile().isFile())
        .map(path -> new RouteSource(path.toFile()))
        .flatMap(routeSource -> {
            try {
                return routeCompiler.compile(routeSource, baseDirectory)
                    .map(compiledRoute -> Stream.of(RouterFunctions.route(
                        compiledRoute.getRequestPredicate(),
                        routeHandler.proxy(compiledRoute))))
                    .orElse(Stream.empty());
            } catch (Exception e) {
                exceptions.add(e);
                return Stream.empty();
            }
        }).collect(toList());
    return functions.stream().reduce(indexResponse(functions, exceptions), RouterFunction::and);
}
 
开发者ID:int128,项目名称:httpstub,代码行数:21,代码来源:RouteRegistrar.java

示例2: personRoutes

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<?> personRoutes() {
    return RouterFunctions
            .route(GET("/person/{id}").and(accept(APPLICATION_JSON)), request -> {
                String personId = request.pathVariable("id");
                Mono<ServerResponse> notFound = ServerResponse.notFound().build();
                return repository.findById(personId)
                        .flatMap(person -> ServerResponse.ok().body(Mono.just(person), Person.class))
                        .switchIfEmpty(notFound);
            })
            .andRoute(GET("/person").and(accept(APPLICATION_JSON)), request ->
                    ServerResponse.ok().body(repository.findAll(), Person.class))
            .andRoute(POST("/person").and(contentType(APPLICATION_JSON)), request ->
                    ServerResponse.ok().body(service.addPerson(request.bodyToMono(Person.class)), Person.class))
            .andRoute(POST("/person/ip_info/update"), request -> {
                service.updateIpInfo();
                return ServerResponse.ok().build();
            });
}
 
开发者ID:ggonchar,项目名称:reactive-spring5-example,代码行数:20,代码来源:PersonRouter.java

示例3: routing

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
@SuppressWarnings("unchecked")
public RouterFunction<ServerResponse> routing() {
  return route(GET(USERS).and(accept(APPLICATION_JSON_UTF8)), userHandler::all)
      .andRoute(GET(USER_ID).and(accept(APPLICATION_JSON_UTF8)), userHandler::get)
      .andRoute(POST(USERS).and(accept(APPLICATION_JSON_UTF8)), userHandler::create)
      .andRoute(PUT(USER_ID).and(accept(APPLICATION_JSON_UTF8)), userHandler::update)
      .andRoute(DELETE(USER_ID).and(accept(APPLICATION_JSON_UTF8)), userHandler::delete)
      .andRoute(GET(PROFILE), userHandler::profile);
}
 
开发者ID:saintdan,项目名称:spring-webflux-microservices-boilerplate,代码行数:11,代码来源:Application.java

示例4: httpServer

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean public HttpServer httpServer(RouterFunction<?> routerFunction) {
  HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction);
  ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
  HttpServer server = HttpServer
      .create(serverConfigBean.getAddress(), serverConfigBean.getPort());
  server.newHandler(adapter);
  return server;
}
 
开发者ID:saintdan,项目名称:spring-webflux-microservices-boilerplate,代码行数:9,代码来源:HttpServerConfig.java

示例5: getRoutingFunction

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Override
protected RouterFunction<ServerResponse> getRoutingFunction(ErrorAttributes errorAttributes) {
	return route(all(), req -> {
		Map<String, Object> error = getErrorAttributes(req, false);
		HttpStatus errorStatus = getHttpStatus(error);
		return ServerResponse.status(getHttpStatus(error))
				.contentType(APPLICATION_JSON_UTF8)
				.body(BodyInserters.fromObject(error.get("yggdrasil")))
				.doOnNext((resp) -> logError(req, errorStatus));
	});
}
 
开发者ID:to2mbn,项目名称:yggdrasil-mock,代码行数:12,代码来源:YggdrasilWebExceptionHandler.java

示例6: routingFunction

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
public RouterFunction<?> routingFunction() {

        return route(
                GET("/techtalk/").and(accept(APPLICATION_JSON)), handler::sayHello)
                .andRoute(
                        GET("/techtalk/gitter/{name}").and(accept(APPLICATION_JSON)), handler::userByName);
    }
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:8,代码来源:ReactorApplication.java

示例7: startReactorServer

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
private void startReactorServer() {
    RouterFunction<?> route = routingFunction();
    HttpHandler httpHandler = toHttpHandler(route);

    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
    HttpServer server = HttpServer.create(HOST, PORT);
    server.newHandler(adapter).block();
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:9,代码来源:ReactorApplication.java

示例8: routeServlet1

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:12,代码来源:HttpServerConfig.java

示例9: departmentServiceBox

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> departmentServiceBox(){
	return route(GET("/listFluxDepts"), dataHandler::deptList)
			.andRoute(GET("/selectDeptById/{id}"), dataHandler::chooseDeptById)
			.andRoute(POST("/selectFluxDepts"), dataHandler::chooseFluxDepts)
			.andRoute(POST("/saveFluxDept"), dataHandler::saveDepartmentMono)
			.andRoute(GET("/countFluxDepts"), dataHandler::countDepts);
	
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:10,代码来源:DeptReactFuncController.java

示例10: employeeServiceBox

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> employeeServiceBox() {
    return route(GET("/listFluxEmps"), empDataHandler::empList)
    		   .andRoute(GET("/selectEmpById/{id}"), empDataHandler::chooseEmpById)
    		   .andRoute(POST("/selectFluxEmps"), empDataHandler::chooseFluxEmps)
    		   .andRoute(POST("/saveEmp"), empDataHandler::saveEmployeeMono)
    		   .andRoute(GET("/avgAgeEmps"), empDataHandler::averageAge)
    		   .andRoute(GET("/totalAgeEmps"), empDataHandler::totalAge)
    		   .andRoute(GET("/countEmps"), empDataHandler::countEmps)
    		   .andRoute(GET("/hello"), empDataHandler::fluxHello)
    		   .andRoute(GET("/countPerDept/{deptid}"), empDataHandler::countEmpsPerDept)
    		   .andRoute(GET("/selectEmpValidAge/{age}"), empDataHandler::chooseFluxEmpsValidAge);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:14,代码来源:EmpReactFuncController.java

示例11: loginServiceBox

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> loginServiceBox() {
    return route(GET("/listFluxLogins"), loginHandler::loginDetailsList)
    		   .andRoute(GET("/selectLoginById/{id}"), loginHandler::loginDetailsById)
    		   .andRoute(POST("/selectFluxLogins"), loginHandler::chooseFluxLoginDetails)
    		   .andRoute(POST("/saveLogin"), loginHandler::saveLogindetailsMono)
    		   .andRoute(GET("/totalLogins"), loginHandler::countLogins);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:9,代码来源:ReactiveControllers.java

示例12: userServiceBox

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> userServiceBox() {
    return route(GET("/listFluxUsers"), loginHandler::userDetailsList)
    		   .andRoute(GET("/selectUserById/{id}"), loginHandler::userDetailsById)
    		   .andRoute(POST("/selectFluxUsers"), loginHandler::chooseFluxUserDetails)
    		   .andRoute(POST("/saveUser"), loginHandler::saveUserdetailsMono)
    		   .andRoute(GET("/selectUserByFirstName/{fname}"), loginHandler::chooseUserByFirstName)
    		   .andRoute(GET("/selectUserByLastName/{lname}"), loginHandler::chooseUserByLastName);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:10,代码来源:ReactiveControllers.java

示例13: employeeServiceBox

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> employeeServiceBox() {
    return route(GET("/listFluxEmps"), dataHandler::empList)
    		   .andRoute(GET("/selectEmpById/{id}"), dataHandler::chooseEmpById)
    		   .andRoute(POST("/selectFluxEmps"), dataHandler::chooseFluxEmps)
    		   .andRoute(POST("/saveEmp"), dataHandler::saveEmployeeMono)
    		   .andRoute(GET("/avgAgeEmps"), dataHandler::averageAge)
    		   .andRoute(GET("/totalAgeEmps"), dataHandler::totalAge)
    		   .andRoute(GET("/countEmps"), dataHandler::countEmps)
    		   .andRoute(GET("/countPerDept/{deptid}"), dataHandler::countEmpsPerDept)
    		   .andRoute(GET("/selectEmpValidAge/{age}"), dataHandler::chooseFluxEmpsValidAge);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:13,代码来源:EmpReactFuncController.java

示例14: departmentServiceBox

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> departmentServiceBox(){
	return route(GET("/listFluxDepts"), dataHandler::deptList)
			.andRoute(GET("/selectDeptById/{id}"), dataHandler::chooseDeptById)
			.andRoute(POST("/selectFluxDepts"), dataHandler::chooseFluxDepts)
			.andRoute(POST("/saveDept"), dataHandler::saveDepartmentMono)
			.andRoute(GET("/countDepts"), dataHandler::countDepts);
	
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:10,代码来源:ReactiveControllers.java

示例15: routes

import org.springframework.web.reactive.function.server.RouterFunction; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> routes(PostHandler postController) {
    return route(GET("/posts"), postController::all)
        .andRoute(POST("/posts"), postController::create)
        .andRoute(GET("/posts/{id}"), postController::get)
        .andRoute(PUT("/posts/{id}"), postController::update)
        .andRoute(DELETE("/posts/{id}"), postController::delete);
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:9,代码来源:DemoApplication.java


注:本文中的org.springframework.web.reactive.function.server.RouterFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。