Add ServerHttpRequest & ServerHttpResponse

This commit introduces HTTP request and response abstractions along
with Servlet-based implementations similar to the ones in the http
package of spring-web but using Reactive Streams.

In turn HttpHandler now accepts the request and response types and
returns Publisher<Void> that reflects the end of handling.

The write method on the response also returns Publisher<Void> allowing
deferred writing. At the moment however the underlying Servlet 3.1
support only supports a single publisher after which the connection
is closed.

Only simple byte[] is supported for reading and writing.
This commit is contained in:
Rossen Stoyanchev
2015-08-11 16:01:13 -04:00
parent bb25267525
commit 2cb32a0fd6
15 changed files with 394 additions and 17 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.reactive.web.servlet;
package org.springframework.reactive.web;
import java.net.URI;
import java.util.Random;
@@ -29,7 +29,7 @@ import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public abstract class AbstractHttpHandlerServletIntegrationTestCase {
public abstract class AbstractHttpHandlerIntegrationTestCase {
private static final int REQUEST_SIZE = 4096 * 3;

View File

@@ -30,8 +30,8 @@ public class CountingHttpHandler implements HttpHandler {
private static final Log logger = LogFactory.getLog(CountingHttpHandler.class);
@Override
public Publisher<byte[]> handle(Publisher<byte[]> request) {
request.subscribe(new Subscriber<byte[]>() {
public Publisher<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
request.getBody().subscribe(new Subscriber<byte[]>() {
private Subscription subscription;
private int byteCount = 0;

View File

@@ -24,7 +24,7 @@ import org.reactivestreams.Publisher;
public class EchoHandler implements HttpHandler {
@Override
public Publisher<byte[]> handle(Publisher<byte[]> request) {
return request;
public Publisher<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
return response.writeWith(request.getBody());
}
}

View File

@@ -23,13 +23,14 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.springframework.reactive.web.AbstractHttpHandlerIntegrationTestCase;
import org.springframework.reactive.web.EchoHandler;
/**
* @author Arjen Poutsma
*/
public class HttpHandlerServletJettyIntegrationTests
extends AbstractHttpHandlerServletIntegrationTestCase {
public class HttpHandlerJettyIntegrationTests
extends AbstractHttpHandlerIntegrationTestCase {
private static Server jettyServer;

View File

@@ -24,12 +24,13 @@ import org.apache.catalina.startup.Tomcat;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.springframework.reactive.web.AbstractHttpHandlerIntegrationTestCase;
import org.springframework.reactive.web.EchoHandler;
/**
* @author Arjen Poutsma
*/
public class HttpHandlerServletTomcatIntegrationTests extends AbstractHttpHandlerServletIntegrationTestCase {
public class HttpHandlerTomcatIntegrationTests extends AbstractHttpHandlerIntegrationTestCase {
private static Tomcat tomcatServer;