Search in sources :

Example 1 with RequestMethodsRequestCondition

use of org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition in project spring-framework by spring-projects.

the class RequestMappingInfo method getMatchingCondition.

/**
	 * Checks if all conditions in this request mapping info match the provided request and returns
	 * a potentially new request mapping info with conditions tailored to the current request.
	 * <p>For example the returned instance may contain the subset of URL patterns that match to
	 * the current request, sorted with best matching patterns on top.
	 * @return a new instance in case all conditions match; or {@code null} otherwise
	 */
@Override
public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
    RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
    ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
    HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
    ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
    ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
    if (methods == null || params == null || headers == null || consumes == null || produces == null) {
        return null;
    }
    PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
    if (patterns == null) {
        return null;
    }
    RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);
    if (custom == null) {
        return null;
    }
    return new RequestMappingInfo(this.name, patterns, methods, params, headers, consumes, produces, custom.getCondition());
}
Also used : ParamsRequestCondition(org.springframework.web.servlet.mvc.condition.ParamsRequestCondition) ProducesRequestCondition(org.springframework.web.servlet.mvc.condition.ProducesRequestCondition) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestConditionHolder(org.springframework.web.servlet.mvc.condition.RequestConditionHolder) HeadersRequestCondition(org.springframework.web.servlet.mvc.condition.HeadersRequestCondition) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) ConsumesRequestCondition(org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition)

Example 2 with RequestMethodsRequestCondition

use of org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition in project spring-framework by spring-projects.

the class RequestMappingInfo method combine.

/**
	 * Combines "this" request mapping info (i.e. the current instance) with another request mapping info instance.
	 * <p>Example: combine type- and method-level request mappings.
	 * @return a new request mapping info instance; never {@code null}
	 */
@Override
public RequestMappingInfo combine(RequestMappingInfo other) {
    String name = combineNames(other);
    PatternsRequestCondition patterns = this.patternsCondition.combine(other.patternsCondition);
    RequestMethodsRequestCondition methods = this.methodsCondition.combine(other.methodsCondition);
    ParamsRequestCondition params = this.paramsCondition.combine(other.paramsCondition);
    HeadersRequestCondition headers = this.headersCondition.combine(other.headersCondition);
    ConsumesRequestCondition consumes = this.consumesCondition.combine(other.consumesCondition);
    ProducesRequestCondition produces = this.producesCondition.combine(other.producesCondition);
    RequestConditionHolder custom = this.customConditionHolder.combine(other.customConditionHolder);
    return new RequestMappingInfo(name, patterns, methods, params, headers, consumes, produces, custom.getCondition());
}
Also used : ParamsRequestCondition(org.springframework.web.servlet.mvc.condition.ParamsRequestCondition) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) ProducesRequestCondition(org.springframework.web.servlet.mvc.condition.ProducesRequestCondition) RequestConditionHolder(org.springframework.web.servlet.mvc.condition.RequestConditionHolder) HeadersRequestCondition(org.springframework.web.servlet.mvc.condition.HeadersRequestCondition) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) ConsumesRequestCondition(org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition)

Example 3 with RequestMethodsRequestCondition

use of org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition in project dhis2-core by dhis2.

the class CustomRequestMappingHandlerMapping method getMappingForMethod.

@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
    RequestMappingInfo info = super.getMappingForMethod(method, handlerType);
    if (info == null) {
        return null;
    }
    ApiVersion typeApiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
    ApiVersion methodApiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class);
    if (typeApiVersion == null && methodApiVersion == null) {
        return info;
    }
    RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
    if (methodsCondition.getMethods().isEmpty()) {
        methodsCondition = new RequestMethodsRequestCondition(RequestMethod.GET);
    }
    Set<String> rqmPatterns = info.getPatternsCondition().getPatterns();
    Set<String> patterns = new HashSet<>();
    Set<DhisApiVersion> versions = getVersions(typeApiVersion, methodApiVersion);
    for (String pattern : rqmPatterns) {
        versions.stream().filter(version -> !version.isIgnore()).forEach(version -> {
            if (!pattern.startsWith(version.getVersionString())) {
                if (pattern.startsWith("/"))
                    patterns.add("/" + version.getVersion() + pattern);
                else
                    patterns.add("/" + version.getVersion() + "/" + pattern);
            } else {
                patterns.add(pattern);
            }
        });
    }
    PatternsRequestCondition patternsRequestCondition = new PatternsRequestCondition(patterns.toArray(new String[] {}), null, null, true, true, null);
    return new RequestMappingInfo(null, patternsRequestCondition, methodsCondition, info.getParamsCondition(), info.getHeadersCondition(), info.getConsumesCondition(), info.getProducesCondition(), info.getCustomCondition());
}
Also used : DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) HashSet(java.util.HashSet) Arrays(java.util.Arrays) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) Set(java.util.Set) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) Method(java.lang.reflect.Method) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) HashSet(java.util.HashSet)

Aggregations

PatternsRequestCondition (org.springframework.web.servlet.mvc.condition.PatternsRequestCondition)3 RequestMethodsRequestCondition (org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition)3 ConsumesRequestCondition (org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition)2 HeadersRequestCondition (org.springframework.web.servlet.mvc.condition.HeadersRequestCondition)2 ParamsRequestCondition (org.springframework.web.servlet.mvc.condition.ParamsRequestCondition)2 ProducesRequestCondition (org.springframework.web.servlet.mvc.condition.ProducesRequestCondition)2 RequestConditionHolder (org.springframework.web.servlet.mvc.condition.RequestConditionHolder)2 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)1 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)1 AnnotationUtils (org.springframework.core.annotation.AnnotationUtils)1 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)1 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)1 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)1