Java Code Examples for org.springframework.web.servlet.HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
The following examples show how to use
org.springframework.web.servlet.HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMessageConverterMethodProcessor.java From spring-analysis-note with MIT License | 6 votes |
@SuppressWarnings("unchecked") private boolean safeExtension(HttpServletRequest request, @Nullable String extension) { if (!StringUtils.hasText(extension)) { return true; } extension = extension.toLowerCase(Locale.ENGLISH); if (this.safeExtensions.contains(extension)) { return true; } String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pattern != null && pattern.endsWith("." + extension)) { return true; } if (extension.equals("html")) { String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(name); if (!CollectionUtils.isEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) { return true; } } return safeMediaTypesForExtension(new ServletWebRequest(request), extension); }
Example 2
Source File: AbstractMessageConverterMethodProcessor.java From java-technology-stack with MIT License | 6 votes |
@SuppressWarnings("unchecked") private boolean safeExtension(HttpServletRequest request, @Nullable String extension) { if (!StringUtils.hasText(extension)) { return true; } extension = extension.toLowerCase(Locale.ENGLISH); if (this.safeExtensions.contains(extension)) { return true; } String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pattern != null && pattern.endsWith("." + extension)) { return true; } if (extension.equals("html")) { String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(name); if (!CollectionUtils.isEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) { return true; } } return safeMediaTypesForExtension(new ServletWebRequest(request), extension); }
Example 3
Source File: AbstractMessageConverterMethodProcessor.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") private boolean safeExtension(HttpServletRequest request, String extension) { if (!StringUtils.hasText(extension)) { return true; } extension = extension.toLowerCase(Locale.ENGLISH); if (this.safeExtensions.contains(extension)) { return true; } String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pattern != null && pattern.endsWith("." + extension)) { return true; } if (extension.equals("html")) { String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(name); if (!CollectionUtils.isEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) { return true; } } return safeMediaTypesForExtension(extension); }
Example 4
Source File: AbstractMessageConverterMethodProcessor.java From spring4-understanding with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private boolean safeExtension(HttpServletRequest request, String extension) { if (!StringUtils.hasText(extension)) { return true; } extension = extension.toLowerCase(Locale.ENGLISH); if (this.safeExtensions.contains(extension)) { return true; } String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pattern != null && pattern.endsWith("." + extension)) { return true; } if (extension.equals("html")) { String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(name); if (!CollectionUtils.isEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) { return true; } } return safeMediaTypesForExtension(extension); }
Example 5
Source File: RequestAttributeAssertionTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testRequestAttributeMatcher() throws Exception { String producibleMediaTypes = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; this.mockMvc.perform(get("/1")) .andExpect(request().attribute(producibleMediaTypes, hasItem(MediaType.APPLICATION_JSON))) .andExpect(request().attribute(producibleMediaTypes, not(hasItem(MediaType.APPLICATION_XML)))); }
Example 6
Source File: RequestAttributeAssertionTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testRequestAttributeMatcher() throws Exception { String producibleMediaTypes = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; this.mockMvc.perform(get("/1")) .andExpect(request().attribute(producibleMediaTypes, hasItem(MediaType.APPLICATION_JSON))) .andExpect(request().attribute(producibleMediaTypes, not(hasItem(MediaType.APPLICATION_XML)))); }
Example 7
Source File: RequestAttributeAssertionTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testRequestAttributeMatcher() throws Exception { String producibleMediaTypes = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; this.mockMvc.perform(get("/1")) .andExpect(request().attribute(producibleMediaTypes, hasItem(MediaType.APPLICATION_JSON))) .andExpect(request().attribute(producibleMediaTypes, not(hasItem(MediaType.APPLICATION_XML)))); }