Package org.springframework.web.accept

Examples of org.springframework.web.accept.ContentNegotiationManager


  public void resolveViewNameFilenameDefaultView() throws Exception {
    request.setRequestURI("/test.json");

    Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
    PathExtensionContentNegotiationStrategy pathStrategy = new PathExtensionContentNegotiationStrategy(mapping);
    viewResolver.setContentNegotiationManager(new ContentNegotiationManager(pathStrategy));

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


    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";
    Locale locale = Locale.ENGLISH;
View Full Code Here

    assertTrue(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
    mapping.setDefaultHandler(handlerMethod);

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
    NativeWebRequest webRequest = new ServletWebRequest(request);
    ContentNegotiationManager manager = mapping.getContentNegotiationManager();
    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));

    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertNotNull(adapter);
    assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
View Full Code Here

  @Test
  public void testContentNegotiationManager() throws Exception {
    loadBeanDefinitions("mvc-config-content-negotiation-manager.xml", 13);

    RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
    ContentNegotiationManager manager = mapping.getContentNegotiationManager();

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
    NativeWebRequest webRequest = new ServletWebRequest(request);
    assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
  }
View Full Code Here

    assertEquals(1, cnvr.getDefaultViews().size());
    assertTrue(cnvr.isUseNotAcceptableStatusCode());

    String beanName = "contentNegotiationManager";
    DirectFieldAccessor accessor = new DirectFieldAccessor(cnvr);
    ContentNegotiationManager manager = (ContentNegotiationManager) accessor.getPropertyValue(beanName);
    assertNotNull(manager);
    assertSame(manager, this.appContext.getBean(ContentNegotiationManager.class));
  }
View Full Code Here

  @Test
  public void contentNegotiation() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
    NativeWebRequest webRequest = new ServletWebRequest(request);

    ContentNegotiationManager manager = this.config.requestMappingHandlerMapping().getContentNegotiationManager();
    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));

    request.setRequestURI("/foo.xml");
    assertEquals(Arrays.asList(MediaType.APPLICATION_XML), manager.resolveMediaTypes(webRequest));

    request.setRequestURI("/foo.rss");
    assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));

    request.setRequestURI("/foo.atom");
    assertEquals(Arrays.asList(MediaType.APPLICATION_ATOM_XML), manager.resolveMediaTypes(webRequest));

    request.setRequestURI("/foo");
    request.setParameter("f", "json");
    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
  }
View Full Code Here

    this.configurer = new ContentNegotiationConfigurer(this.servletRequest.getServletContext());
  }

  @Test
  public void defaultSettings() throws Exception {
    ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();

    this.servletRequest.setRequestURI("/flower.gif");

    assertEquals("Should be able to resolve file extensions by default",
        Arrays.asList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest));

    this.servletRequest.setRequestURI("/flower?format=gif");
    this.servletRequest.addParameter("format", "gif");

    assertEquals("Should not resolve request parameters by default",
        Collections.emptyList(), manager.resolveMediaTypes(this.webRequest));

    this.servletRequest.setRequestURI("/flower");
    this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE);

    assertEquals("Should resolve Accept header by default",
        Arrays.asList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest));
  }
View Full Code Here

  }

  @Test
  public void addMediaTypes() throws Exception {
    this.configurer.mediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON));
    ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();

    this.servletRequest.setRequestURI("/flower.json");
    assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
  }
View Full Code Here

  @Test
  public void favorParameter() throws Exception {
    this.configurer.favorParameter(true);
    this.configurer.parameterName("f");
    this.configurer.mediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON));
    ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();

    this.servletRequest.setRequestURI("/flower");
    this.servletRequest.addParameter("f", "json");

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

  }

  @Test
  public void ignoreAcceptHeader() throws Exception {
    this.configurer.ignoreAcceptHeader(true);
    ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();

    this.servletRequest.setRequestURI("/flower");
    this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE);

    assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest));
  }
View Full Code Here

TOP

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

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.