提交 4d04bd56 编写于 作者: R Rossen Stoyanchev

Consolidate view resolution under result.view

While View and ViewResolver play the same role as in spring-webmvc they
are now abstracted behind the HandlerResultHandler abstraction so that
top-level contracts don't reference them and the DispatcherHandler is
also unaware of their existence.

Furthermore view resolution and response body handling which are now at
the same level of abstraction (each is a HandlerResultHandler) will
also share code for content negotiation, so it makes sense for them to
be side by side.

This commit moves the reactive.view package to reactive.result.view
with the View and ViewResolver contracts (previously in the top-level
reactive package) also moving there.
上级 318b15c3
/**
* Provides various controller styles for request handling.
* Support for various programming model styles including the invocation of
* different types of handlers (e.g. annotated controllers, simple WebHandler,
* etc) as well as result handling (@ResponseBody, view resolution, etc).
*/
package org.springframework.web.reactive.result;
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.util.Locale;
......
......@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -35,7 +34,6 @@ import org.springframework.http.MediaType;
import org.springframework.ui.ModelMap;
import org.springframework.util.Assert;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.View;
import org.springframework.web.server.ServerWebExchange;
/**
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.util.Locale;
......@@ -22,19 +22,17 @@ import reactor.core.publisher.Mono;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.PatternMatchUtils;
import org.springframework.web.reactive.View;
/**
* A {@link org.springframework.web.reactive.ViewResolver ViewResolver} that
* allow direct resolution of symbolic view names to URLs without explicit
* mapping definition. This is useful if symbolic names match the names of view
* resources in a straightforward manner (i.e. the symbolic name is the unique
* part of the resource's filename), without the need for a dedicated mapping
* to be defined for each view.
* A {@link ViewResolver} that allow direct resolution of symbolic view names
* to URLs without explicit mapping definition. This is useful if symbolic names
* match the names of view resources in a straightforward manner (i.e. the
* symbolic name is the unique part of the resource's filename), without the need
* for a dedicated mapping to be defined for each view.
*
* <p>Supports {@link AbstractUrlBasedView} subclasses like
* {@link org.springframework.web.reactive.view.freemarker.FreeMarkerView}.
* {@link org.springframework.web.reactive.result.view.freemarker.FreeMarkerView}.
* The view class for all views generated by this resolver can be specified
* via the "viewClass" property.
*
......@@ -54,7 +52,7 @@ import org.springframework.web.reactive.View;
* a symbolic view name to different resources depending on the current locale.
* * @author Rossen Stoyanchev
*/
public class UrlBasedViewResolver extends ViewResolverSupport implements InitializingBean {
public class UrlBasedViewResolver extends ViewResolverSupport implements ViewResolver, InitializingBean {
private Class<?> viewClass;
......@@ -125,9 +123,8 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements Initial
/**
* Set the view names (or name patterns) that can be handled by this
* {@link org.springframework.web.reactive.ViewResolver}. View names can
* contain simple wildcards such that 'my*', '*Report' and '*Repo*' will
* all match the view name 'myReport'.
* {@link ViewResolver}. View names can contain simple wildcards such that
* 'my*', '*Report' and '*Repo*' will all match the view name 'myReport'.
* @see #canHandle
*/
public void setViewNames(String... viewNames) {
......@@ -136,7 +133,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements Initial
/**
* Return the view names (or name patterns) that can be handled by this
* {@link org.springframework.web.reactive.ViewResolver}.
* {@link ViewResolver}.
*/
protected String[] getViewNames() {
return this.viewNames;
......@@ -167,8 +164,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport implements Initial
}
/**
* Indicates whether or not this
* {@link org.springframework.web.reactive.ViewResolver} can handle the
* Indicates whether or not this {@link ViewResolver} can handle the
* supplied view name. If not, an empty result is returned. The default
* implementation checks against the configured {@link #setViewNames
* view names}.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive;
package org.springframework.web.reactive.result.view;
import java.util.List;
import java.util.Optional;
......@@ -22,6 +22,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.server.ServerWebExchange;
/**
......
package org.springframework.web.reactive;
package org.springframework.web.reactive.result.view;
import java.util.Locale;
......@@ -10,11 +10,11 @@ import reactor.core.publisher.Mono;
*
* <p>The process of view resolution is driven through a ViewResolver-based
* {@code HandlerResultHandler} implementation called
* {@link org.springframework.web.reactive.view.ViewResolverResultHandler
* {@link org.springframework.web.reactive.result.view.ViewResolverResultHandler
* ViewResolverResultHandler}.
*
* @author Rossen Stoyanchev
* @see org.springframework.web.reactive.view.ViewResolverResultHandler
* @see org.springframework.web.reactive.result.view.ViewResolverResultHandler
*/
public interface ViewResolver {
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.util.ArrayList;
import java.util.Collections;
......@@ -31,8 +31,6 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.util.Assert;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.HandlerResultHandler;
import org.springframework.web.reactive.View;
import org.springframework.web.reactive.ViewResolver;
import org.springframework.web.server.ServerWebExchange;
......@@ -81,8 +79,7 @@ public class ViewResolverResultHandler implements HandlerResultHandler, Ordered
return this.order;
}
// TODO: @ModelAttribute return value, declared Object return value (either String or View)
// TODO: Add support for model-related return value (Model, ModelAndView, @ModelAttribute)
@Override
public boolean supports(HandlerResult result) {
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.util.ArrayList;
import java.util.List;
......@@ -25,7 +25,6 @@ import org.springframework.core.io.buffer.DataBufferAllocator;
import org.springframework.core.io.buffer.DefaultDataBufferAllocator;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.reactive.ViewResolver;
/**
* Base class for {@code ViewResolver} implementations with shared properties.
......@@ -33,7 +32,7 @@ import org.springframework.web.reactive.ViewResolver;
* @author Rossen Stoyanchev
* @since 4.3
*/
public abstract class ViewResolverSupport implements ViewResolver, ApplicationContextAware, Ordered {
public abstract class ViewResolverSupport implements ApplicationContextAware, Ordered {
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.parseMediaType("text/html;charset=UTF-8");
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.web.reactive.view.freemarker;
package org.springframework.web.reactive.result.view.freemarker;
import freemarker.template.Configuration;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.web.reactive.view.freemarker;
package org.springframework.web.reactive.result.view.freemarker;
import java.io.IOException;
import java.util.List;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view.freemarker;
package org.springframework.web.reactive.result.view.freemarker;
import java.io.FileNotFoundException;
import java.io.IOException;
......@@ -36,7 +36,7 @@ import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContextException;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.web.reactive.view.AbstractUrlBasedView;
import org.springframework.web.reactive.result.view.AbstractUrlBasedView;
import org.springframework.web.server.ServerWebExchange;
/**
......
......@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view.freemarker;
package org.springframework.web.reactive.result.view.freemarker;
import org.springframework.web.reactive.view.UrlBasedViewResolver;
import org.springframework.web.reactive.result.view.UrlBasedViewResolver;
/**
* A {@code ViewResolver} for resolving {@link FreeMarkerView} instances, i.e.
......
/**
* Support for result handling through view resolution.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
......@@ -75,16 +75,20 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.ViewResolver;
import org.springframework.web.reactive.result.SimpleResultHandler;
import org.springframework.web.reactive.view.ViewResolverResultHandler;
import org.springframework.web.reactive.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.reactive.view.freemarker.FreeMarkerViewResolver;
import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.reactive.result.view.ViewResolverResultHandler;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Integration tests with {@code @RequestMapping} methods.
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @author Stephane Maldini
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.util.Locale;
import java.util.Map;
......@@ -24,7 +24,6 @@ import reactor.core.publisher.Mono;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.web.reactive.View;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertNotNull;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view;
package org.springframework.web.reactive.result.view;
import java.lang.reflect.Method;
import java.net.URI;
......@@ -50,15 +50,16 @@ import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.ModelMap;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.reactive.HandlerResultHandler;
import org.springframework.web.reactive.View;
import org.springframework.web.reactive.ViewResolver;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
......
......@@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.view.freemarker;
package org.springframework.web.reactive.result.view.freemarker;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Locale;
import java.util.Optional;
......@@ -39,17 +38,14 @@ import org.springframework.http.server.reactive.MockServerHttpRequest;
import org.springframework.http.server.reactive.MockServerHttpResponse;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.reactive.HandlerResult;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.DefaultServerWebExchange;
import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册