当前位置: 首页>>代码示例>>Java>>正文


Java SimpleUrlHandlerMapping类代码示例

本文整理汇总了Java中org.springframework.web.servlet.handler.SimpleUrlHandlerMapping的典型用法代码示例。如果您正苦于以下问题:Java SimpleUrlHandlerMapping类的具体用法?Java SimpleUrlHandlerMapping怎么用?Java SimpleUrlHandlerMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleUrlHandlerMapping类属于org.springframework.web.servlet.handler包,在下文中一共展示了SimpleUrlHandlerMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMappingLocations

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Map<String, List<Resource>> getMappingLocations(HandlerMapping mapping)
		throws IllegalAccessException {
	Map<String, List<Resource>> mappingLocations = new LinkedHashMap<String, List<Resource>>();
	if (mapping instanceof SimpleUrlHandlerMapping) {
		Field locationsField = ReflectionUtils
				.findField(ResourceHttpRequestHandler.class, "locations");
		locationsField.setAccessible(true);
		for (Map.Entry<String, Object> entry : ((SimpleUrlHandlerMapping) mapping)
				.getHandlerMap().entrySet()) {
			ResourceHttpRequestHandler handler = (ResourceHttpRequestHandler) entry
					.getValue();
			mappingLocations.put(entry.getKey(),
					(List<Resource>) locationsField.get(handler));
		}
	}
	return mappingLocations;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:WebMvcAutoConfigurationTests.java

示例2: detectResourceHandlers

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
protected void detectResourceHandlers(ApplicationContext appContext) {
	logger.debug("Looking for resource handler mappings");

	Map<String, SimpleUrlHandlerMapping> map = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
	List<SimpleUrlHandlerMapping> handlerMappings = new ArrayList<SimpleUrlHandlerMapping>(map.values());
	AnnotationAwareOrderComparator.sort(handlerMappings);

	for (SimpleUrlHandlerMapping hm : handlerMappings) {
		for (String pattern : hm.getHandlerMap().keySet()) {
			Object handler = hm.getHandlerMap().get(pattern);
			if (handler instanceof ResourceHttpRequestHandler) {
				ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler;
				if (logger.isDebugEnabled()) {
					logger.debug("Found resource handler mapping: URL pattern=\"" + pattern + "\", " +
							"locations=" + resourceHandler.getLocations() + ", " +
							"resolvers=" + resourceHandler.getResourceResolvers());
				}
				this.handlerMap.put(pattern, resourceHandler);
			}
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ResourceUrlProvider.java

示例3: registerHandlerMapping

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
private BeanDefinition registerHandlerMapping(ParserContext context, Object source) {
	if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) {
		return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME);
	}
	RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef);
	context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME));

	beanDef.setSource(source);
	beanDef.getPropertyValues().add("order", "1");
	beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source));
	beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source));
	RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source);
	beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);

	return beanDef;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ViewControllerBeanDefinitionParser.java

示例4: testDefaultServletHandler

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void testDefaultServletHandler() throws Exception {
	loadBeanDefinitions("mvc-config-default-servlet.xml", 6);

	HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
	assertNotNull(adapter);

	DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/foo.css");
	request.setMethod("GET");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);

	MockHttpServletResponse response = new MockHttpServletResponse();
	ModelAndView mv = adapter.handle(request, response, chain.getHandler());
	assertNull(mv);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:MvcNamespaceTests.java

示例5: testDefaultServletHandlerWithOptionalAttributes

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void testDefaultServletHandlerWithOptionalAttributes() throws Exception {
	loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml", 6);

	HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
	assertNotNull(adapter);

	DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/foo.css");
	request.setMethod("GET");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);

	MockHttpServletResponse response = new MockHttpServletResponse();
	ModelAndView mv = adapter.handle(request, response, chain.getHandler());
	assertNull(mv);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:MvcNamespaceTests.java

示例6: testViewControllersDefaultConfig

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void testViewControllersDefaultConfig() {
	loadBeanDefinitions("mvc-config-view-controllers-minimal.xml", 7);

	SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(hm);
	ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
	assertNotNull(viewController);
	assertEquals("home", viewController.getViewName());

	ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
	assertNotNull(redirectViewController);
	assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class));

	ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
	assertNotNull(statusViewController);
	assertEquals(404, statusViewController.getStatusCode().value());

	BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
	assertNotNull(beanNameMapping);
	assertEquals(2, beanNameMapping.getOrder());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:MvcNamespaceTests.java

示例7: testPathMatchingHandlerMappings

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void testPathMatchingHandlerMappings() throws Exception {
	loadBeanDefinitions("mvc-config-path-matching-mappings.xml", 23);

	RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(requestMapping);
	assertEquals(TestPathHelper.class, requestMapping.getUrlPathHelper().getClass());
	assertEquals(TestPathMatcher.class, requestMapping.getPathMatcher().getClass());

	SimpleUrlHandlerMapping viewController = appContext.getBean(VIEWCONTROLLER_BEAN_NAME, SimpleUrlHandlerMapping.class);
	assertNotNull(viewController);
	assertEquals(TestPathHelper.class, viewController.getUrlPathHelper().getClass());
	assertEquals(TestPathMatcher.class, viewController.getPathMatcher().getClass());

	for (SimpleUrlHandlerMapping handlerMapping : appContext.getBeansOfType(SimpleUrlHandlerMapping.class).values()) {
		assertNotNull(handlerMapping);
		assertEquals(TestPathHelper.class, handlerMapping.getUrlPathHelper().getClass());
		assertEquals(TestPathMatcher.class, handlerMapping.getPathMatcher().getClass());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MvcNamespaceTests.java

示例8: enable

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void enable() throws Exception {
	configurer.enable();
	SimpleUrlHandlerMapping getHandlerMapping = getHandlerMapping();
	SimpleUrlHandlerMapping handlerMapping = getHandlerMapping;
	DefaultServletHttpRequestHandler handler = (DefaultServletHttpRequestHandler) handlerMapping.getUrlMap().get("/**");

	assertNotNull(handler);
	assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());

	handler.handleRequest(new MockHttpServletRequest(), response);

	String expected = "default";
	assertEquals("The ServletContext was not called with the default servlet name", expected, servletContext.url);
	assertEquals("The request was not forwarded", expected, response.getForwardedUrl());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DefaultServletHandlerConfigurerTests.java

示例9: getHandlerMapping

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping with the mapped ViewControllers; or {@code null} in case
 * of no registrations.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<>();
	for (WebMvcWampWebSocketEndpointRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration
				.getMappings();
		for (HttpRequestHandler httpHandler : mappings.keySet()) {
			for (String pattern : mappings.get(httpHandler)) {
				urlMap.put(pattern, httpHandler);
			}
		}
	}
	SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:24,代码来源:WebMvcWampEndpointRegistry.java

示例10: setUp

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {

	requestPayload = readResource("request_add.txt");
	responsePayload = readResource("response_add.txt");
	MockServletContext servletContext = new MockServletContext(new ResourceLoaderSupport());
	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	applicationContext = new XmlWebApplicationContext();
	applicationContext.setServletContext(servletContext);
	applicationContext.setServletConfig(servletConfig);
	applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/exporter-servlet.xml",
			"src/main/webapp/WEB-INF/applicationContext.xml" });
	applicationContext.refresh();
	handlerMapping = (SimpleUrlHandlerMapping) applicationContext
			.getBean("org.springframework.web.servlet.handler.SimpleUrlHandlerMapping");
}
 
开发者ID:ggeorgovassilis,项目名称:gwt-sl,代码行数:18,代码来源:TestRPCExporter.java

示例11: getHandlerMapping

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
/**
 * Returns a handler mapping with the mapped ViewControllers; or {@code null} in case of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (registrations.isEmpty()) {
		return null;
	}

	Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
	for (ViewControllerRegistration registration : registrations) {
		urlMap.put(registration.getUrlPath(), registration.getViewController());
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:ViewControllerRegistry.java

示例12: getHandlerMapping

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
/**
 * 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 : registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler requestHandler = registration.getRequestHandler();
			requestHandler.setServletContext(servletContext);
			requestHandler.setApplicationContext(applicationContext);
			urlMap.put(pathPattern, requestHandler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:ResourceHandlerRegistry.java

示例13: testDefaultServletHandler

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void testDefaultServletHandler() throws Exception {
	loadBeanDefinitions("mvc-config-default-servlet.xml", 5);

	HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
	assertNotNull(adapter);

	DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/foo.css");
	request.setMethod("GET");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);

	MockHttpServletResponse response = new MockHttpServletResponse();
	ModelAndView mv = adapter.handle(request, response, chain.getHandler());
	assertNull(mv);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:26,代码来源:MvcNamespaceTests.java

示例14: testDefaultServletHandlerWithOptionalAttributes

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
@Test
public void testDefaultServletHandlerWithOptionalAttributes() throws Exception {
	loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml", 5);

	HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
	assertNotNull(adapter);

	DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
	assertNotNull(handler);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertEquals(Ordered.LOWEST_PRECEDENCE, mapping.getOrder());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/foo.css");
	request.setMethod("GET");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);

	MockHttpServletResponse response = new MockHttpServletResponse();
	ModelAndView mv = adapter.handle(request, response, chain.getHandler());
	assertNull(mv);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:26,代码来源:MvcNamespaceTests.java

示例15: addControllerToCasServletHandlerMapping

import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; //导入依赖的package包/类
/**
 * Add controller to cas servlet handler mapping.
 *
 * @param path the path
 * @param controller the controller
 */
protected final void addControllerToCasServletHandlerMapping(final String path, final Object controller) {
    logger.debug("Adding {} to application context for {}", controller, path);
    final SimpleUrlHandlerMapping handlerMappingC = getCasServletHandlerMapping();
    final Map<String, Object> urlMap = (Map<String, Object>) handlerMappingC.getUrlMap();
    urlMap.put(path, controller);
    handlerMappingC.initApplicationContext();

}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:AbstractServletContextInitializer.java


注:本文中的org.springframework.web.servlet.handler.SimpleUrlHandlerMapping类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。