org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition Java Examples

The following examples show how to use org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition. 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: CrossOriginTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
				new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
				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);
	}
	else {
		return null;
	}
}
 
Example #2
Source File: RbacAuthorityService.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取 所有URL Mapping,返回格式为{"/test":["GET","POST"],"/sys":["GET","DELETE"]}
 *
 * @return {@link ArrayListMultimap} 格式的 URL Mapping
 */
private Multimap<String, String> allUrlMapping() {
    Multimap<String, String> urlMapping = ArrayListMultimap.create();

    // 获取url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();

    handlerMethods.forEach((k, v) -> {
        // 获取当前 key 下的获取所有URL
        Set<String> url = k.getPatternsCondition()
                .getPatterns();
        RequestMethodsRequestCondition method = k.getMethodsCondition();

        // 为每个URL添加所有的请求方法
        url.forEach(s -> urlMapping.putAll(s, method.getMethods()
                .stream()
                .map(Enum::toString)
                .collect(Collectors.toList())));
    });

    return urlMapping;
}
 
Example #3
Source File: RequestMappingInfoHandlerMappingTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
			new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
			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);
	}
	else {
		return null;
	}
}
 
Example #4
Source File: RequestMappingInfoTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void preFlightRequest() {
	MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/foo");
	request.addHeader(HttpHeaders.ORIGIN, "http://domain.com");
	request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST");

	RequestMappingInfo info = new RequestMappingInfo(
			new PatternsRequestCondition("/foo"), new RequestMethodsRequestCondition(RequestMethod.POST), null,
			null, null, null, null);
	RequestMappingInfo match = info.getMatchingCondition(request);
	assertNotNull(match);

	info = new RequestMappingInfo(
			new PatternsRequestCondition("/foo"), new RequestMethodsRequestCondition(RequestMethod.OPTIONS), null,
			null, null, null, null);
	match = info.getMatchingCondition(request);
	assertNotNull(match);
}
 
Example #5
Source File: RequestMappingInfoTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void compareTwoHttpMethodsOneParam() {
	RequestMappingInfo none = new RequestMappingInfo(null, null, null, null, null, null, null);
	RequestMappingInfo oneMethod =
		new RequestMappingInfo(null,
				new RequestMethodsRequestCondition(RequestMethod.GET), null, null, null, null, null);
	RequestMappingInfo oneMethodOneParam =
			new RequestMappingInfo(null,
					new RequestMethodsRequestCondition(RequestMethod.GET),
					new ParamsRequestCondition("foo"), null, null, null, null);

	Comparator<RequestMappingInfo> comparator = new Comparator<RequestMappingInfo>() {
		@Override
		public int compare(RequestMappingInfo info, RequestMappingInfo otherInfo) {
			return info.compareTo(otherInfo, new MockHttpServletRequest());
		}
	};

	List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
	Collections.shuffle(list);
	Collections.sort(list, comparator);

	assertEquals(oneMethodOneParam, list.get(0));
	assertEquals(oneMethod, list.get(1));
	assertEquals(none, list.get(2));
}
 
Example #6
Source File: CrossOriginTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
				new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
				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);
	}
	else {
		return null;
	}
}
 
Example #7
Source File: RequestMappingInfo.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public RequestMappingInfo build() {
	ContentNegotiationManager manager = this.options.getContentNegotiationManager();

	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
			this.paths, this.options.getUrlPathHelper(), this.options.getPathMatcher(),
			this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
			this.options.getFileExtensions());

	return new RequestMappingInfo(this.mappingName, patternsCondition,
			new RequestMethodsRequestCondition(methods),
			new ParamsRequestCondition(this.params),
			new HeadersRequestCondition(this.headers),
			new ConsumesRequestCondition(this.consumes, this.headers),
			new ProducesRequestCondition(this.produces, this.headers, manager),
			this.customCondition);
}
 
Example #8
Source File: RbacAuthorityService.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取 所有URL Mapping,返回格式为{"/test":["GET","POST"],"/sys":["GET","DELETE"]}
 *
 * @return {@link ArrayListMultimap} 格式的 URL Mapping
 */
private Multimap<String, String> allUrlMapping() {
    Multimap<String, String> urlMapping = ArrayListMultimap.create();

    // 获取url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();

    handlerMethods.forEach((k, v) -> {
        // 获取当前 key 下的获取所有URL
        Set<String> url = k.getPatternsCondition()
                .getPatterns();
        RequestMethodsRequestCondition method = k.getMethodsCondition();

        // 为每个URL添加所有的请求方法
        url.forEach(s -> urlMapping.putAll(s, method.getMethods()
                .stream()
                .map(Enum::toString)
                .collect(Collectors.toList())));
    });

    return urlMapping;
}
 
Example #9
Source File: RequestMappingInfo.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RequestMappingInfo build() {
	ContentNegotiationManager manager = this.options.getContentNegotiationManager();

	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
			this.paths, this.options.getUrlPathHelper(), this.options.getPathMatcher(),
			this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
			this.options.getFileExtensions());

	return new RequestMappingInfo(this.mappingName, patternsCondition,
			new RequestMethodsRequestCondition(methods),
			new ParamsRequestCondition(this.params),
			new HeadersRequestCondition(this.headers),
			new ConsumesRequestCondition(this.consumes, this.headers),
			new ProducesRequestCondition(this.produces, this.headers, manager),
			this.customCondition);
}
 
Example #10
Source File: RequestMappingInfo.java    From lams with GNU General Public License v2.0 6 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
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());
}
 
Example #11
Source File: ExposedEndpointsControllerTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void getTest() {
    RequestMappingHandlerMapping handlerMapping = Mockito.mock(RequestMappingHandlerMapping.class);
    ExposedEndpointsController controller = new ExposedEndpointsController(new Gson(), handlerMapping);

    String endpoint1 = "/api/test";
    String endpoint2 = "/api/other/test";

    Map<RequestMappingInfo, HandlerMethod> handlerMethods = new HashMap<>();
    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);

    ResponseEntity<String> responseEntity = controller.get();
    Assertions.assertTrue(StringUtils.isNotBlank(responseEntity.getBody()), "Expected the response body to contain json");
}
 
Example #12
Source File: RequestMappingMethodHandlerMapping.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
protected RequestMappingInfo createRequestMappingInfoByApiMethodAnno(RequestMapping requestMapping, RequestCondition<?> customCondition,
                                                                     Method method) {
    String[] patterns = resolveEmbeddedValuesInPatterns(requestMapping.value());
    if (!method.isAnnotationPresent(RequestMapping.class) || CollectionUtil.isEmpty(patterns)) {
        RequestMappingResolveResult methodParsered = RequestMappingResolver.resolveOwnPath(method);
        String path = methodParsered.getPath();
        patterns = new String[] { path };
    }

    return new RequestMappingInfo(
        new PatternsRequestCondition(patterns, getUrlPathHelper(), getPathMatcher(), this.useSuffixPatternMatch, this.useTrailingSlashMatch,
            this.fileExtensions),
        new RequestMethodsRequestCondition(requestMapping.method()), new ParamsRequestCondition(requestMapping.params()),
        new HeadersRequestCondition(requestMapping.headers()), new ConsumesRequestCondition(requestMapping.consumes(), requestMapping.headers()),
        new ProducesRequestCondition(requestMapping.produces(), requestMapping.headers(), this.contentNegotiationManager), customCondition);
}
 
Example #13
Source File: RequestMappingService.java    From api-mock-util with Apache License 2.0 6 votes vote down vote up
public boolean unregisterApi(String index,String api,String requestMethod){
    check(hasApiRegistered(api,requestMethod),"该api未注册过");

    RequestMappingHandlerMapping requestMappingHandlerMapping = webApplicationContext.getBean(RequestMappingHandlerMapping.class);
    Method targetMethod = ReflectionUtils.findMethod(ApiController.class, getHandlerMethodName(index));

    PatternsRequestCondition patternsRequestCondition = new PatternsRequestCondition(api);
    RequestMethodsRequestCondition requestMethodsRequestCondition = new RequestMethodsRequestCondition(getRequestMethod(requestMethod));
    RequestMappingInfo mapping_info = new RequestMappingInfo(patternsRequestCondition, requestMethodsRequestCondition, null, null, null, null, null);

    requestMappingHandlerMapping.unregisterMapping(mapping_info); // 注销

    if(Constants.requestMappings.containsKey(index)){
        Constants.requestMappings.remove(index);
    }

    return true;
}
 
Example #14
Source File: RequestMappingService.java    From api-mock-util with Apache License 2.0 6 votes vote down vote up
public ApiBean registerApi(String index,String api,String requestMethod,String msg){
    check(!hasMethodOccupied(index),"该序号已经被占用,请先注销api。");
    check(!hasApiRegistered(api,requestMethod),"该api已经注册过了");

    RequestMappingHandlerMapping requestMappingHandlerMapping = webApplicationContext.getBean(RequestMappingHandlerMapping.class);
    Method targetMethod = ReflectionUtils.findMethod(ApiController.class, getHandlerMethodName(index)); // 找到处理该路由的方法

    PatternsRequestCondition patternsRequestCondition = new PatternsRequestCondition(api);
    RequestMethodsRequestCondition requestMethodsRequestCondition = new RequestMethodsRequestCondition(getRequestMethod(requestMethod));

    RequestMappingInfo mapping_info = new RequestMappingInfo(patternsRequestCondition, requestMethodsRequestCondition, null, null, null, null, null);
    requestMappingHandlerMapping.registerMapping(mapping_info, "apiController", targetMethod); // 注册映射处理

    // 保存注册信息到本地
    ApiBean apiInfo = new ApiBean();
    apiInfo.setApi(api);
    apiInfo.setRequestMethod(requestMethod);
    apiInfo.setMsg(msg);
    Constants.requestMappings.put(index,apiInfo);

    return apiInfo;
}
 
Example #15
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annot = AnnotationUtils.findAnnotation(method, RequestMapping.class);
	if (annot != null) {
		return new RequestMappingInfo(
			new PatternsRequestCondition(annot.value(), getUrlPathHelper(), getPathMatcher(), true, true),
			new RequestMethodsRequestCondition(annot.method()),
			new ParamsRequestCondition(annot.params()),
			new HeadersRequestCondition(annot.headers()),
			new ConsumesRequestCondition(annot.consumes(), annot.headers()),
			new ProducesRequestCondition(annot.produces(), annot.headers()), null);
	}
	else {
		return null;
	}
}
 
Example #16
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public RequestMappingInfo build() {
	ContentNegotiationManager manager = this.options.getContentNegotiationManager();

	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
			this.paths, this.options.getUrlPathHelper(), this.options.getPathMatcher(),
			this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
			this.options.getFileExtensions());

	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, manager),
			this.customCondition);
}
 
Example #17
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public RequestMappingInfo build() {
	ContentNegotiationManager manager = this.options.getContentNegotiationManager();

	PatternsRequestCondition patternsCondition = new PatternsRequestCondition(
			this.paths, this.options.getUrlPathHelper(), this.options.getPathMatcher(),
			this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(),
			this.options.getFileExtensions());

	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, manager),
			this.customCondition);
}
 
Example #18
Source File: RequestMappingInfoHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annot = AnnotationUtils.findAnnotation(method, RequestMapping.class);
	if (annot != null) {
		return new RequestMappingInfo(
			new PatternsRequestCondition(annot.value(), getUrlPathHelper(), getPathMatcher(), true, true),
			new RequestMethodsRequestCondition(annot.method()),
			new ParamsRequestCondition(annot.params()),
			new HeadersRequestCondition(annot.headers()),
			new ConsumesRequestCondition(annot.consumes(), annot.headers()),
			new ProducesRequestCondition(annot.produces(), annot.headers()), null);
	}
	else {
		return null;
	}
}
 
Example #19
Source File: RbacAuthorityService.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取 所有URL Mapping,返回格式为{"/test":["GET","POST"],"/sys":["GET","DELETE"]}
 *
 * @return {@link ArrayListMultimap} 格式的 URL Mapping
 */
private Multimap<String, String> allUrlMapping() {
    Multimap<String, String> urlMapping = ArrayListMultimap.create();

    // 获取url与类和方法的对应信息
    Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();

    handlerMethods.forEach((k, v) -> {
        // 获取当前 key 下的获取所有URL
        Set<String> url = k.getPatternsCondition()
                .getPatterns();
        RequestMethodsRequestCondition method = k.getMethodsCondition();

        // 为每个URL添加所有的请求方法
        url.forEach(s -> urlMapping.putAll(s, method.getMethods()
                .stream()
                .map(Enum::toString)
                .collect(Collectors.toList())));
    });

    return urlMapping;
}
 
Example #20
Source File: CrossOriginTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
	RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
	if (annotation != null) {
		return new RequestMappingInfo(
				new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true),
				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);
	}
	else {
		return null;
	}
}
 
Example #21
Source File: RequestMappingInfo.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public RequestMappingInfo(String name, PatternsRequestCondition patterns, RequestMethodsRequestCondition methods,
		ParamsRequestCondition params, HeadersRequestCondition headers, ConsumesRequestCondition consumes,
		ProducesRequestCondition produces, 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 #22
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 #23
Source File: RequestMappingInfo.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Combine "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 #24
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(HttpServletRequest request) {
	RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
	if (methods == null) {
		return null;
	}
	ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
	if (params == null) {
		return null;
	}
	HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
	if (headers == null) {
		return null;
	}
	ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
	if (consumes == null) {
		return null;
	}
	ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
	if (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());
}
 
Example #25
Source File: RequestMappingInfo.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return a matching RequestMethodsRequestCondition based on the expected
 * HTTP method specified in a CORS pre-flight request.
 */
private RequestMethodsRequestCondition getAccessControlRequestMethodCondition(HttpServletRequest request) {
	String expectedMethod = request.getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD);
	if (StringUtils.hasText(expectedMethod)) {
		for (RequestMethod method : getMethodsCondition().getMethods()) {
			if (expectedMethod.equalsIgnoreCase(method.name())) {
				return new RequestMethodsRequestCondition(method);
			}
		}
	}
	return null;
}
 
Example #26
Source File: RequestMappingInfo.java    From spring4-understanding with Apache License 2.0 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
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) {
		if (CorsUtils.isPreFlightRequest(request)) {
			methods = getAccessControlRequestMethodCondition(request);
			if (methods == null || params == null) {
				return null;
			}
		}
		else {
			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());
}
 
Example #27
Source File: RequestMappingInfo.java    From spring4-understanding with Apache License 2.0 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 #28
Source File: RequestMappingInfo.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance with the given request conditions.
 */
public RequestMappingInfo(PatternsRequestCondition patterns, RequestMethodsRequestCondition methods,
		ParamsRequestCondition params, HeadersRequestCondition headers, ConsumesRequestCondition consumes,
		ProducesRequestCondition produces, RequestCondition<?> custom) {

	this(null, patterns, methods, params, headers, consumes, produces, custom);
}
 
Example #29
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(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());
}
 
Example #30
Source File: RequestMappingInfo.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Combine "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());
}