org.springframework.web.servlet.mvc.method.RequestMappingInfo Java Examples

The following examples show how to use org.springframework.web.servlet.mvc.method.RequestMappingInfo. 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: CrossOriginTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
				new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
				new RequestMethodsRequestCondition(annotation.method()),
				new ParamsRequestCondition(annotation.params()),
				new HeadersRequestCondition(annotation.headers()),
				new ConsumesRequestCondition(annotation.consumes(), annotation.headers()),
				new ProducesRequestCondition(annotation.produces(), annotation.headers()), null);
	}
	else {
		return null;
	}
}
 
Example #2
Source File: RequestMappingHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path,
		RequestMethod requestMethod) throws Exception {

	Class<?> clazz = ComposedAnnotationController.class;
	Method method = clazz.getMethod(methodName);
	RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);

	assertNotNull(info);

	Set<String> paths = info.getPatternsCondition().getPatterns();
	assertEquals(1, paths.size());
	assertEquals(path, paths.iterator().next());

	Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
	assertEquals(1, methods.size());
	assertEquals(requestMethod, methods.iterator().next());

	return info;
}
 
Example #3
Source File: CodelessAutoGenerateHandlerMapping.java    From sca-best-practice with Apache License 2.0 6 votes vote down vote up
private RequestMappingInfo createRequestMappingInfo(String codelessName, String action) {
    RequestMappingInfo.Builder builder = RequestMappingInfo
        .paths(resolveEmbeddedValuesInPatterns(new String[] {"/" + codelessName + "/" + action}));
    if ("add".equals(action)) {
        builder.methods(RequestMethod.POST);
    }
    if ("modify".equals(action)) {
        builder.methods(RequestMethod.PUT);
    }
    if ("delete".equals(action)) {
        builder.methods(RequestMethod.DELETE);
    }
    if ("get".equals(action) || Pattern.matches("list.*", action)) {
        builder.methods(RequestMethod.GET);
    }
    builder.mappingName("[" + codelessEntityMetadataMap.get(codelessName).getEntityClass().getSimpleName() + "] "
        + action
        + " mapping");
    return builder.options(this.config).build();
}
 
Example #4
Source File: WebApiRequestMappingCombiner.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Override
public RequestMappingInfo combine(Method method, Class<?> handlerType, RequestMappingInfo info) {
	if(info==null){
		return info;
	}
	Optional<AnnotationAttributes> webApiOpt = findWebApiAttrs(method, handlerType);
	if(!webApiOpt.isPresent()){
		return info;
	}
	AnnotationAttributes webApi = webApiOpt.get();
	String prefixPath = webApi.getString("prefixPath");
	if(StringUtils.isBlank(prefixPath)){
		return info;
	}
	prefixPath = SpringUtils.resolvePlaceholders(applicationContext, prefixPath);
	if(StringUtils.isBlank(prefixPath)){
		return info;
	}
	RequestMappingInfo combinerInfo = RequestMappingCombiner.createRequestMappingInfo(prefixPath, method, handlerType, info)
															.combine(info);
	return combinerInfo;
}
 
Example #5
Source File: RequestMappingHandlerMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
	HandlerMethod handlerMethod = createHandlerMethod(handler, method);
	Class<?> beanType = handlerMethod.getBeanType();
	CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
	CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);

	if (typeAnnotation == null && methodAnnotation == null) {
		return null;
	}

	CorsConfiguration config = new CorsConfiguration();
	updateCorsConfig(config, typeAnnotation);
	updateCorsConfig(config, methodAnnotation);

	if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
		for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
			config.addAllowedMethod(allowedMethod.name());
		}
	}
	return config.applyPermitDefaultValues();
}
 
Example #6
Source File: RequestMappingHandlerMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Uses method and type-level @{@link RequestMapping} annotations to create
 * the RequestMappingInfo.
 * @return the created RequestMappingInfo, or {@code null} if the method
 * does not have a {@code @RequestMapping} annotation.
 * @see #getCustomMethodCondition(Method)
 * @see #getCustomTypeCondition(Class)
 */
@Override
@Nullable
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMappingInfo info = createRequestMappingInfo(method);
	if (info != null) {
		RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
		if (typeInfo != null) {
			info = typeInfo.combine(info);
		}
		String prefix = getPathPrefix(handlerType);
		if (prefix != null) {
			info = RequestMappingInfo.paths(prefix).build().combine(info);
		}
	}
	return info;
}
 
Example #7
Source File: RbacAuthorityService.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取 所有URL Mapping,返回格式为{"/test":["GET","POST"],"/sys":["GET","DELETE"]}
 *
 * @return {@link ArrayListMultimap} 格式的 URL Mapping
 */
private Multimap<String, String> allUrlMapping() {
    Multimap<String, String> urlMapping = ArrayListMultimap.create();

    // 获取url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();

    handlerMethods.forEach((k, v) -> {
        // 获取当前 key 下的获取所有URL
        Set<String> url = k.getPatternsCondition()
                .getPatterns();
        RequestMethodsRequestCondition method = k.getMethodsCondition();

        // 为每个URL添加所有的请求方法
        url.forEach(s -> urlMapping.putAll(s, method.getMethods()
                .stream()
                .map(Enum::toString)
                .collect(Collectors.toList())));
    });

    return urlMapping;
}
 
Example #8
Source File: XssFiltersConfiguration.java    From XssRequestFilters with GNU General Public License v3.0 6 votes vote down vote up
public List<String> xssMatches() {
    List<String> urls = new ArrayList<String >();
    Map<RequestMappingInfo, HandlerMethod> handlerMethods =
            this.requestMappingHandlerMapping.getHandlerMethods();

    for(Map.Entry<RequestMappingInfo, HandlerMethod> item : handlerMethods.entrySet()) {
        RequestMappingInfo mapping = item.getKey();
        HandlerMethod method = item.getValue();
        if (mapping.getPatternsCondition() != null && mapping.getPatternsCondition().getPatterns() != null) {
            for (String urlPattern : mapping.getPatternsCondition().getPatterns()) {
                if(method.hasMethodAnnotation(XxsFilter.class)) {
                    urls.add(urlPattern);
                }
            }
        }
    }
    return urls;
}
 
Example #9
Source File: RequestMappingHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path,
		RequestMethod requestMethod) throws Exception {

	Class<?> clazz = ComposedAnnotationController.class;
	Method method = ClassUtils.getMethod(clazz, methodName, (Class<?>[]) null);
	RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);

	assertNotNull(info);

	Set<String> paths = info.getPatternsCondition().getPatterns();
	assertEquals(1, paths.size());
	assertEquals(path, paths.iterator().next());

	Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
	assertEquals(1, methods.size());
	assertEquals(requestMethod, methods.iterator().next());

	return info;
}
 
Example #10
Source File: PermissionHandlerMappingListener.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public void onHandlerMethodsInitialized(Map<RequestMappingInfo, HandlerMethod> handlerMethods) {
	this.permissionManager.build();
	for(Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethods.entrySet()){
		/*if (entry.getValue().getBeanType().getName().contains("SysSettingsController")) {
			System.out.println("test");
		}*/
		ByPermissionClass permClassInst = entry.getValue().getMethodAnnotation(ByPermissionClass.class);
		if(permClassInst==null){
			continue ;
		}
		for(Class<?> codeClass : permClassInst.value()){
			this.autoConifgPermission(codeClass, entry, permClassInst);
		}
	}
	this.permissionManager.getMemoryRootMenu().forEach(rootMenu->{
		logger.info("menu:\n{}", rootMenu.toTreeString("\n"));
	});
}
 
Example #11
Source File: CrossOriginTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
				new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
				new RequestMethodsRequestCondition(annotation.method()),
				new ParamsRequestCondition(annotation.params()),
				new HeadersRequestCondition(annotation.headers()),
				new ConsumesRequestCondition(annotation.consumes(), annotation.headers()),
				new ProducesRequestCondition(annotation.produces(), annotation.headers()), null);
	}
	else {
		return null;
	}
}
 
Example #12
Source File: RequestMappingMethodHandlerMapping.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
protected RequestMappingInfo createRequestMappingInfoByApiMethodAnno(RequestMapping requestMapping, RequestCondition<?> customCondition,
                                                                     Method method) {
    String[] patterns = resolveEmbeddedValuesInPatterns(requestMapping.value());
    if (!method.isAnnotationPresent(RequestMapping.class) || CollectionUtil.isEmpty(patterns)) {
        RequestMappingResolveResult methodParsered = RequestMappingResolver.resolveOwnPath(method);
        String path = methodParsered.getPath();
        patterns = new String[] { path };
    }

    return new RequestMappingInfo(
        new PatternsRequestCondition(patterns, getUrlPathHelper(), getPathMatcher(), this.useSuffixPatternMatch, this.useTrailingSlashMatch,
            this.fileExtensions),
        new RequestMethodsRequestCondition(requestMapping.method()), new ParamsRequestCondition(requestMapping.params()),
        new HeadersRequestCondition(requestMapping.headers()), new ConsumesRequestCondition(requestMapping.consumes(), requestMapping.headers()),
        new ProducesRequestCondition(requestMapping.produces(), requestMapping.headers(), this.contentNegotiationManager), customCondition);
}
 
Example #13
Source File: PermissionHandlerMappingListener.java    From onetwo with Apache License 2.0 6 votes vote down vote up
private void setResourcePatternByRequestMappingInfo(Class<?> codeClass, IPermission perm, Entry<RequestMappingInfo, HandlerMethod> entry){
	/*if(perm.getResourcesPattern()!=null){
		List<UrlResourceInfo> infos = urlResourceInfoParser.parseToUrlResourceInfos(perm.getResourcesPattern());
		//如果自定义了,忽略自动解释
		if(!infos.isEmpty()){
			String urls = this.urlResourceInfoParser.parseToString(infos);
			perm.setResourcesPattern(urls);
		}
		return ;
	}*/
	List<UrlResourceInfo> infos = urlResourceInfoParser.parseToUrlResourceInfos(perm.getResourcesPattern());
	
	Set<String> urlPattterns = entry.getKey().getPatternsCondition().getPatterns();
	
	if(urlPattterns.size()==1){
		String url = urlPattterns.stream().findFirst().orElse("");
		Optional<RequestMethod> method = getFirstMethod(entry.getKey());
		infos.add(new UrlResourceInfo(url, method.isPresent()?method.get().name():null));
		
	}else{
		//超过一个url映射的,不判断方法
		urlPattterns.stream().forEach(url->infos.add(new UrlResourceInfo(url)));
	}
	String urls = this.urlResourceInfoParser.parseToString(infos);
	perm.setResourcesPattern(urls);
}
 
Example #14
Source File: ExposedEndpointsControllerTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void getTest() {
    RequestMappingHandlerMapping handlerMapping = Mockito.mock(RequestMappingHandlerMapping.class);
    ExposedEndpointsController controller = new ExposedEndpointsController(new Gson(), handlerMapping);

    String endpoint1 = "/api/test";
    String endpoint2 = "/api/other/test";

    Map<RequestMappingInfo, HandlerMethod> handlerMethods = new HashMap<>();
    RequestMappingInfo info = new RequestMappingInfo(new PatternsRequestCondition(endpoint1, endpoint2), new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST), null, null, null, null, null);
    handlerMethods.put(info, null);

    Mockito.when(handlerMapping.getHandlerMethods()).thenReturn(handlerMethods);

    ResponseEntity<String> responseEntity = controller.get();
    Assertions.assertTrue(StringUtils.isNotBlank(responseEntity.getBody()), "Expected the response body to contain json");
}
 
Example #15
Source File: RequestMappingHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void useRegisteredSuffixPatternMatchInitialization() {
	Map<String, MediaType> fileExtensions = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
	PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(fileExtensions);
	ContentNegotiationManager manager = new ContentNegotiationManager(strategy);

	final Set<String> extensions = new HashSet<>();

	RequestMappingHandlerMapping hm = new RequestMappingHandlerMapping() {
		@Override
		protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
			extensions.addAll(getFileExtensions());
			return super.getMappingForMethod(method, handlerType);
		}
	};

	wac.registerSingleton("testController", ComposedAnnotationController.class);
	wac.refresh();

	hm.setContentNegotiationManager(manager);
	hm.setUseRegisteredSuffixPatternMatch(true);
	hm.setApplicationContext(wac);
	hm.afterPropertiesSet();

	assertEquals(Collections.singleton("json"), extensions);
}
 
Example #16
Source File: RequestMappingService.java    From api-mock-util with Apache License 2.0 6 votes vote down vote up
public boolean hasApiRegistered(String api,String requestMethod){
    notBlank(api,"api cant not be null");
    notBlank(requestMethod,"requestMethod cant not be null");

    RequestMappingHandlerMapping requestMappingHandlerMapping = webApplicationContext.getBean(RequestMappingHandlerMapping.class);
    Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
    for (RequestMappingInfo info : map.keySet()) {
        for(String pattern :info.getPatternsCondition().getPatterns()){
            if(pattern.equalsIgnoreCase(api)){ // 匹配url
                if(info.getMethodsCondition().getMethods().contains(getRequestMethod(requestMethod))){ // 匹配requestMethod
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example #17
Source File: RequestMappingHandlerMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Uses method and type-level @{@link RequestMapping} annotations to create
 * the RequestMappingInfo.
 * @return the created RequestMappingInfo, or {@code null} if the method
 * does not have a {@code @RequestMapping} annotation.
 * @see #getCustomMethodCondition(Method)
 * @see #getCustomTypeCondition(Class)
 */
@Override
@Nullable
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMappingInfo info = createRequestMappingInfo(method);
	if (info != null) {
		RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
		if (typeInfo != null) {
			info = typeInfo.combine(info);
		}
		String prefix = getPathPrefix(handlerType);
		if (prefix != null) {
			info = RequestMappingInfo.paths(prefix).build().combine(info);
		}
	}
	return info;
}
 
Example #18
Source File: RequestMappingHandlerMapping.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link RequestMappingInfo} from the supplied
 * {@link RequestMapping @RequestMapping} annotation, which is either
 * a directly declared annotation, a meta-annotation, or the synthesized
 * result of merging annotation attributes within an annotation hierarchy.
 */
protected RequestMappingInfo createRequestMappingInfo(
		RequestMapping requestMapping, RequestCondition<?> customCondition) {

	return RequestMappingInfo
			.paths(resolveEmbeddedValuesInPatterns(requestMapping.path()))
			.methods(requestMapping.method())
			.params(requestMapping.params())
			.headers(requestMapping.headers())
			.consumes(requestMapping.consumes())
			.produces(requestMapping.produces())
			.mappingName(requestMapping.name())
			.customCondition(customCondition)
			.options(this.config)
			.build();
}
 
Example #19
Source File: RbacAuthorityService.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取 所有URL Mapping,返回格式为{"/test":["GET","POST"],"/sys":["GET","DELETE"]}
 *
 * @return {@link ArrayListMultimap} 格式的 URL Mapping
 */
private Multimap<String, String> allUrlMapping() {
    Multimap<String, String> urlMapping = ArrayListMultimap.create();

    // 获取url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();

    handlerMethods.forEach((k, v) -> {
        // 获取当前 key 下的获取所有URL
        Set<String> url = k.getPatternsCondition()
                .getPatterns();
        RequestMethodsRequestCondition method = k.getMethodsCondition();

        // 为每个URL添加所有的请求方法
        url.forEach(s -> urlMapping.putAll(s, method.getMethods()
                .stream()
                .map(Enum::toString)
                .collect(Collectors.toList())));
    });

    return urlMapping;
}
 
Example #20
Source File: ApisController.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@PostConstruct
private void initApiMappings() {
    Map<RequestMappingInfo, HandlerMethod> requestMappedHandlers = this.handlerMapping.getHandlerMethods();
    for (Map.Entry<RequestMappingInfo, HandlerMethod> requestMappedHandlerEntry : requestMappedHandlers.entrySet()) {
        RequestMappingInfo requestMappingInfo = requestMappedHandlerEntry.getKey();
        HandlerMethod handlerMethod = requestMappedHandlerEntry.getValue();

        Class<?> handlerMethodBeanClazz = handlerMethod.getBeanType();
        if (handlerMethodBeanClazz == this.getClass()) {
            continue;
        }

        String controllerName = handlerMethodBeanClazz.getSimpleName();
        Set<String> mappedRequests = requestMappingInfo.getPatternsCondition().getPatterns();

        SortedSet<RequestMappedUri> alreadyMappedRequests = this.apiMappings.get(controllerName);
        if (alreadyMappedRequests == null) {
            alreadyMappedRequests = new TreeSet<RequestMappedUri>(RequestMappedUri.MAPPED_URI_ORDER);
            this.apiMappings.put(controllerName, alreadyMappedRequests);
        }
        alreadyMappedRequests.addAll(createRequestMappedApis(handlerMethod, mappedRequests));
    }
}
 
Example #21
Source File: OpenApiResource.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate path.
 *
 * @param restControllers the rest controllers
 * @param map the map
 */
protected void calculatePath(Map<String, Object> restControllers, Map<RequestMappingInfo, HandlerMethod> map) {
	for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) {
		RequestMappingInfo requestMappingInfo = entry.getKey();
		HandlerMethod handlerMethod = entry.getValue();
		PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
		Set<String> patterns = patternsRequestCondition.getPatterns();
		Map<String, String> regexMap = new LinkedHashMap<>();
		for (String pattern : patterns) {
			String operationPath = PathUtils.parsePath(pattern, regexMap);
			if (((actuatorProvider.isPresent() && actuatorProvider.get().isRestController(operationPath))
					|| isRestController(restControllers, handlerMethod, operationPath))
					&& isPackageToScan(handlerMethod.getBeanType().getPackage())
					&& isPathToMatch(operationPath)) {
				Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
				// default allowed requestmethods
				if (requestMethods.isEmpty())
					requestMethods = this.getDefaultAllowedHttpMethods();
				calculatePath(handlerMethod, operationPath, requestMethods);
			}
		}
	}
}
 
Example #22
Source File: CommonPageController.java    From Shiro-Action with MIT License 5 votes vote down vote up
/**
 * 获取 @RequestMapping 中配置的所有 URL.
 * @param keyword   关键字: 过滤条件
 * @return          URL 列表.
 */
@GetMapping("/system/urls")
@ResponseBody
public ResultBean getUrl(@RequestParam(defaultValue = "") String keyword) {
    RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
    // 获取url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
    Set<UrlVO> urlSet = new HashSet<>();

    for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {

        // URL 类型, JSON 还是 VIEW
        String type = "view";
        if (isResponseBodyUrl(m.getValue())){
            type = "json";
        }

        // URL 地址和 URL 请求 METHOD
        RequestMappingInfo info = m.getKey();
        PatternsRequestCondition p = info.getPatternsCondition();
        // 一个 @RequestMapping, 可能有多个 URL.
        for (String url : p.getPatterns()) {
            // 根据 keyword 过滤 URL
            if (url.contains(keyword)) {

                // 获取这个 URL 支持的所有 http method, 多个以逗号分隔, 未配置返回 ALL.
                Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
                String method = "ALL";
                if (methods.size() != 0) {
                    method = StringUtils.collectionToDelimitedString(methods, ",");
                }
                urlSet.add(new UrlVO(url, method, type));
            }
        }
    }
    return ResultBean.success(urlSet);
}
 
Example #23
Source File: SpringDocApp94Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Bean
public RequestMappingHandlerMapping defaultTestHandlerMapping(GreetingController greetingController) throws NoSuchMethodException {
	RequestMappingHandlerMapping result = new RequestMappingHandlerMapping();
	RequestMappingInfo requestMappingInfo =
			RequestMappingInfo.paths("/test").methods(RequestMethod.GET).produces(MediaType.APPLICATION_JSON_VALUE).build();

	result.setApplicationContext(this.applicationContext);
	result.registerMapping(requestMappingInfo, "greetingController", GreetingController.class.getDeclaredMethod("sayHello2"));
	//result.handlerme
	return result;
}
 
Example #24
Source File: RequestMappingMethodHandlerMapping.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
    RequestMappingInfo info = createRequestMappingInfo(method);
    if (info != null) {
        RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);
        if (typeInfo != null) {
            info = typeInfo.combine(info);
        }
    }
    return info;
}
 
Example #25
Source File: OperationTranslation.java    From httpdoc with Apache License 2.0 5 votes vote down vote up
public OperationTranslation(SpringMVCTranslation parent, RequestMappingInfo mapping, HandlerMethod handler, Method method, Controller controller) {
    super(parent);
    this.mapping = mapping;
    this.handler = handler;
    this.method = method;
    this.controller = controller;
}
 
Example #26
Source File: RequestMappingHandlerMapping.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RequestMatchResult match(HttpServletRequest request, String pattern) {
	RequestMappingInfo info = RequestMappingInfo.paths(pattern).options(this.config).build();
	RequestMappingInfo matchingInfo = info.getMatchingCondition(request);
	if (matchingInfo == null) {
		return null;
	}
	Set<String> patterns = matchingInfo.getPatternsCondition().getPatterns();
	String lookupPath = getUrlPathHelper().getLookupPathForRequest(request);
	return new RequestMatchResult(patterns.iterator().next(), lookupPath, getPathMatcher());
}
 
Example #27
Source File: XResponseViewManager.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
public void onHandlerMethodsInitialized(Map<RequestMappingInfo, HandlerMethod> handlerMethods) {
	for(HandlerMethod hm : handlerMethods.values()){
		Map<String, XResponseViewData> viewDatas = findXResponseViewData(hm);
		if(!viewDatas.isEmpty()){
			viewDataCaces.put(hm.getMethod().getName(), viewDatas);
		}
	}
	Map<String, XResponseViewData> def = ImmutableMap.of(XResponseView.DEFAULT_VIEW, new XResponseViewData(XResponseView.DEFAULT_VIEW, dataResultWrapper));
	this.viewDataCaces.put(XResponseView.DEFAULT_VIEW, def);
}
 
Example #28
Source File: DataRestRouterOperationBuilder.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets search entry.
 *
 * @param handlerMethodMap the handler method map
 * @return the search entry
 */
private Optional<Entry<RequestMappingInfo, HandlerMethod>> getSearchEntry(Map<RequestMappingInfo, HandlerMethod> handlerMethodMap) {
	return handlerMethodMap.entrySet().stream().filter(
			requestMappingInfoHandlerMethodEntry -> {
				RequestMappingInfo requestMappingInfo = requestMappingInfoHandlerMethodEntry.getKey();
				HandlerMethod handlerMethod = requestMappingInfoHandlerMethodEntry.getValue();
				Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
				for (RequestMethod requestMethod : requestMethods) {
					if (isSearchControllerPresent(requestMappingInfo, handlerMethod, requestMethod))
						return true;
				}
				return false;
			}).findAny();
}
 
Example #29
Source File: MenuServiceImpl.java    From FEBS-Security with Apache License 2.0 5 votes vote down vote up
@Override
public List<Map<String, String>> getAllUrl(String p1) {
    RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
    //获取 url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
    List<Map<String, String>> urlList = new ArrayList<>();
    for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) {
        RequestMappingInfo info = entry.getKey();
        HandlerMethod handlerMethod = map.get(info);
        PreAuthorize permissions = handlerMethod.getMethodAnnotation(PreAuthorize.class);
        String perms = "";
        if (null != permissions) {
            String value = permissions.value();
            value = StringUtils.substringBetween(value, "hasAuthority(", ")");
            perms = StringUtils.join(value, ",");
        }
        Set<String> patterns = info.getPatternsCondition().getPatterns();
        for (String url : patterns) {
            Map<String, String> urlMap = new HashMap<>();
            urlMap.put("url", url.replaceFirst("\\/", ""));
            urlMap.put("perms", perms);
            urlList.add(urlMap);
        }
    }
    return urlList;

}
 
Example #30
Source File: OptionalPrefixControllerAutoConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
private List<String> getPatterns(RequestMappingInfo mapping) {
	List<String> newPatterns = new ArrayList<String>(mapping.getPatternsCondition().getPatterns().size());
	for (String pattern : mapping.getPatternsCondition().getPatterns()) {
		newPatterns.add(prefix + pattern);
	}
	return newPatterns;
}