Polish and update reactive getting started reference

This commit updates the instructions on getting started with
Spring Web Reactive and also updates constructors and setters to
streamline the getting started procedure.

Issue: SPR-14640
This commit is contained in:
Rossen Stoyanchev
2016-08-30 14:36:19 -04:00
parent 436486b8a1
commit 391752abc2
8 changed files with 70 additions and 53 deletions

View File

@@ -23,6 +23,7 @@ import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.util.Assert;
/**
@@ -40,17 +41,20 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle
private final HttpHandler delegate;
private final DataBufferFactory dataBufferFactory;
private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(false);
public UndertowHttpHandlerAdapter(HttpHandler delegate, DataBufferFactory dataBufferFactory) {
public UndertowHttpHandlerAdapter(HttpHandler delegate) {
Assert.notNull(delegate, "'delegate' is required");
Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null");
this.delegate = delegate;
this.dataBufferFactory = dataBufferFactory;
}
public void setDataBufferFactory(DataBufferFactory dataBufferFactory) {
Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null");
this.dataBufferFactory = dataBufferFactory;
}
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {

View File

@@ -19,8 +19,6 @@ package org.springframework.http.server.reactive.bootstrap;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.server.reactive.UndertowHttpHandlerAdapter;
import org.springframework.util.Assert;
@@ -31,19 +29,13 @@ public class UndertowHttpServer extends HttpServerSupport implements HttpServer
private Undertow server;
private DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
private boolean running;
public void setDataBufferFactory(DataBufferFactory dataBufferFactory) {
this.dataBufferFactory = dataBufferFactory;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(getHttpHandler());
HttpHandler handler =
new UndertowHttpHandlerAdapter(getHttpHandler(), dataBufferFactory);
HttpHandler handler = new UndertowHttpHandlerAdapter(getHttpHandler());
this.server = Undertow.builder().addHttpListener(getPort(), getHost())
.setHandler(handler).build();
}