use of cn.taketoday.web.view.ContentNegotiatingViewResolver in project today-infrastructure by TAKETODAY.
the class ViewResolverRegistryTests method contentNegotiation.
@Test
public void contentNegotiation() {
MappingJackson2JsonView view = new MappingJackson2JsonView();
this.registry.enableContentNegotiation(view);
ContentNegotiatingViewResolver resolver = checkAndGetResolver(ContentNegotiatingViewResolver.class);
assertThat(resolver.getDefaultViews()).isEqualTo(Arrays.asList(view));
assertThat(this.registry.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE);
}
use of cn.taketoday.web.view.ContentNegotiatingViewResolver in project today-infrastructure by TAKETODAY.
the class WebMvcAutoConfiguration method viewResolver.
@Component
@ConditionalOnBean(ViewResolver.class)
@ConditionalOnMissingBean(name = "viewResolver", value = ContentNegotiatingViewResolver.class)
public ContentNegotiatingViewResolver viewResolver(@Nullable ContentNegotiationManager contentNegotiationManager) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(contentNegotiationManager);
// ContentNegotiatingViewResolver uses all the other view resolvers to locate
// a view so it should have a high precedence
resolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
return resolver;
}
use of cn.taketoday.web.view.ContentNegotiatingViewResolver in project today-infrastructure by TAKETODAY.
the class ViewResolverRegistry method enableContentNegotiation.
/**
* Enable use of a {@link ContentNegotiatingViewResolver} to front all other
* configured view resolvers and select among all selected Views based on
* media types requested by the client (e.g. in the Accept header).
* <p>If invoked multiple times the provided default views will be added to
* any other default views that may have been configured already.
*
* @see ContentNegotiatingViewResolver#setDefaultViews
*/
public void enableContentNegotiation(boolean useNotAcceptableStatus, View... defaultViews) {
ContentNegotiatingViewResolver vr = initContentNegotiatingViewResolver(defaultViews);
vr.setUseNotAcceptableStatusCode(useNotAcceptableStatus);
}
use of cn.taketoday.web.view.ContentNegotiatingViewResolver in project today-infrastructure by TAKETODAY.
the class ViewResolverRegistry method initContentNegotiatingViewResolver.
private ContentNegotiatingViewResolver initContentNegotiatingViewResolver(View[] defaultViews) {
// ContentNegotiatingResolver in the registry: elevate its precedence!
this.order = order != null ? order : Ordered.HIGHEST_PRECEDENCE;
if (contentNegotiatingResolver != null) {
if (ObjectUtils.isNotEmpty(defaultViews) && CollectionUtils.isNotEmpty(contentNegotiatingResolver.getDefaultViews())) {
ArrayList<View> views = new ArrayList<>(contentNegotiatingResolver.getDefaultViews());
CollectionUtils.addAll(views, defaultViews);
contentNegotiatingResolver.setDefaultViews(views);
}
} else {
this.contentNegotiatingResolver = new ContentNegotiatingViewResolver();
contentNegotiatingResolver.setDefaultViews(Arrays.asList(defaultViews));
contentNegotiatingResolver.setViewResolvers(viewResolvers);
if (contentNegotiationManager != null) {
contentNegotiatingResolver.setContentNegotiationManager(contentNegotiationManager);
}
}
return contentNegotiatingResolver;
}
use of cn.taketoday.web.view.ContentNegotiatingViewResolver in project today-framework by TAKETODAY.
the class ViewResolverRegistry method initContentNegotiatingViewResolver.
private ContentNegotiatingViewResolver initContentNegotiatingViewResolver(View[] defaultViews) {
// ContentNegotiatingResolver in the registry: elevate its precedence!
this.order = order != null ? order : Ordered.HIGHEST_PRECEDENCE;
if (contentNegotiatingResolver != null) {
if (ObjectUtils.isNotEmpty(defaultViews) && CollectionUtils.isNotEmpty(contentNegotiatingResolver.getDefaultViews())) {
ArrayList<View> views = new ArrayList<>(contentNegotiatingResolver.getDefaultViews());
CollectionUtils.addAll(views, defaultViews);
contentNegotiatingResolver.setDefaultViews(views);
}
} else {
this.contentNegotiatingResolver = new ContentNegotiatingViewResolver();
contentNegotiatingResolver.setDefaultViews(Arrays.asList(defaultViews));
contentNegotiatingResolver.setViewResolvers(viewResolvers);
if (contentNegotiationManager != null) {
contentNegotiatingResolver.setContentNegotiationManager(contentNegotiationManager);
}
}
return contentNegotiatingResolver;
}
Aggregations