本文整理了Java中org.springframework.web.reactive.function.server.RouterFunctions.toWebHandler
方法的一些代码示例,展示了RouterFunctions.toWebHandler
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RouterFunctions.toWebHandler
方法的具体详情如下:
包路径:org.springframework.web.reactive.function.server.RouterFunctions
类名称:RouterFunctions
方法名:toWebHandler
[英]Convert the given RouterFunction into a WebHandler. This conversion uses HandlerStrategies#builder().
[中]将给定的RouterFunction转换为WebHandler。此转换使用HandlerStrategies#builder()。
代码示例来源:origin: spring-projects/spring-framework
/**
* Convert the given {@linkplain RouterFunction router function} into a {@link WebHandler}.
* This conversion uses {@linkplain HandlerStrategies#builder() default strategies}.
* @param routerFunction the router function to convert
* @return a web handler that handles web request using the given router function
*/
public static WebHandler toWebHandler(RouterFunction<?> routerFunction) {
return toWebHandler(routerFunction, HandlerStrategies.withDefaults());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected WebHttpHandlerBuilder initHttpHandlerBuilder() {
WebHandler webHandler = RouterFunctions.toWebHandler(this.routerFunction, this.handlerStrategies);
return WebHttpHandlerBuilder.webHandler(webHandler)
.filters(filters -> filters.addAll(this.handlerStrategies.webFilters()))
.exceptionHandlers(handlers -> handlers.addAll(this.handlerStrategies.exceptionHandlers()))
.localeContextResolver(this.handlerStrategies.localeContextResolver());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Convert the given {@linkplain RouterFunction router function} into a {@link HttpHandler},
* using the given strategies.
* <p>The returned {@code HttpHandler} can be adapted to run in
* <ul>
* <li>Servlet 3.1+ using the
* {@link org.springframework.http.server.reactive.ServletHttpHandlerAdapter},</li>
* <li>Reactor using the
* {@link org.springframework.http.server.reactive.ReactorHttpHandlerAdapter},</li>
* <li>Undertow using the
* {@link org.springframework.http.server.reactive.UndertowHttpHandlerAdapter}.</li>
* </ul>
* @param routerFunction the router function to convert
* @param strategies the strategies to use
* @return an http handler that handles HTTP request using the given router function
*/
public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies) {
WebHandler webHandler = toWebHandler(routerFunction, strategies);
return WebHttpHandlerBuilder.webHandler(webHandler)
.filters(filters -> filters.addAll(strategies.webFilters()))
.exceptionHandlers(handlers -> handlers.addAll(strategies.exceptionHandlers()))
.localeContextResolver(strategies.localeContextResolver())
.build();
}
代码示例来源:origin: apache/servicemix-bundles
@Override
protected WebHttpHandlerBuilder initHttpHandlerBuilder() {
WebHandler webHandler = RouterFunctions.toWebHandler(this.routerFunction, this.handlerStrategies);
return WebHttpHandlerBuilder.webHandler(webHandler)
.filters(filters -> filters.addAll(this.handlerStrategies.webFilters()))
.exceptionHandlers(handlers -> handlers.addAll(this.handlerStrategies.exceptionHandlers()))
.localeContextResolver(this.handlerStrategies.localeContextResolver());
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test
@Override
protected WebHttpHandlerBuilder initHttpHandlerBuilder() {
WebHandler webHandler = RouterFunctions.toWebHandler(this.routerFunction, this.handlerStrategies);
return WebHttpHandlerBuilder.webHandler(webHandler)
.filters(filters -> filters.addAll(this.handlerStrategies.webFilters()))
.exceptionHandlers(handlers -> handlers.addAll(this.handlerStrategies.exceptionHandlers()))
.localeContextResolver(this.handlerStrategies.localeContextResolver());
}
代码示例来源:origin: dsyer/spring-boot-allocations
public static void main(String[] args) throws Exception {
long t0 = System.currentTimeMillis();
GenericApplicationContext context = new GenericApplicationContext();
context.registerBean(RouterFunction.class, () -> RouterFunctions.route(GET("/"),
request -> ok().body(Mono.just("Hello"), String.class)));
context.registerBean("webHandler", WebHandler.class, () -> RouterFunctions
.toWebHandler(context.getBean(RouterFunction.class)));
context.refresh();
ApplicationBuilder.start(context, b -> {
System.err.println("Started HttpServer: " + (System.currentTimeMillis() - t0) + "ms");
});
}
}
代码示例来源:origin: hantsy/spring-reactive-sample
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();
nettyServer(context).onDispose().block();
}
内容来源于网络,如有侵权,请联系作者删除!