Package org.springframework.web.accept

Examples of org.springframework.web.accept.FixedContentNegotiationStrategy


  @Test
  public void resolveViewNameWithDefaultContentType() throws Exception {
    request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

    MediaType mediaType = new MediaType("application", "xml");
    FixedContentNegotiationStrategy fixedStrategy = new FixedContentNegotiationStrategy(mediaType);
    viewResolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy));

    ViewResolver viewResolverMock1 = mock(ViewResolver.class, "viewResolver1");
    ViewResolver viewResolverMock2 = mock(ViewResolver.class, "viewResolver2");
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));
View Full Code Here


    InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver();
    nestedResolver.setApplicationContext(webAppContext);
    nestedResolver.setViewClass(InternalResourceView.class);
    viewResolver.setViewResolvers(new ArrayList<ViewResolver>(Arrays.asList(nestedResolver)));

    FixedContentNegotiationStrategy fixedStrategy = new FixedContentNegotiationStrategy(MediaType.TEXT_HTML);
    viewResolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy));

    viewResolver.afterPropertiesSet();

    String viewName = "view";
View Full Code Here

    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
  }

  @Test
  public void setDefaultContentTypeStrategy() throws Exception {
    this.configurer.defaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
    ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();

    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
  }
View Full Code Here

    List<View> viewList = new ArrayList<View>();
    viewList.add(new MappingJackson2JsonView());
    viewList.add(new MarshallingView(marshaller));

    ContentNegotiationManager manager = new ContentNegotiationManager(
        new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));

    ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
    cnViewResolver.setDefaultViews(viewList);
    cnViewResolver.setContentNegotiationManager(manager);
    cnViewResolver.afterPropertiesSet();
View Full Code Here

    if (!this.ignoreAcceptHeader) {
      strategies.add(new HeaderContentNegotiationStrategy());
    }

    if (this.defaultContentType != null) {
      strategies.add(new FixedContentNegotiationStrategy(this.defaultContentType));
    }
    this.contentNegotiationManager = new ContentNegotiationManager(strategies);
   
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.accept.FixedContentNegotiationStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.