springrfcspring-eluritemplate

Does Spring MVC URI Template processing implement RFC 6570?


I am trying to find a definitive answer as to how URI Templates in Spring MVC are parsed. The Documentation links to the Draft RFC, but Spring is not listed in the RFC's implementations page On the other hand, this page seems to suggest that they use SpEL. Anyone has a link that could clear this for me?


Solution

  • There are two classes involved on parsing URI Templates.

    You can use these classes to test how the URI Templates are parsed.

    For example for MVC RequestMapping:

    @RunWith(BlockJUnit4ClassRunner.class)
    public class UriTemplateTest {
    
        private AntPathMatcher matcher = new AntPathMatcher();
        private Log log = LogFactory.getLog(UriTemplateTest.class);
    
        @Test
        public void testUriTemplate() {
            Map<String, String> variables = matcher.extractUriTemplateVariables("/booking/hotel/{id}", "/booking/hotel/43");
            log.info(variables);
        }
    
    }