Return HandlerResult in HandlerAdapter#handle()

This commit updates HandlerAdapter#handle() to return HandlerResult
instead of Publisher<HandlerResult>. A new SimpleHandlerResultHandler
class has been introduced for handlers returning Publisher<Void>.
This commit is contained in:
Sebastien Deleuze
2015-10-02 15:42:43 +02:00
parent 49fc32e214
commit 9516c9992f
8 changed files with 143 additions and 28 deletions

View File

@@ -28,6 +28,7 @@ import reactor.rx.Streams;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.reactive.web.dispatch.DispatcherHandler;
import org.springframework.reactive.web.dispatch.SimpleHandlerResultHandler;
import org.springframework.reactive.web.http.AbstractHttpHandlerIntegrationTests;
import org.springframework.reactive.web.http.HttpHandler;
import org.springframework.reactive.web.http.ServerHttpRequest;
@@ -52,6 +53,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("hm", TestHandlerMapping.class);
wac.registerSingleton("ha", HttpHandlerAdapter.class);
wac.registerSingleton("hhrh", SimpleHandlerResultHandler.class);
wac.refresh();
DispatcherHandler dispatcherHandler = new DispatcherHandler();

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.reactive.web.dispatch.method.annotation;
import java.util.Collections;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.reactivestreams.Publisher;
import org.springframework.reactive.web.dispatch.HandlerResult;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;
/**
* @author Sebastien Deleuze
*/
public class ResponseBodyResultHandlerTests {
@Test
public void supports() throws NoSuchMethodException {
ResponseBodyResultHandler resultHandler = new ResponseBodyResultHandler(Collections.emptyList());
TestController controller = new TestController();
HandlerMethod notAnnotatedMethod = new HandlerMethod(controller, TestController.class.getMethod("notAnnotated"));
assertFalse(resultHandler.supports(new HandlerResult(notAnnotatedMethod, null)));
HandlerMethod publisherStringMethod = new HandlerMethod(controller, TestController.class.getMethod("publisherString"));
assertTrue(resultHandler.supports(new HandlerResult(publisherStringMethod, null)));
HandlerMethod publisherVoidMethod = new HandlerMethod(controller, TestController.class.getMethod("publisherVoid"));
assertFalse(resultHandler.supports(new HandlerResult(publisherVoidMethod, null)));
}
private static class TestController {
public Publisher<String> notAnnotated() {
return null;
}
@ResponseBody
public Publisher<String> publisherString() {
return null;
}
@ResponseBody
public Publisher<Void> publisherVoid() {
return null;
}
}
}