org.springframework.http.server.reactive.ReactorHttpHandlerAdapter Java Examples

The following examples show how to use org.springframework.http.server.reactive.ReactorHttpHandlerAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebFluxIT.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: RSocketNettyReactiveWebServerFactory.java    From spring-boot-rsocket with Apache License 2.0 6 votes vote down vote up
@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
		));
}
 
Example #3
Source File: WebFluxIT.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #4
Source File: FunctionEndpointInitializer.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example #5
Source File: StandaloneApplication.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 6 votes vote down vote up
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();
}
 
Example #6
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public HttpServer httpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    return  HttpServer.create()
            .host("localhost")
            .port(this.port)
            .handle(adapter);
}
 
Example #10
Source File: Spring5ReactiveServerClientIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeAll
public static void setUp() throws Exception {
    HttpServer server = HttpServer.create()
        .host("localhost")
        .port(8080);
    RouterFunction<?> route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok()
        .body(request.bodyToFlux(Task.class)
            .map(ll -> new Task("TaskName", 1)), Task.class))
        .and(RouterFunctions.route(GET("/task"), request -> ServerResponse.ok()
            .body(Mono.just("server is alive"), String.class)));
    HttpHandler httpHandler = RouterFunctions.toHttpHandler(route);
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
    disposableServer = server.handle(adapter)
        .bindNow();
}
 
Example #11
Source File: SpringSecurity5Application.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public DisposableServer disposableServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context)
            .build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    HttpServer httpServer = HttpServer.create();
    httpServer.host("localhost");
    httpServer.port(8080);
    return httpServer.handle(adapter).bindNow();
}
 
Example #12
Source File: Application.java    From spring-security-reactive with Apache License 2.0 5 votes vote down vote up
@Bean
public NettyContext nettyContext(ApplicationContext context) {
	HttpHandler handler = DispatcherHandler.toHttpHandler(context);
	ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
	HttpServer httpServer = HttpServer.create("localhost", port);
	return httpServer.newHandler(adapter).block();
}
 
Example #13
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #16
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #17
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #19
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #27
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public HttpServer httpServer(ApplicationContext context) {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
    return  HttpServer.create()
            .host("localhost")
            .port(this.port)
            .handle(adapter);
}
 
Example #28
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #29
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #30
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@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);
}