Search in sources :

Example 1 with RequestMappingInfo

use of org.springframework.web.servlet.mvc.method.RequestMappingInfo in project pinpoint by naver.

the class ApisController method initApiMappings.

@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));
    }
}
Also used : RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) TreeMap(java.util.TreeMap) Map(java.util.Map) HandlerMethod(org.springframework.web.method.HandlerMethod) PostConstruct(javax.annotation.PostConstruct)

Example 2 with RequestMappingInfo

use of org.springframework.web.servlet.mvc.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingHandlerMappingTests method assertComposedAnnotationMapping.

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;
}
Also used : RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Method(java.lang.reflect.Method) RequestMethod(org.springframework.web.bind.annotation.RequestMethod)

Example 3 with RequestMappingInfo

use of org.springframework.web.servlet.mvc.method.RequestMappingInfo in project spring-security-oauth by spring-projects.

the class FrameworkEndpointHandlerMapping method getMappingForMethod.

@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
    RequestMappingInfo defaultMapping = super.getMappingForMethod(method, handlerType);
    if (defaultMapping == null) {
        return null;
    }
    Set<String> defaultPatterns = defaultMapping.getPatternsCondition().getPatterns();
    String[] patterns = new String[defaultPatterns.size()];
    int i = 0;
    for (String pattern : defaultPatterns) {
        patterns[i] = getPath(pattern);
        paths.add(pattern);
        i++;
    }
    PatternsRequestCondition patternsInfo = new PatternsRequestCondition(patterns, getUrlPathHelper(), getPathMatcher(), useSuffixPatternMatch(), useTrailingSlashMatch(), getFileExtensions());
    ParamsRequestCondition paramsInfo = defaultMapping.getParamsCondition();
    if (!approvalParameter.equals(OAuth2Utils.USER_OAUTH_APPROVAL) && defaultPatterns.contains("/oauth/authorize")) {
        String[] params = new String[paramsInfo.getExpressions().size()];
        Set<NameValueExpression<String>> expressions = paramsInfo.getExpressions();
        i = 0;
        for (NameValueExpression<String> expression : expressions) {
            String param = expression.toString();
            if (OAuth2Utils.USER_OAUTH_APPROVAL.equals(param)) {
                params[i] = approvalParameter;
            } else {
                params[i] = param;
            }
            i++;
        }
        paramsInfo = new ParamsRequestCondition(params);
    }
    RequestMappingInfo mapping = new RequestMappingInfo(patternsInfo, defaultMapping.getMethodsCondition(), paramsInfo, defaultMapping.getHeadersCondition(), defaultMapping.getConsumesCondition(), defaultMapping.getProducesCondition(), defaultMapping.getCustomCondition());
    return mapping;
}
Also used : NameValueExpression(org.springframework.web.servlet.mvc.condition.NameValueExpression) ParamsRequestCondition(org.springframework.web.servlet.mvc.condition.ParamsRequestCondition) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo)

Example 4 with RequestMappingInfo

use of org.springframework.web.servlet.mvc.method.RequestMappingInfo in project spring-boot-admin by codecentric.

the class PrefixHandlerMapping method withPrefix.

private RequestMappingInfo withPrefix(RequestMappingInfo mapping) {
    List<String> newPatterns = getPatterns(mapping);
    PatternsRequestCondition patterns = new PatternsRequestCondition(newPatterns.toArray(new String[newPatterns.size()]));
    return new RequestMappingInfo(patterns, mapping.getMethodsCondition(), mapping.getParamsCondition(), mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(), mapping.getCustomCondition());
}
Also used : PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo)

Example 5 with RequestMappingInfo

use of org.springframework.web.servlet.mvc.method.RequestMappingInfo in project spring-framework by spring-projects.

the class RequestMappingHandlerMapping method match.

@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());
}
Also used : RequestMatchResult(org.springframework.web.servlet.handler.RequestMatchResult) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo)

Aggregations

RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)9 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)3 PatternsRequestCondition (org.springframework.web.servlet.mvc.condition.PatternsRequestCondition)3 Method (java.lang.reflect.Method)2 Map (java.util.Map)2 Test (org.junit.Test)2 HandlerMethod (org.springframework.web.method.HandlerMethod)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 PostConstruct (javax.annotation.PostConstruct)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)1 AnnotationUtils (org.springframework.core.annotation.AnnotationUtils)1 HttpMethod (org.springframework.http.HttpMethod)1 RequestMatchResult (org.springframework.web.servlet.handler.RequestMatchResult)1 NameValueExpression (org.springframework.web.servlet.mvc.condition.NameValueExpression)1