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