org.springframework.web.bind.annotation.RequestMapping#headers ( )源码实例Demo

下面列出了org.springframework.web.bind.annotation.RequestMapping#headers ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring-analysis-note   文件: CrossOriginTests.java
@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;
	}
}
 
@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;
	}
}
 
源代码3 项目: java-technology-stack   文件: CrossOriginTests.java
@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;
	}
}
 
@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;
	}
}
 
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);
}
 
源代码6 项目: lams   文件: AnnotationMethodHandlerAdapter.java
@Override
protected boolean isHandlerMethod(Method method) {
	if (this.mappings.containsKey(method)) {
		return true;
	}
	RequestMapping mapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
	if (mapping != null) {
		String[] patterns = mapping.value();
		RequestMethod[] methods = new RequestMethod[0];
		String[] params = new String[0];
		String[] headers = new String[0];
		if (!hasTypeLevelMapping() || !Arrays.equals(mapping.method(), getTypeLevelMapping().method())) {
			methods = mapping.method();
		}
		if (!hasTypeLevelMapping() || !Arrays.equals(mapping.params(), getTypeLevelMapping().params())) {
			params = mapping.params();
		}
		if (!hasTypeLevelMapping() || !Arrays.equals(mapping.headers(), getTypeLevelMapping().headers())) {
			headers = mapping.headers();
		}
		RequestMappingInfo mappingInfo = new RequestMappingInfo(patterns, methods, params, headers);
		this.mappings.put(method, mappingInfo);
		return true;
	}
	return false;
}
 
源代码7 项目: lams   文件: DefaultAnnotationHandlerMapping.java
/**
 * Validate the given type-level mapping metadata against the current request,
 * checking HTTP request method and parameter conditions.
 * @param mapping the mapping metadata to validate
 * @param request current HTTP request
 * @throws Exception if validation failed
 */
protected void validateMapping(RequestMapping mapping, HttpServletRequest request) throws Exception {
	RequestMethod[] mappedMethods = mapping.method();
	if (!ServletAnnotationMappingUtils.checkRequestMethod(mappedMethods, request)) {
		String[] supportedMethods = new String[mappedMethods.length];
		for (int i = 0; i < mappedMethods.length; i++) {
			supportedMethods[i] = mappedMethods[i].name();
		}
		throw new HttpRequestMethodNotSupportedException(request.getMethod(), supportedMethods);
	}

	String[] mappedParams = mapping.params();
	if (!ServletAnnotationMappingUtils.checkParameters(mappedParams, request)) {
		throw new UnsatisfiedServletRequestParameterException(mappedParams, request.getParameterMap());
	}

	String[] mappedHeaders = mapping.headers();
	if (!ServletAnnotationMappingUtils.checkHeaders(mappedHeaders, request)) {
		throw new ServletRequestBindingException("Header conditions \"" +
				StringUtils.arrayToDelimitedString(mappedHeaders, ", ") +
				"\" not met for actual request");
	}
}
 
@Override
protected boolean isHandlerMethod(Method method) {
	if (this.mappings.containsKey(method)) {
		return true;
	}
	RequestMapping mapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
	if (mapping != null) {
		String[] patterns = mapping.value();
		RequestMethod[] methods = new RequestMethod[0];
		String[] params = new String[0];
		String[] headers = new String[0];
		if (!hasTypeLevelMapping() || !Arrays.equals(mapping.method(), getTypeLevelMapping().method())) {
			methods = mapping.method();
		}
		if (!hasTypeLevelMapping() || !Arrays.equals(mapping.params(), getTypeLevelMapping().params())) {
			params = mapping.params();
		}
		if (!hasTypeLevelMapping() || !Arrays.equals(mapping.headers(), getTypeLevelMapping().headers())) {
			headers = mapping.headers();
		}
		RequestMappingInfo mappingInfo = new RequestMappingInfo(patterns, methods, params, headers);
		this.mappings.put(method, mappingInfo);
		return true;
	}
	return false;
}
 
/**
 * Validate the given type-level mapping metadata against the current request,
 * checking HTTP request method and parameter conditions.
 * @param mapping the mapping metadata to validate
 * @param request current HTTP request
 * @throws Exception if validation failed
 */
protected void validateMapping(RequestMapping mapping, HttpServletRequest request) throws Exception {
	RequestMethod[] mappedMethods = mapping.method();
	if (!ServletAnnotationMappingUtils.checkRequestMethod(mappedMethods, request)) {
		String[] supportedMethods = new String[mappedMethods.length];
		for (int i = 0; i < mappedMethods.length; i++) {
			supportedMethods[i] = mappedMethods[i].name();
		}
		throw new HttpRequestMethodNotSupportedException(request.getMethod(), supportedMethods);
	}

	String[] mappedParams = mapping.params();
	if (!ServletAnnotationMappingUtils.checkParameters(mappedParams, request)) {
		throw new UnsatisfiedServletRequestParameterException(mappedParams, request.getParameterMap());
	}

	String[] mappedHeaders = mapping.headers();
	if (!ServletAnnotationMappingUtils.checkHeaders(mappedHeaders, request)) {
		throw new ServletRequestBindingException("Header conditions \"" +
				StringUtils.arrayToDelimitedString(mappedHeaders, ", ") +
				"\" not met for actual request");
	}
}
 
源代码10 项目: spring4-understanding   文件: CrossOriginTests.java
@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;
	}
}
 
@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;
	}
}
 
protected void parseHeaders(MethodMetadata md, Method method, RequestMapping annotation) {

        if (annotation.headers() != null && annotation.headers().length > 0) {
            for (String header : annotation.headers()) {
                int index = header.indexOf('=');
                if (!header.contains("!=") && index >= 0) {
                    md.template().header(resolve(header.substring(0, index)),
                        resolve(header.substring(index + 1).trim()));
                }
            }
        }
    }
 
源代码13 项目: spring-cloud-openfeign   文件: SpringMvcContract.java
private void parseHeaders(MethodMetadata md, Method method,
		RequestMapping annotation) {
	// TODO: only supports one header value per key
	if (annotation.headers() != null && annotation.headers().length > 0) {
		for (String header : annotation.headers()) {
			int index = header.indexOf('=');
			if (!header.contains("!=") && index >= 0) {
				md.template().header(resolve(header.substring(0, index)),
						resolve(header.substring(index + 1).trim()));
			}
		}
	}
}
 
源代码14 项目: raptor   文件: SpringMvcContract.java
private void parseHeaders(MethodMetadata md, Method method,
                          RequestMapping annotation) {
    // TODO: only supports one header value per key
    if (annotation.headers() != null && annotation.headers().length > 0) {
        for (String header : annotation.headers()) {
            int index = header.indexOf('=');
            if (!header.contains("!=") && index >= 0) {
                md.template().header(resolve(header.substring(0, index)),
                        resolve(header.substring(index + 1).trim()));
            }
        }
    }
}
 
源代码15 项目: venus-cloud-feign   文件: VenusSpringMvcContract.java
private void parseHeaders(MethodMetadata md, Method method,
                          RequestMapping annotation) {
    // TODO: only supports one header value per key
    if (annotation.headers() != null && annotation.headers().length > 0) {
        for (String header : annotation.headers()) {
            int index = header.indexOf('=');
            if (!header.contains("!=") && index >= 0) {
                md.template().header(resolve(header.substring(0, index)),
                        resolve(header.substring(index + 1).trim()));
            }
        }
    }
}
 
/**
 * Register all handlers specified in the Portlet mode map for the corresponding modes.
 * @throws org.springframework.beans.BeansException if the handler couldn't be registered
 */
protected void detectHandlers() throws BeansException {
	ApplicationContext context = getApplicationContext();
	String[] beanNames = context.getBeanNamesForType(Object.class);
	for (String beanName : beanNames) {
		Class<?> handlerType = context.getType(beanName);
		RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
		if (mapping != null) {
			// @RequestMapping found at type level
			String[] modeKeys = mapping.value();
			String[] params = mapping.params();
			boolean registerHandlerType = true;
			if (modeKeys.length == 0 || params.length == 0) {
				registerHandlerType = !detectHandlerMethods(handlerType, beanName, mapping);
			}
			if (registerHandlerType) {
				AbstractParameterMappingPredicate predicate = new TypeLevelMappingPredicate(
						params, mapping.headers(), mapping.method());
				for (String modeKey : modeKeys) {
					registerHandler(new PortletMode(modeKey), beanName, predicate);
				}
			}
		}
		else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) {
			detectHandlerMethods(handlerType, beanName, mapping);
		}
	}
}