Search in sources :

Example 1 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition 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 2 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition 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 3 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition in project leopard by tanhaichao.

the class LeopardHandlerMapping method createRequestMappingInfo2.

/**
 * Created a RequestMappingInfo from a RequestMapping annotation.
 */
protected RequestMappingInfo createRequestMappingInfo2(RequestMapping annotation, Method method) {
    String[] patterns;
    if (method != null && annotation.value().length == 0) {
        patterns = new String[] { this.createPattern(method.getName()) };
    } else {
        patterns = resolveEmbeddedValuesInPatterns(annotation.value());
    }
    Map<String, String> headerMap = new LinkedHashMap<String, String>();
    ExtensiveDomain extensiveDomain = new ExtensiveDomain();
    requestMappingInfoBuilder.getHeaders(annotation, method, extensiveDomain, headerMap);
    // System.out.println("headerMap:" + headerMap);
    String[] headers = new String[headerMap.size()];
    {
        int i = 0;
        for (Entry<String, String> entry : headerMap.entrySet()) {
            String header = entry.getKey() + "=" + entry.getValue();
            headers[i] = header;
            i++;
        }
    }
    RequestCondition<?> customCondition = new ServerNameRequestCondition(extensiveDomain, headers);
    return new RequestMappingInfo(new PatternsRequestCondition(patterns, getUrlPathHelper(), getPathMatcher(), false, this.useTrailingSlashMatch(), this.getFileExtensions()), new RequestMethodsRequestCondition(annotation.method()), new ParamsRequestCondition(annotation.params()), new HeadersRequestCondition(), new ConsumesRequestCondition(annotation.consumes(), headers), new ProducesRequestCondition(annotation.produces(), headers, getContentNegotiationManager()), customCondition);
}
Also used : ServerNameRequestCondition(io.leopard.web.mvc.condition.ServerNameRequestCondition) ParamsRequestCondition(org.springframework.web.servlet.mvc.condition.ParamsRequestCondition) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) LinkedHashMap(java.util.LinkedHashMap) ExtensiveDomain(io.leopard.vhost.ExtensiveDomain) Entry(java.util.Map.Entry) ProducesRequestCondition(org.springframework.web.servlet.mvc.condition.ProducesRequestCondition) 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 4 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition in project wombat by PLOS.

the class SiteHandlerMapping method createRequestMappingInfo.

private RequestMappingInfo createRequestMappingInfo(RequestMappingContext mapping, RequestCondition<?> customCondition) {
    Set<String> allPatterns = SiteRequestCondition.getAllPatterns(siteSet, mapping);
    RequestMapping annotation = mapping.getAnnotation();
    String[] embeddedPatterns = resolveEmbeddedValuesInPatterns(allPatterns.toArray(new String[allPatterns.size()]));
    return new RequestMappingInfo(annotation.name(), new PatternsRequestCondition(embeddedPatterns, null, null, true, true, null), 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), customCondition);
}
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) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) HeadersRequestCondition(org.springframework.web.servlet.mvc.condition.HeadersRequestCondition) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) ConsumesRequestCondition(org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition in project wombat by PLOS.

the class SiteRequestCondition method create.

/**
 * Create a condition, representing all sites, for a single request handler.
 * <p>
 * Writes to the {@link RequestMappingContextDictionary} object as a side effect. To avoid redundant writes, this
 * method must be called only once per {@link RequestMapping} object.
 *
 * @param siteResolver                    the global site resolver
 * @param siteSet                         the set of all sites in the system
 * @param controllerMethod                the method annotated with the request handler
 * @param requestMappingContextDictionary the global handler directory, which must be in a writable state
 * @return the new condition object
 */
public static SiteRequestCondition create(SiteResolver siteResolver, SiteSet siteSet, Method controllerMethod, RequestMappingContextDictionary requestMappingContextDictionary) {
    RequestMappingContext baseMapping = RequestMappingContext.create(controllerMethod);
    if (baseMapping.isSiteless()) {
        PatternsRequestCondition patternsRequestCondition = new PatternsRequestCondition(baseMapping.getPattern());
        requestMappingContextDictionary.registerGlobalMapping(baseMapping);
        return forSiteless(patternsRequestCondition);
    }
    Multimap<RequestMappingContext, Site> patternMap = buildPatternMap(siteSet, baseMapping);
    ImmutableMap.Builder<Site, PatternsRequestCondition> requestConditionMap = ImmutableMap.builder();
    for (Map.Entry<RequestMappingContext, Collection<Site>> entry : patternMap.asMap().entrySet()) {
        RequestMappingContext mapping = entry.getKey();
        // all sites that share the mapping pattern
        Collection<Site> sites = entry.getValue();
        PatternsRequestCondition condition = new PatternsRequestCondition(mapping.getPattern());
        for (Site site : sites) {
            requestConditionMap.put(site, condition);
            if (!mapping.getAnnotation().name().isEmpty()) {
                requestMappingContextDictionary.registerSiteMapping(mapping, site);
            }
        }
    }
    return forSiteMap(siteResolver, requestConditionMap.build());
}
Also used : PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) Collection(java.util.Collection) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

PatternsRequestCondition (org.springframework.web.servlet.mvc.condition.PatternsRequestCondition)11 RequestMethodsRequestCondition (org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition)6 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)6 ParamsRequestCondition (org.springframework.web.servlet.mvc.condition.ParamsRequestCondition)5 ConsumesRequestCondition (org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition)4 HeadersRequestCondition (org.springframework.web.servlet.mvc.condition.HeadersRequestCondition)4 ProducesRequestCondition (org.springframework.web.servlet.mvc.condition.ProducesRequestCondition)4 HashSet (java.util.HashSet)2 Set (java.util.Set)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2 RequestConditionHolder (org.springframework.web.servlet.mvc.condition.RequestConditionHolder)2 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ExtensiveDomain (io.leopard.vhost.ExtensiveDomain)1 ServerNameRequestCondition (io.leopard.web.mvc.condition.ServerNameRequestCondition)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1