use of org.springframework.web.servlet.mvc.condition.ProducesRequestCondition 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.ProducesRequestCondition 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.ProducesRequestCondition 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.ProducesRequestCondition 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());
}
Aggregations