/** * Build a {@link ContentNegotiationManager} based on this configurer's settings. * @since 4.3.12 * @see ContentNegotiationManagerFactoryBean#getObject() */ protected ContentNegotiationManager buildContentNegotiationManager() { this.factory.addMediaTypes(this.mediaTypes); return this.factory.build(); }
/** * Build a {@link ContentNegotiationManager} based on this configurer's settings. * @since 4.3.12 * @see ContentNegotiationManagerFactoryBean#getObject() */ protected ContentNegotiationManager buildContentNegotiationManager() { this.factory.addMediaTypes(this.mediaTypes); return this.factory.build(); }
@Test public void favorParameter() throws Exception { this.factoryBean.setFavorParameter(true); Map<String, MediaType> mediaTypes = new HashMap<>(); mediaTypes.put("json", MediaType.APPLICATION_JSON); this.factoryBean.addMediaTypes(mediaTypes); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); this.servletRequest.setRequestURI("/flower"); this.servletRequest.addParameter("format", "json"); assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); }
@Test public void favorPath() throws Exception { this.factoryBean.setFavorPathExtension(true); this.factoryBean.addMediaTypes(Collections.singletonMap("bar", new MediaType("application", "bar"))); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); this.servletRequest.setRequestURI("/flower.foo"); assertEquals(Collections.singletonList(new MediaType("application", "foo")), manager.resolveMediaTypes(this.webRequest)); this.servletRequest.setRequestURI("/flower.bar"); assertEquals(Collections.singletonList(new MediaType("application", "bar")), manager.resolveMediaTypes(this.webRequest)); this.servletRequest.setRequestURI("/flower.gif"); assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest)); }
/** * Build a {@link ContentNegotiationManager} based on this configurer's settings. * @since 4.3.12 * @see ContentNegotiationManagerFactoryBean#getObject() */ protected ContentNegotiationManager buildContentNegotiationManager() { this.factory.addMediaTypes(this.mediaTypes); this.factory.afterPropertiesSet(); return this.factory.getObject(); }