org.springframework.web.reactive.result.condition.PatternsRequestCondition Java Examples

The following examples show how to use org.springframework.web.reactive.result.condition.PatternsRequestCondition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public RequestMappingInfo build() {
	RequestedContentTypeResolver contentTypeResolver = this.options.getContentTypeResolver();

	PathPatternParser parser = (this.options.getPatternParser() != null ?
			this.options.getPatternParser() : new PathPatternParser());
	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(parse(this.paths, parser));

	return new RequestMappingInfo(this.mappingName, patternsCondition,
			new RequestMethodsRequestCondition(this.methods),
			new ParamsRequestCondition(this.params),
			new HeadersRequestCondition(this.headers),
			new ConsumesRequestCondition(this.consumes, this.headers),
			new ProducesRequestCondition(this.produces, this.headers, contentTypeResolver),
			this.customCondition);
}
 
Example #2
Source File: OpenApiResource.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate path.
 *
 * @param restControllers the rest controllers
 * @param map the map
 */
protected void calculatePath(Map<String, Object> restControllers, Map<RequestMappingInfo, HandlerMethod> map) {
	for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) {
		RequestMappingInfo requestMappingInfo = entry.getKey();
		HandlerMethod handlerMethod = entry.getValue();
		PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
		Set<PathPattern> patterns = patternsRequestCondition.getPatterns();
		for (PathPattern pathPattern : patterns) {
			String operationPath = pathPattern.getPatternString();
			Map<String, String> regexMap = new LinkedHashMap<>();
			operationPath = PathUtils.parsePath(operationPath, regexMap);
			if (operationPath.startsWith(DEFAULT_PATH_SEPARATOR)
					&& (restControllers.containsKey(handlerMethod.getBean().toString()) || actuatorProvider.isPresent())
					&& isPackageToScan(handlerMethod.getBeanType().getPackage()) && isPathToMatch(operationPath)) {
				Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
				// default allowed requestmethods
				if (requestMethods.isEmpty())
					requestMethods = this.getDefaultAllowedHttpMethods();
				calculatePath(handlerMethod, operationPath, requestMethods);
			}
		}
	}
}
 
Example #3
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public RequestMappingInfo build() {
	RequestedContentTypeResolver contentTypeResolver = this.options.getContentTypeResolver();

	PathPatternParser parser = (this.options.getPatternParser() != null ?
			this.options.getPatternParser() : new PathPatternParser());
	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(parse(this.paths, parser));

	return new RequestMappingInfo(this.mappingName, patternsCondition,
			new RequestMethodsRequestCondition(this.methods),
			new ParamsRequestCondition(this.params),
			new HeadersRequestCondition(this.headers),
			new ConsumesRequestCondition(this.consumes, this.headers),
			new ProducesRequestCondition(this.produces, this.headers, contentTypeResolver),
			this.customCondition);
}
 
Example #4
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
		@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
		@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,
		@Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) {

	this.name = (StringUtils.hasText(name) ? name : null);
	this.patternsCondition = (patterns != null ? patterns : new PatternsRequestCondition());
	this.methodsCondition = (methods != null ? methods : new RequestMethodsRequestCondition());
	this.paramsCondition = (params != null ? params : new ParamsRequestCondition());
	this.headersCondition = (headers != null ? headers : new HeadersRequestCondition());
	this.consumesCondition = (consumes != null ? consumes : new ConsumesRequestCondition());
	this.producesCondition = (produces != null ? produces : new ProducesRequestCondition());
	this.customConditionHolder = new RequestConditionHolder(custom);
}
 
Example #5
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Creates a new instance with the given request conditions.
 */
public RequestMappingInfo(@Nullable PatternsRequestCondition patterns,
		@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
		@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,
		@Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) {

	this(null, patterns, methods, params, headers, consumes, produces, custom);
}
 
Example #6
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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());
}
 
Example #7
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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
@Nullable
public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
	RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange);
	if (methods == null) {
		return null;
	}
	ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
	if (params == null) {
		return null;
	}
	HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange);
	if (headers == null) {
		return null;
	}
	// Match "Content-Type" and "Accept" (parsed ones and cached) before patterns
	ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
	if (consumes == null) {
		return null;
	}
	ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);
	if (produces == null) {
		return null;
	}
	PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
	if (patterns == null) {
		return null;
	}
	RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange);
	if (custom == null) {
		return null;
	}
	return new RequestMappingInfo(this.name, patterns,
			methods, params, headers, consumes, produces, custom.getCondition());
}
 
Example #8
Source File: RequestMappingHandlerMappingTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test // gh-22010
public void consumesWithOptionalRequestBody() {
	this.wac.registerSingleton("testController", ComposedAnnotationController.class);
	this.wac.refresh();
	this.handlerMapping.afterPropertiesSet();
	RequestMappingInfo info = this.handlerMapping.getHandlerMethods().keySet().stream()
			.filter(i -> {
				PatternsRequestCondition condition = i.getPatternsCondition();
				return condition.getPatterns().iterator().next().getPatternString().equals("/post");
			})
			.findFirst()
			.orElseThrow(() -> new AssertionError("No /post"));

	assertFalse(info.getConsumesCondition().isBodyRequired());
}
 
Example #9
Source File: AdminControllerHandlerMapping.java    From Moss with Apache License 2.0 5 votes vote down vote up
private RequestMappingInfo withPrefix(RequestMappingInfo mapping) {
    if (!StringUtils.hasText(adminContextPath)) {
        return mapping;
    }
    PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
        withNewPatterns(mapping.getPatternsCondition().getPatterns()));
    return new RequestMappingInfo(patternsCondition, mapping.getMethodsCondition(), mapping.getParamsCondition(),
        mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(),
        mapping.getCustomCondition());
}
 
Example #10
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 5 votes vote down vote up
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
		@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
		@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,
		@Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) {

	this.name = (StringUtils.hasText(name) ? name : null);
	this.patternsCondition = (patterns != null ? patterns : new PatternsRequestCondition());
	this.methodsCondition = (methods != null ? methods : new RequestMethodsRequestCondition());
	this.paramsCondition = (params != null ? params : new ParamsRequestCondition());
	this.headersCondition = (headers != null ? headers : new HeadersRequestCondition());
	this.consumesCondition = (consumes != null ? consumes : new ConsumesRequestCondition());
	this.producesCondition = (produces != null ? produces : new ProducesRequestCondition());
	this.customConditionHolder = new RequestConditionHolder(custom);
}
 
Example #11
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Creates a new instance with the given request conditions.
 */
public RequestMappingInfo(@Nullable PatternsRequestCondition patterns,
		@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
		@Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes,
		@Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) {

	this(null, patterns, methods, params, headers, consumes, produces, custom);
}
 
Example #12
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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());
}
 
Example #13
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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
@Nullable
public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
	RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange);
	ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
	HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange);
	ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
	ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);

	if (methods == null || params == null || headers == null || consumes == null || produces == null) {
		return null;
	}

	PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
	if (patterns == null) {
		return null;
	}

	RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange);
	if (custom == null) {
		return null;
	}

	return new RequestMappingInfo(this.name, patterns,
			methods, params, headers, consumes, produces, custom.getCondition());
}
 
Example #14
Source File: AdminControllerHandlerMapping.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
private RequestMappingInfo withPrefix(RequestMappingInfo mapping) {
	if (!StringUtils.hasText(adminContextPath)) {
		return mapping;
	}
	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
			withNewPatterns(mapping.getPatternsCondition().getPatterns()));
	return new RequestMappingInfo(patternsCondition, mapping.getMethodsCondition(), mapping.getParamsCondition(),
			mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(),
			mapping.getCustomCondition());
}
 
Example #15
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Returns the URL patterns of this {@link RequestMappingInfo};
 * or instance with 0 patterns, never {@code null}.
 */
public PatternsRequestCondition getPatternsCondition() {
	return this.patternsCondition;
}
 
Example #16
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Returns the URL patterns of this {@link RequestMappingInfo};
 * or instance with 0 patterns, never {@code null}.
 */
public PatternsRequestCondition getPatternsCondition() {
	return this.patternsCondition;
}