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;
}
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());
}
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);
}
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);
}
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());
}
Aggregations