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


Java HandlerMapping类代码示例

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


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

示例1: getHandler

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@Override
public HandlerExecutionChain getHandler(HttpServletRequest request)
		throws Exception {
	if (this.mappings == null) {
		this.mappings = extractMappings();
	}
	for (HandlerMapping mapping : this.mappings) {
		HandlerExecutionChain handler = mapping.getHandler(request);
		if (handler != null) {
			return handler;
		}
	}
	return null;
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:15,代码来源:EndpointWebMvcChildContextConfiguration.java

示例2: getMappingLocations

import org.springframework.web.servlet.HandlerMapping; //导入依赖的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

示例3: userUltraViresHandle

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
private void userUltraViresHandle ( HandlerMethod handlerMethod , HttpServletRequest request ) {

		/**
		 * 大概流程
		 * {@link org.springframework.web.servlet.DispatcherServlet#doDispatch(HttpServletRequest , HttpServletResponse)}
		 * {@link org.springframework.web.servlet.DispatcherServlet#getHandler(HttpServletRequest)}
		 * {@link org.springframework.web.servlet.handler.AbstractHandlerMapping#getHandler(HttpServletRequest)}
		 * {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#getHandlerInternal(HttpServletRequest)}
		 * ... ...
		 * 在下面方法中Spring会把解析后的Path URI存放到域中
		 * {@link org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping#handleMatch(Object , String , HttpServletRequest)}
		 *
		 */
		// /roles/{userId}/{roleId}
		final String uriVariables =
			( String ) request.getAttribute( HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE );
		// {userId=1, roleId=10000}
		final Map< String, String > decodedUriVariables = ( Map< String, String > ) request.getAttribute( HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE );

	}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:21,代码来源:AdminPermissionInterceptor.java

示例4: picture

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@RequestMapping(value = "/pages/**", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<FileSystemResource> picture(HttpServletRequest request) {

	String resource = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring(1);
	Path path = fileService.getPageFile(resource).toPath();

	File file = path.toAbsolutePath().toFile();

	if (file.exists() && file.isFile()) {
		try {
			String detect = tika.detect(file);
			MediaType mediaType = MediaType.parseMediaType(detect);
			return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType)
					.body(new FileSystemResource(file));
		} catch (IOException e) {
			e.printStackTrace();
		}
	} else {
           throw new ResourceNotFoundException();
       }
	return null;
}
 
开发者ID:Itema-as,项目名称:dawn-marketplace-server,代码行数:24,代码来源:PageController.java

示例5: getWorkflowJsonGeneric

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
/**
 * Get JSON representation of a workflow from generic git details
 * @param branch The branch of the repository
 * @return The JSON representation of the workflow
 */
@GetMapping(value="/workflows/**/*.git/{branch}/**",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Workflow getWorkflowJsonGeneric(@PathVariable("branch") String branch,
                                       HttpServletRequest request) {
    // The wildcard end of the URL is the path
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);

    // Construct a GitDetails object to search for in the database
    GitDetails gitDetails = WorkflowController.getGitDetails(11, path, branch);

    // Get workflow
    Workflow workflowModel = workflowService.getWorkflow(gitDetails);
    if (workflowModel == null) {
        throw new WorkflowNotFoundException();
    } else {
        return workflowModel;
    }
}
 
开发者ID:common-workflow-language,项目名称:cwlviewer,代码行数:24,代码来源:WorkflowJSONController.java

示例6: getProducibleMediaTypes

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
/**
 * Returns the media types that can be produced:
 * <ul>
 * <li>The producible media types specified in the request mappings, or
 * <li>Media types of configured converters that can write the specific return value, or
 * <li>{@link MediaType#ALL}
 * </ul>
 * @since 4.2
 */
@SuppressWarnings("unchecked")
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> returnValueClass, Type returnValueType) {
	Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
	if (!CollectionUtils.isEmpty(mediaTypes)) {
		return new ArrayList<MediaType>(mediaTypes);
	}
	else if (!this.allSupportedMediaTypes.isEmpty()) {
		List<MediaType> result = new ArrayList<MediaType>();
		for (HttpMessageConverter<?> converter : this.messageConverters) {
			if (converter instanceof GenericHttpMessageConverter && returnValueType != null) {
				if (((GenericHttpMessageConverter<?>) converter).canWrite(returnValueType, returnValueClass, null)) {
					result.addAll(converter.getSupportedMediaTypes());
				}
			}
			else if (converter.canWrite(returnValueClass, null)) {
				result.addAll(converter.getSupportedMediaTypes());
			}
		}
		return result;
	}
	else {
		return Collections.singletonList(MediaType.ALL);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:AbstractMessageConverterMethodProcessor.java

示例7: resolveArgument

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
/**
 * Return a Map with all URI template variables or an empty map.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, String> uriTemplateVars =
			(Map<String, String>) webRequest.getAttribute(
					HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (!CollectionUtils.isEmpty(uriTemplateVars)) {
		return new LinkedHashMap<String, String>(uriTemplateVars);
	}
	else {
		return Collections.emptyMap();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:PathVariableMapMethodArgumentResolver.java

示例8: resourceHandlerMapping

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped
 * resource handlers. To configure resource handling, override
 * {@link #addResourceHandlers}.
 */
@Bean
public HandlerMapping resourceHandlerMapping() {
	ResourceHandlerRegistry registry = new ResourceHandlerRegistry(this.applicationContext, this.servletContext);
	addResourceHandlers(registry);

	AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
	if (handlerMapping != null) {
		handlerMapping.setPathMatcher(mvcPathMatcher());
		handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
		handlerMapping.setInterceptors(new HandlerInterceptor[] {
				new ResourceUrlProviderExposingInterceptor(mvcResourceUrlProvider())});
		handlerMapping.setCorsConfigurations(getCorsConfigurations());
	}
	else {
		handlerMapping = new EmptyHandlerMapping();
	}
	return handlerMapping;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:WebMvcConfigurationSupport.java

示例9: uriTemplateReuseCurrentRequestVars

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@Test
public void uriTemplateReuseCurrentRequestVars() throws Exception {
	Map<String, Object> model = new HashMap<String, Object>();
	model.put("key1", "value1");
	model.put("name", "value2");
	model.put("key3", "value3");

	Map<String, String> currentRequestUriTemplateVars = new HashMap<String, String>();
	currentRequestUriTemplateVars.put("var1", "v1");
	currentRequestUriTemplateVars.put("name", "v2");
	currentRequestUriTemplateVars.put("var3", "v3");
	this.request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, currentRequestUriTemplateVars);

	String url = "http://url.somewhere.com";
	RedirectView redirectView = new RedirectView(url + "/{key1}/{var1}/{name}");
	redirectView.renderMergedOutputModel(model, this.request, this.response);

	assertEquals(url + "/value1/v1/value2?key3=value3", this.response.getRedirectedUrl());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:RedirectViewUriTemplateTests.java

示例10: getFile

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@RequestMapping(value = "/static/**", method = RequestMethod.GET)
public void getFile(HttpServletResponse response, HttpServletRequest request) {
	try {

		String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
		PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver();

		Resource template = res.getResource(path);

		if (!template.exists()) {
			log.info("file n/a... " + path);
			return;
		}

		org.apache.commons.io.IOUtils.copy(template.getInputStream(), response.getOutputStream());
		response.flushBuffer();

	} catch (IOException ex) {
		log.info("Error writing file to output stream", ex);
	}
}
 
开发者ID:SchweizerischeBundesbahnen,项目名称:releasetrain,代码行数:22,代码来源:FileDownloadUtil.java

示例11: downloadGraphPng

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
/**
 * Download a generated graph for a workflow in PNG format
 * @param domain The domain of the hosting site, Github or Gitlab
 * @param owner The owner of the repository
 * @param repoName The name of the repository
 * @param branch The branch of repository
 */
@GetMapping(value={"/graph/png/{domain}.com/{owner}/{repoName}/tree/{branch}/**",
                   "/graph/png/{domain}.com/{owner}/{repoName}/blob/{branch}/**"},
            produces="image/png")
@ResponseBody
public FileSystemResource downloadGraphPng(@PathVariable("domain") String domain,
                                           @PathVariable("owner") String owner,
                                           @PathVariable("repoName") String repoName,
                                           @PathVariable("branch") String branch,
                                           HttpServletRequest request,
                                           HttpServletResponse response) throws IOException {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    path = extractPath(path, 8);
    GitDetails gitDetails = getGitDetails(domain, owner, repoName, branch, path);
    response.setHeader("Content-Disposition", "inline; filename=\"graph.png\"");
    return workflowService.getWorkflowGraph("png", gitDetails);
}
 
开发者ID:common-workflow-language,项目名称:cwlviewer,代码行数:24,代码来源:WorkflowController.java

示例12: setUp

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	this.resolver = new MatrixVariableMethodArgumentResolver();

	Method method = getClass().getMethod("handle", String.class, List.class, int.class);
	this.paramString = new MethodParameter(method, 0);
	this.paramColors = new MethodParameter(method, 1);
	this.paramYear = new MethodParameter(method, 2);

	this.paramColors.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());

	this.mavContainer = new ModelAndViewContainer();
	this.request = new MockHttpServletRequest();
	this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse());

	Map<String, MultiValueMap<String, String>> params = new LinkedHashMap<String, MultiValueMap<String, String>>();
	this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MatrixVariablesMethodArgumentResolverTests.java

示例13: setUp

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	this.resolver = new MatrixVariableMapMethodArgumentResolver();

	Method method = getClass().getMethod("handle", String.class,
			Map.class, MultiValueMap.class, MultiValueMap.class, Map.class);

	this.paramString = new SynthesizingMethodParameter(method, 0);
	this.paramMap = new SynthesizingMethodParameter(method, 1);
	this.paramMultivalueMap = new SynthesizingMethodParameter(method, 2);
	this.paramMapForPathVar = new SynthesizingMethodParameter(method, 3);
	this.paramMapWithName = new SynthesizingMethodParameter(method, 4);

	this.mavContainer = new ModelAndViewContainer();
	this.request = new MockHttpServletRequest();
	this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse());

	Map<String, MultiValueMap<String, String>> params = new LinkedHashMap<String, MultiValueMap<String, String>>();
	this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MatrixVariablesMapMethodArgumentResolverTests.java

示例14: uriTemplateVariables

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
@Test
public void uriTemplateVariables() {
	PatternsRequestCondition patterns = new PatternsRequestCondition("/{path1}/{path2}");
	RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
	String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	@SuppressWarnings("unchecked")
	Map<String, String> uriVariables =
		(Map<String, String>) request.getAttribute(
				HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

	assertNotNull(uriVariables);
	assertEquals("1", uriVariables.get("path1"));
	assertEquals("2", uriVariables.get("path2"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:RequestMappingInfoHandlerMappingTests.java

示例15: getWorkflowJson

import org.springframework.web.servlet.HandlerMapping; //导入依赖的package包/类
/**
 * Get the JSON representation of a workflow from Github or Gitlab details
 * @param domain The domain of the hosting site, Github or Gitlab
 * @param owner The owner of the Github repository
 * @param repoName The name of the repository
 * @param branch The branch of repository
 * @return The JSON representation of the workflow
 */
@GetMapping(value = {"/workflows/{domain}.com/{owner}/{repoName}/tree/{branch}/**",
                     "/workflows/{domain}.com/{owner}/{repoName}/blob/{branch}/**"},
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Workflow getWorkflowJson(@PathVariable("domain") String domain,
                                @PathVariable("owner") String owner,
                                @PathVariable("repoName") String repoName,
                                @PathVariable("branch") String branch,
                                HttpServletRequest request) {
    // The wildcard end of the URL is the path
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    path = WorkflowController.extractPath(path, 7);

    // Construct a GitDetails object to search for in the database
    GitDetails gitDetails = WorkflowController.getGitDetails(domain, owner, repoName, branch, path);

    // Get workflow
    Workflow workflowModel = workflowService.getWorkflow(gitDetails);
    if (workflowModel == null) {
        throw new WorkflowNotFoundException();
    } else {
        return workflowModel;
    }
}
 
开发者ID:common-workflow-language,项目名称:cwlviewer,代码行数:32,代码来源:WorkflowJSONController.java


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