本文整理汇总了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);
}
示例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();
});
}
示例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);
}
示例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;
}
示例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));
});
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}