Search in sources :

Example 6 with SimpleUrlHandlerMapping

use of org.springframework.web.reactive.handler.SimpleUrlHandlerMapping in project spring-framework by spring-projects.

the class ResourceHandlerRegistry method getHandlerMapping.

/**
	 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
	 * of no registrations.
	 */
protected AbstractHandlerMapping getHandlerMapping() {
    if (this.registrations.isEmpty()) {
        return null;
    }
    Map<String, WebHandler> urlMap = new LinkedHashMap<>();
    for (ResourceHandlerRegistration registration : this.registrations) {
        for (String pathPattern : registration.getPathPatterns()) {
            ResourceWebHandler handler = registration.getRequestHandler();
            handler.setContentTypeResolver(this.contentTypeResolver);
            try {
                handler.afterPropertiesSet();
                handler.afterSingletonsInstantiated();
            } catch (Exception ex) {
                throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
            }
            urlMap.put(pathPattern, handler);
        }
    }
    SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
    handlerMapping.setOrder(this.order);
    handlerMapping.setUrlMap(urlMap);
    return handlerMapping;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) WebHandler(org.springframework.web.server.WebHandler) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

SimpleUrlHandlerMapping (org.springframework.web.reactive.handler.SimpleUrlHandlerMapping)6 Test (org.junit.Test)4 ResourceWebHandler (org.springframework.web.reactive.resource.ResourceWebHandler)4 WebHandler (org.springframework.web.server.WebHandler)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 AbstractHandlerMapping (org.springframework.web.reactive.handler.AbstractHandlerMapping)1