cc.shacocloud.mirage.web.bind.support.RequestHeaderMethodArgumentResolver Maven / Gradle / Ivy
package cc.shacocloud.mirage.web.bind.support;
import cc.shacocloud.mirage.utils.Utils;
import cc.shacocloud.mirage.web.HttpRequest;
import cc.shacocloud.mirage.web.bind.annotation.RequestHeader;
import cc.shacocloud.mirage.web.http.HttpHeaderMap;
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import org.springframework.core.MethodParameter;
import java.util.List;
/**
* 解析{@link RequestHeader} 注解的方法参数。
*
* 支持三种方法参数定义类型:
*
MultiMap类型,即当前请求的所有请求头{@link HttpHeaderMap}
* List类型,即当前请求头指定名称的所有值
* 其他,即当前请求头指定名称的第一个值
*/
public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(RequestHeader.class);
}
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
RequestHeader ann = parameter.getParameterAnnotation(RequestHeader.class);
if (ann != null) return new HeaderNamedValueInfo(ann);
throw new IllegalStateException("不支持处理当前方法,请先执行 supportsParameter 方法进行判断:" + Utils.methodDescription(parameter.getDeclaringClass(), parameter.getMethod()));
}
@Override
protected String resolveStringValue(String value) {
return value;
}
@Override
protected Future
© 2015 - 2025 Weber Informatics LLC | Privacy Policy