Search in sources :

Example 6 with ContentNegotiatingViewResolver

use of org.springframework.web.servlet.view.ContentNegotiatingViewResolver in project spring-framework by spring-projects.

the class ViewResolverRegistryTests method contentNegotiationAddsDefaultViewRegistrations.

@Test
public void contentNegotiationAddsDefaultViewRegistrations() {
    MappingJackson2JsonView view1 = new MappingJackson2JsonView();
    this.registry.enableContentNegotiation(view1);
    ContentNegotiatingViewResolver resolver1 = checkAndGetResolver(ContentNegotiatingViewResolver.class);
    assertEquals(Arrays.asList(view1), resolver1.getDefaultViews());
    MarshallingView view2 = new MarshallingView();
    this.registry.enableContentNegotiation(view2);
    ContentNegotiatingViewResolver resolver2 = checkAndGetResolver(ContentNegotiatingViewResolver.class);
    assertEquals(Arrays.asList(view1, view2), resolver2.getDefaultViews());
    assertSame(resolver1, resolver2);
}
Also used : ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) MarshallingView(org.springframework.web.servlet.view.xml.MarshallingView) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) Test(org.junit.Test)

Example 7 with ContentNegotiatingViewResolver

use of org.springframework.web.servlet.view.ContentNegotiatingViewResolver in project spring-security-oauth by spring-projects.

the class WebMvcConfig method contentViewResolver.

@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setDefaultViews(Arrays.<View>asList(new MappingJackson2JsonView()));
    return contentViewResolver;
}
Also used : ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) ConversionServiceFactoryBean(org.springframework.context.support.ConversionServiceFactoryBean)

Example 8 with ContentNegotiatingViewResolver

use of org.springframework.web.servlet.view.ContentNegotiatingViewResolver in project spring-security-oauth by spring-projects.

the class WebMvcConfig method contentViewResolver.

@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/jsp/");
    viewResolver.setSuffix(".jsp");
    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);
    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
}
Also used : ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ContentNegotiatingViewResolver (org.springframework.web.servlet.view.ContentNegotiatingViewResolver)8 Test (org.junit.Test)5 MappingJackson2JsonView (org.springframework.web.servlet.view.json.MappingJackson2JsonView)5 InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)4 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)3 ArrayList (java.util.ArrayList)2 Bean (org.springframework.context.annotation.Bean)2 ContentNegotiationManagerFactoryBean (org.springframework.web.accept.ContentNegotiationManagerFactoryBean)2 View (org.springframework.web.servlet.View)2 ViewResolver (org.springframework.web.servlet.ViewResolver)2 BeanNameViewResolver (org.springframework.web.servlet.view.BeanNameViewResolver)2 ViewResolverComposite (org.springframework.web.servlet.view.ViewResolverComposite)2 FreeMarkerViewResolver (org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver)2 GroovyMarkupViewResolver (org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver)2 ScriptTemplateViewResolver (org.springframework.web.servlet.view.script.ScriptTemplateViewResolver)2 TilesViewResolver (org.springframework.web.servlet.view.tiles3.TilesViewResolver)2 MarshallingView (org.springframework.web.servlet.view.xml.MarshallingView)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 ConversionServiceFactoryBean (org.springframework.context.support.ConversionServiceFactoryBean)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1