Java Code Examples for org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#setUrlMap()

The following examples show how to use org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#setUrlMap() . 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: ValidatorController.java    From validator-web with Apache License 2.0 5 votes vote down vote up
public void setupUrlMapping(SimpleUrlHandlerMapping urlHandlerMapping) {
    Map<String, Object> urlMap = new HashMap<String, Object>();
    for (String url : this.processor.getUrlMapping().keySet()) {
        if (url.endsWith("/")) {
            url = url + "**";
        }
        urlMap.put(url, this);
    }
    urlHandlerMapping.setUrlMap(urlMap);
}
 
Example 2
Source File: HandlerMappingPrioritiesConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping simpleUrlHandlerMappingOrder0() {
    SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping();
    simpleUrlHandlerMapping.setOrder(0);
    Map<String, Object> urlMap = new HashMap<>();
    urlMap.put("/welcome", simpleUrlMapping());
    simpleUrlHandlerMapping.setUrlMap(urlMap);
    return simpleUrlHandlerMapping;
}
 
Example 3
Source File: FaviconConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping myFaviconHandlerMapping() {
    SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setOrder(Integer.MIN_VALUE);
    mapping.setUrlMap(Collections.singletonMap("/favicon.ico", faviconRequestHandler()));
    return mapping;
}
 
Example 4
Source File: WallRideWebMvcConfiguration.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping mediaUrlHandlerMapping(
		ApplicationContext applicationContext,
		ServletContext servletContext,
		ContentNegotiationManager contentNegotiationManager) {
	MediaHttpRequestHandler handler = new MediaHttpRequestHandler();

	handler.setServletContext(servletContext);
	handler.setApplicationContext(applicationContext);
	handler.setContentNegotiationManager(contentNegotiationManager);

	handler.setWallRideProperties(wallRideProperties);
	handler.setMediaService(mediaService);
	handler.setResourceLoader(resourceLoader);
	handler.setCacheSeconds(86400);

	try {
		handler.afterPropertiesSet();
	} catch (Exception e) {
		throw new BeanInitializationException("Failed to init MediaHttpRequestHandler", e);
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<>();
	urlMap.put("/media/{key}", handler);

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(0);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 5
Source File: SimulatorRestAutoConfiguration.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Bean
public HandlerMapping simulatorRestHandlerMapping(ApplicationContext applicationContext) {
    SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
    handlerMapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
    handlerMapping.setAlwaysUseFullPath(true);

    Map<String, Object> mappings = new HashMap<>();
    mappings.put(getUrlMapping(), createRestController(applicationContext));

    handlerMapping.setUrlMap(mappings);
    handlerMapping.setInterceptors(interceptors());

    return handlerMapping;
}
 
Example 6
Source File: WebSocketConfigurer.java    From computoser with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping handlerMapping() {

    SockJsService sockJsService = new DefaultSockJsService(taskScheduler());

    Map<String, Object> urlMap = new HashMap<String, Object>();
    urlMap.put("/game/websocket/**", new SockJsHttpRequestHandler(sockJsService, gameHandler));

    SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
    hm.setUrlMap(urlMap);
    return hm;
}
 
Example 7
Source File: ResourceUrlProviderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping simpleUrlHandlerMapping() {
	ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
	HashMap<String, ResourceHttpRequestHandler> handlerMap = new HashMap<String, ResourceHttpRequestHandler>();
	handlerMap.put("/resources/**", handler);
	SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
	hm.setUrlMap(handlerMap);
	return hm;
}
 
Example 8
Source File: ResourceHandlerRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.appContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Exception e) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 9
Source File: DefaultServletHandlerConfigurer.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
 * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if
 * default servlet handling was not been enabled.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (handler == null) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new HashMap<String, HttpRequestHandler>();
	urlMap.put("/**", handler);

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(Integer.MAX_VALUE);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 10
Source File: DefaultServletHandlerConfigurer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
 * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"};
 * or {@code null} if default servlet handling was not been enabled.
 * @since 4.3.12
 */
@Nullable
protected SimpleUrlHandlerMapping buildHandlerMapping() {
	if (this.handler == null) {
		return null;
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setUrlMap(Collections.singletonMap("/**", this.handler));
	handlerMapping.setOrder(Integer.MAX_VALUE);
	return handlerMapping;
}
 
Example 11
Source File: ResourceHandlerRegistry.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.applicationContext);
			handler.setContentNegotiationManager(this.contentNegotiationManager);
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable ex) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
Example 12
Source File: DefaultServletHandlerConfigurer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
 * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"};
 * or {@code null} if default servlet handling was not been enabled.
 * @since 4.3.12
 */
protected SimpleUrlHandlerMapping buildHandlerMapping() {
	if (this.handler == null) {
		return null;
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setUrlMap(Collections.singletonMap("/**", this.handler));
	handlerMapping.setOrder(Integer.MAX_VALUE);
	return handlerMapping;
}
 
Example 13
Source File: ResourceUrlProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping simpleUrlHandlerMapping() {
	ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
	HashMap<String, ResourceHttpRequestHandler> handlerMap = new HashMap<>();
	handlerMap.put("/resources/**", handler);
	SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
	hm.setUrlMap(handlerMap);
	return hm;
}
 
Example 14
Source File: ResourceHandlerRegistry.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
 * of no registrations.
 */
@Nullable
protected AbstractHandlerMapping getHandlerMapping() {
	if (this.registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			if (this.pathHelper != null) {
				handler.setUrlPathHelper(this.pathHelper);
			}
			if (this.contentNegotiationManager != null) {
				handler.setContentNegotiationManager(this.contentNegotiationManager);
			}
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.applicationContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable 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;
}
 
Example 15
Source File: DefaultServletHandlerConfigurer.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
 * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"};
 * or {@code null} if default servlet handling was not been enabled.
 * @since 4.3.12
 */
@Nullable
protected SimpleUrlHandlerMapping buildHandlerMapping() {
	if (this.handler == null) {
		return null;
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setUrlMap(Collections.singletonMap("/**", this.handler));
	handlerMapping.setOrder(Integer.MAX_VALUE);
	return handlerMapping;
}
 
Example 16
Source File: ResourceUrlProviderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping simpleUrlHandlerMapping() {
	ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
	HashMap<String, ResourceHttpRequestHandler> handlerMap = new HashMap<>();
	handlerMap.put("/resources/**", handler);
	SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
	hm.setUrlMap(handlerMap);
	return hm;
}
 
Example 17
Source File: ResourceHandlerRegistry.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case
 * of no registrations.
 */
@Nullable
protected AbstractHandlerMapping getHandlerMapping() {
	if (this.registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			if (this.pathHelper != null) {
				handler.setUrlPathHelper(this.pathHelper);
			}
			if (this.contentNegotiationManager != null) {
				handler.setContentNegotiationManager(this.contentNegotiationManager);
			}
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.applicationContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Throwable 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;
}