本文整理汇总了Java中org.springframework.web.reactive.function.server.RouterFunctions类的典型用法代码示例。如果您正苦于以下问题:Java RouterFunctions类的具体用法?Java RouterFunctions怎么用?Java RouterFunctions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RouterFunctions类属于org.springframework.web.reactive.function.server包,在下文中一共展示了RouterFunctions类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stubResponse
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的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.RouterFunctions; //导入依赖的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: httpServer
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的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;
}
示例4: routeServlet1
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的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;
}
示例5: main
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
PostRepository posts = new PostRepository();
PostHandler postHandler = new PostHandler(posts);
Routes routesBean = new Routes(postHandler);
context.registerBean(PostRepository.class, () -> posts);
context.registerBean(PostHandler.class, () -> postHandler);
context.registerBean(Routes.class, () -> routesBean);
context.registerBean(WebHandler.class, () -> RouterFunctions.toWebHandler(routesBean.routes(), HandlerStrategies.builder().build()));
context.refresh();
nettyContext(context).onClose().block();
}
示例6: httpServer
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
@Bean
public HttpServer httpServer(RouterFunction<?> routerFunction) {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
HttpServer server = HttpServer.create();
server.newHandler(adapter);
return server;
}
示例7: indexResponse
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
private static RouterFunction<ServerResponse> indexResponse(List<RouterFunction<ServerResponse>> functions, List<Exception> exceptions) {
// TODO: Thymeleaf
val status = String.format(
"## %d ERROR(S)\n\n%s\n\n## %d ROUTE(S)\n\n%s",
exceptions.size(),
String.join("\n----\n", exceptions.stream().map(Throwable::toString).collect(toList())),
functions.size(),
String.join("\n", functions.stream().map(RouterFunction::toString).collect(toList())));
return RouterFunctions.route(GET("/"), request -> ok().syncBody(status));
}
示例8: routes
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
/**
* Defines the routes mapped to {@link FunctionalUserController}.
*
* @param controller
* @return
*/
@Bean
RouterFunction<?> routes(FunctionalUserController controller) {
return RouterFunctions//
.route(GET("/users"), controller::getUsers)//
.andRoute(GET("/users/{id}"), controller::getUser);
}
示例9: applicationContext
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
private static ApplicationContext applicationContext(WebFilter... webFilters) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
for(WebFilter filter : webFilters) {
context.registerBean(WebFilter.class, () -> filter);
}
context.registerBean("webHandler", DispatcherHandler.class, () -> new DispatcherHandler());
context.registerBean(HandlerMapping.class, () -> RouterFunctions.toHandlerMapping(request -> Mono.just(r -> ServerResponse.ok().build())));
context.registerBean(HandlerAdapter.class, () -> new HandlerFunctionAdapter());
context.registerBean(HandlerResultHandler.class, () -> new ServerResponseResultHandler());
context.refresh();
return context;
}
示例10: testFunRouterFunction
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
@Bean
public RouterFunction<ServerResponse> testFunRouterFunction() {
RouterFunction<ServerResponse> route = RouterFunctions.route(
RequestPredicates.path("/testfun"),
request -> ServerResponse.ok().body(BodyInserters.fromObject("hello")));
return route;
}
示例11: routingHandler
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
public HttpHandler routingHandler() {
LoanBrokerHandler loanBrokerHandler = new LoanBrokerHandler(reactorLoanBrokerAgent);
return RouterFunctions.toHttpHandler(route(GET("/reactor/quotation"), loanBrokerHandler::bestQuotation));
}
示例12: errorResponse
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
private static RouterFunction<ServerResponse> errorResponse(String cause) {
return RouterFunctions.route(all(), request -> status(HttpStatus.INTERNAL_SERVER_ERROR).syncBody(cause));
}
示例13: httpServer
import org.springframework.web.reactive.function.server.RouterFunctions; //导入依赖的package包/类
@Bean
public HttpServer httpServer(RouterFunction<?> routerFunction) {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
HttpServer server = HttpServer.create(
String.valueOf(environment.getProperty("server.address")),
Integer.valueOf(environment.getProperty("server.port")));
server.newHandler(adapter);
return server;
}