org.springframework.http.server.reactive.ReactorHttpHandlerAdapter源码实例Demo

类org.springframework.http.server.reactive.ReactorHttpHandlerAdapter源码实例Demo

下面列出了org.springframework.http.server.reactive.ReactorHttpHandlerAdapter 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@SuppressWarnings("unchecked")
private RSocketFactory.Start<CloseableChannel> createRSocketStarter(HttpHandler httpHandler) {
	RSocketFactory.ServerRSocketFactory rSocketFactory = applyCustomizers(RSocketFactory.receive());


	HttpServer httpServer = createHttpServer();
	ReactorHttpHandlerAdapter handlerAdapter = new ReactorHttpHandlerAdapter(httpHandler);

	return rSocketFactory
		.acceptor(socketAcceptor)
		.transport((ServerTransport) new WebsocketRouteTransport(
			httpServer,
			r -> r.route(hsr -> !("/" + hsr.path()).equals(path), handlerAdapter),
			path
		));
}
 
public static void main(String... args) {
    long start = System.currentTimeMillis();
    HttpHandler httpHandler = RouterFunctions.toHttpHandler(routes(
        new BCryptPasswordEncoder(18)
    ));
    ReactorHttpHandlerAdapter reactorHttpHandler = new ReactorHttpHandlerAdapter(httpHandler);

    DisposableServer server = HttpServer.create()
                                        .host("localhost")
                                        .port(8080)
                                        .handle(reactorHttpHandler)
                                        .bindNow();

    LOGGER.debug("Started in " + (System.currentTimeMillis() - start) + " ms");

    server.onDispose()
          .block();
}
 
@Override
public void onApplicationEvent(ApplicationEvent event) {
	ApplicationContext context = ((ContextRefreshedEvent) event).getApplicationContext();
	if (context != this.context) {
		return;
	}
	if (!ClassUtils.isPresent("org.springframework.http.server.reactive.HttpHandler", null)) {
		logger.info("No web server classes found so no server to start");
		return;
	}
	Integer port = Integer.valueOf(context.getEnvironment().resolvePlaceholders("${server.port:${PORT:8080}}"));
	String address = context.getEnvironment().resolvePlaceholders("${server.address:0.0.0.0}");
	if (port >= 0) {
		HttpHandler handler = context.getBean(HttpHandler.class);
		ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
		HttpServer httpServer = HttpServer.create().host(address).port(port).handle(adapter);
		Thread thread = new Thread(
				() -> httpServer.bindUntilJavaShutdown(Duration.ofSeconds(60), this::callback),
				"server-startup");
		thread.setDaemon(false);
		thread.start();
	}
}
 
源代码4 项目: glowroot   文件: WebFluxIT.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    DisposableServer httpServer = HttpServer.create()
            .host("localhost")
            .port(port)
            .handle(new ReactorHttpHandlerAdapter(new MyHttpHandler()))
            .bind()
            .block();

    WebClient client = WebClient.create("http://localhost:" + port);
    client.get()
            .uri("/webflux/abc")
            .retrieve()
            .bodyToMono(String.class)
            .block();

    httpServer.dispose();
}
 
源代码5 项目: glowroot   文件: WebFluxIT.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    NettyContext nettyContext = HttpServer.create("localhost", port)
            .newHandler(new ReactorHttpHandlerAdapter(new MyHttpHandler()))
            .block();

    WebClient client = WebClient.create("http://localhost:" + port);
    client.get()
            .uri("/webflux/abc")
            .retrieve()
            .bodyToMono(String.class)
            .block();

    nettyContext.dispose();
}
 
public void startReactorServer() throws InterruptedException {
	RouterFunction<ServerResponse> route = routingFunction();
	HttpHandler httpHandler = toHttpHandler(route);

	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
	HttpServer server = HttpServer.create(HOST, PORT);
	server.newHandler(adapter).block();
}
 
public void startReactorServer() throws InterruptedException {
	RouterFunction<ServerResponse> route = routingFunction();
	HttpHandler httpHandler = toHttpHandler(route);

	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
	HttpServer server = HttpServer.create(HOST, PORT);
	server.newHandler(adapter).block();
}
 
源代码8 项目: sofa-lookout   文件: ExportManageServerRunner.java
/**
 * 暴露6200管理端口
 */
@Override
public void run(ApplicationArguments args) throws Exception {
    RouterFunction manageRouterFunction = RouterFunctions
            .route(RequestPredicates.GET("/ok"), req -> {
                return ServerResponse.ok()
                        .syncBody("online");
            })
            .andRoute(RequestPredicates.GET("/cmd/{line}"), request -> {
                String pathVar = request.pathVariable("line");
                try {
                    if ("down".equals(pathVar)) {
                        refuseRequestService.setRefuseRequest(true);
                    } else if ("up".equals(pathVar)) {
                        refuseRequestService.setRefuseRequest(false);
                    }
                    return ServerResponse.ok().body(Mono.just("ok"), String.class);
                } catch (Throwable e) {
                    LOGGER.error("{} request err!", pathVar, e);
                    return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
                }
            });

    HttpHandler handler = RouterFunctions.toHttpHandler(manageRouterFunction);
    int managePort = serverPort - 1000;

    ReactorHttpHandlerAdapter inboundAdapter = new ReactorHttpHandlerAdapter(handler);

    // manage port
    HttpServer.create().port(managePort).handle(inboundAdapter).bind();
    // HttpServer.create(managePort).newHandler(inboundAdapter).block();

    LOGGER.info("management services run on port:{}", managePort);
}
 
源代码9 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8095"));
	return httpServer.newHandler(adapter).block();
}
 
源代码10 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8908"));
	return httpServer.newHandler(adapter).block();
}
 
源代码11 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8901"));
	return httpServer.newHandler(adapter).block();
}
 
源代码12 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9007"));
	return httpServer.newHandler(adapter).block();
}
 
源代码13 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9006"));
	return httpServer.newHandler(adapter).block();
}
 
源代码14 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8901"));
	return httpServer.newHandler(adapter).block();
}
 
源代码15 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8909"));
	return httpServer.newHandler(adapter).block();
}
 
源代码16 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8125"));
	return httpServer.newHandler(adapter).block();
}
 
源代码17 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9008"));
	return httpServer.newHandler(adapter).block();
}
 
源代码18 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8901"));
	return httpServer.newHandler(adapter).block();
}
 
源代码19 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8095"));
	return httpServer.newHandler(adapter).block();
}
 
源代码20 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("9008"));
	return httpServer.newHandler(adapter).block();
}
 
源代码21 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
@Bean
public  NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", Integer.valueOf("8908"));
	return httpServer.newHandler(adapter).block();
}
 
源代码22 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码23 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码24 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码25 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码26 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码27 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码28 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码29 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码30 项目: spring-reactive-sample   文件: Application.java
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
    return httpServer.handle(adapter);
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法