Search in sources :

Example 1 with ProducesRequestCondition

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

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);
}
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 3 with ProducesRequestCondition

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);
}
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 4 with ProducesRequestCondition

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

Aggregations

ConsumesRequestCondition (org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition)4 HeadersRequestCondition (org.springframework.web.servlet.mvc.condition.HeadersRequestCondition)4 ParamsRequestCondition (org.springframework.web.servlet.mvc.condition.ParamsRequestCondition)4 PatternsRequestCondition (org.springframework.web.servlet.mvc.condition.PatternsRequestCondition)4 ProducesRequestCondition (org.springframework.web.servlet.mvc.condition.ProducesRequestCondition)4 RequestMethodsRequestCondition (org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition)4 RequestConditionHolder (org.springframework.web.servlet.mvc.condition.RequestConditionHolder)2 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)2 ExtensiveDomain (io.leopard.vhost.ExtensiveDomain)1 ServerNameRequestCondition (io.leopard.web.mvc.condition.ServerNameRequestCondition)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1