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


Java RouterFunctions类代码示例

本文整理汇总了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);
}
 
开发者ID:int128,项目名称:httpstub,代码行数:21,代码来源:RouteRegistrar.java

示例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();
            });
}
 
开发者ID:ggonchar,项目名称:reactive-spring5-example,代码行数:20,代码来源:PersonRouter.java

示例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;
}
 
开发者ID:saintdan,项目名称:spring-webflux-microservices-boilerplate,代码行数:9,代码来源:HttpServerConfig.java

示例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;
 }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:12,代码来源:HttpServerConfig.java

示例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();
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:15,代码来源:Application.java

示例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;
}
 
开发者ID:rbarbioni,项目名称:spring-boot-microservices-docker,代码行数:9,代码来源:HttpServerConfig.java

示例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));
}
 
开发者ID:int128,项目名称:httpstub,代码行数:11,代码来源:RouteRegistrar.java

示例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);
}
 
开发者ID:olivergierke,项目名称:spring-five-functional-reactive,代码行数:14,代码来源:WebfluxFnConfiguration.java

示例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;
}
 
开发者ID:spring-projects,项目名称:spring-security-reactive,代码行数:14,代码来源:WebTestClientBuilder.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:8,代码来源:GatewaySampleApplication.java

示例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));
}
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:5,代码来源:Application.java

示例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));
}
 
开发者ID:int128,项目名称:httpstub,代码行数:4,代码来源:RouteRegistrar.java

示例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;
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:16,代码来源:NettyHttpServer.java


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