/** * Set the default content types to use when no content type is requested. * <p>By default this is not set. * @since 5.0 * @see #setDefaultContentTypeStrategy */ public void setDefaultContentTypes(List<MediaType> contentTypes) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentTypes); }
/** * Set the default content type to use when no content type is requested. * <p>By default this is not set. * @see #setDefaultContentTypeStrategy */ public void setDefaultContentType(MediaType contentType) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentType); }
/** * Set the default content type to use when no content type is requested. * <p>By default this is not set. * @see #setDefaultContentTypeStrategy */ public void setDefaultContentType(MediaType contentType) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentType); }
/** * Set the default content types to use when no content type is requested. * <p>By default this is not set. * @since 5.0 * @see #setDefaultContentTypeStrategy */ public void setDefaultContentTypes(List<MediaType> contentTypes) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentTypes); }
@Test public void setDefaultContentTypeStrategy() throws Exception { this.configurer.defaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); assertEquals(MediaType.APPLICATION_JSON, manager.resolveMediaTypes(this.webRequest).get(0)); }
@Test // SPR-12286 public void setDefaultContentTypeWithStrategy() throws Exception { this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE); assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); }
@Test public void nestedViewResolverIsNotSpringBean() throws Exception { StaticWebApplicationContext webAppContext = new StaticWebApplicationContext(); webAppContext.setServletContext(new MockServletContext()); webAppContext.refresh(); InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver(); nestedResolver.setApplicationContext(webAppContext); nestedResolver.setViewClass(InternalResourceView.class); viewResolver.setViewResolvers(new ArrayList<>(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 result = viewResolver.resolveViewName(viewName, locale); assertNotNull("Invalid view", result); }
new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
@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)); viewResolver.afterPropertiesSet(); View viewMock1 = mock(View.class, "application_xml"); View viewMock2 = mock(View.class, "text_html"); String viewName = "view"; Locale locale = Locale.ENGLISH; given(viewResolverMock1.resolveViewName(viewName, locale)).willReturn(viewMock1); given(viewResolverMock2.resolveViewName(viewName, locale)).willReturn(viewMock2); given(viewMock1.getContentType()).willReturn("application/xml"); given(viewMock2.getContentType()).willReturn("text/html;charset=ISO-8859-1"); View result = viewResolver.resolveViewName(viewName, locale); assertSame("Invalid view", viewMock1, result); }
/** * Set the default content types to use when no content type is requested. * <p>By default this is not set. * @since 5.0 * @see #setDefaultContentTypeStrategy */ public void setDefaultContentTypes(List<MediaType> contentTypes) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentTypes); }
/** * Set the default content type to use when no content type is requested. * <p>By default this is not set. * @see #setDefaultContentTypeStrategy */ public void setDefaultContentType(MediaType contentType) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentType); }
/** * Set the default content type to use when no content type is requested. * <p>By default this is not set. * @see #setDefaultContentTypeStrategy */ public void setDefaultContentType(MediaType contentType) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentType); }
/** * Set the default content types to use when no content type is requested. * <p>By default this is not set. * @see #setDefaultContentTypeStrategy * @since 5.0 */ public void setDefaultContentTypes(List<MediaType> contentTypes) { this.defaultNegotiationStrategy = new FixedContentNegotiationStrategy(contentTypes); }
@Override public void afterPropertiesSet() throws Exception { this.responseProcessor = new HttpEntityMethodProcessor( // this.messageConverters, // this.contentNegotiationManager // ); this.fallbackResponseProcessor = new HttpEntityMethodProcessor( // this.messageConverters, // new ContentNegotiationManager( // new FixedContentNegotiationStrategy(this.defaultContentType) // ) // ); }
@Override public void afterPropertiesSet() { if (contentNegotiationManager == null) { contentNegotiationManager = new ContentNegotiationManager( new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(defaultContentType)); } responseProcessor = new HttpEntityMethodProcessor(messageConverters, contentNegotiationManager); fallbackResponseProcessor = new HttpEntityMethodProcessor(messageConverters, new ContentNegotiationManager(new FixedContentNegotiationStrategy(defaultContentType))); }
@Override public void afterPropertiesSet() throws Exception { this.responseProcessor = new HttpEntityMethodProcessor( // this.messageConverters, // this.contentNegotiationManager // ); this.fallbackResponseProcessor = new HttpEntityMethodProcessor( // this.messageConverters, // new ContentNegotiationManager( // new FixedContentNegotiationStrategy(this.defaultContentType) // ) // ); }
public static ContentNegotiationManager defaultContentNegotiationManager(final MediaType defaultContentType) { final ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager( // new HeaderContentNegotiationStrategy(), // new ParameterContentNegotiationStrategy( // ImmutableMap.of("json", APPLICATION_JSON, "xml", APPLICATION_XML) // ), // new FixedContentNegotiationStrategy(defaultContentType) // ); return contentNegotiationManager; } }
public static ContentNegotiationManager defaultContentNegotiationManager(final MediaType defaultContentType) { final ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager( // new HeaderContentNegotiationStrategy(), // new ParameterContentNegotiationStrategy( // ImmutableMap.of("json", APPLICATION_JSON, "xml", APPLICATION_XML) // ), // new FixedContentNegotiationStrategy(defaultContentType) // ); return contentNegotiationManager; } }
strategies.add(new FixedContentNegotiationStrategy(this.defaultContentType));