Search in sources :

Example 6 with PatternsRequestCondition

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

the class SiteRequestCondition method compareTo.

@Override
public int compareTo(SiteRequestCondition that, HttpServletRequest request) {
    PatternsRequestCondition thisCondition = this.resolve(request);
    PatternsRequestCondition thatCondition = that.resolve(request);
    return thisCondition == null && thatCondition == null ? 0 : thisCondition == null ? 1 : thatCondition == null ? -1 : thisCondition.compareTo(thatCondition, request);
}
Also used : PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition)

Example 7 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)

Example 8 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition in project spring-boot-admin by codecentric.

the class PrefixHandlerMapping method withPrefix.

private RequestMappingInfo withPrefix(RequestMappingInfo mapping) {
    List<String> newPatterns = getPatterns(mapping);
    PatternsRequestCondition patterns = new PatternsRequestCondition(newPatterns.toArray(new String[newPatterns.size()]));
    return new RequestMappingInfo(patterns, mapping.getMethodsCondition(), mapping.getParamsCondition(), mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(), mapping.getCustomCondition());
}
Also used : PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo)

Example 9 with PatternsRequestCondition

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

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition in project hub-alert by blackducksoftware.

the class ExposedEndpointsControllerTest method getTest.

@Test
public void getTest() {
    final RequestMappingHandlerMapping handlerMapping = Mockito.mock(RequestMappingHandlerMapping.class);
    final ExposedEndpointsController controller = new ExposedEndpointsController(handlerMapping);
    final String endpoint1 = "/api/test";
    final String endpoint2 = "/api/other/test";
    final Set<RequestMethod> expectedSet = new HashSet<>(Arrays.asList(RequestMethod.GET, RequestMethod.POST));
    final Map<RequestMappingInfo, HandlerMethod> handlerMethods = new HashMap<>();
    final RequestMappingInfo info = new RequestMappingInfo(new PatternsRequestCondition(endpoint1, endpoint2), new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST), null, null, null, null, null);
    handlerMethods.put(info, null);
    Mockito.when(handlerMapping.getHandlerMethods()).thenReturn(handlerMethods);
    final Map<String, Set<RequestMethod>> mappings = controller.get();
    assertEquals(mappings.get(endpoint1), expectedSet);
}
Also used : PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) Set(java.util.Set) HashSet(java.util.HashSet) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) HashMap(java.util.HashMap) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) HashSet(java.util.HashSet) Test(org.junit.Test)

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 ExtensiveDomainRequestCondition (io.leopard.web.mvc.condition.ExtensiveDomainRequestCondition)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