Java Code Examples for org.springframework.web.bind.annotation.ValueConstants

The following examples show how to use org.springframework.web.bind.annotation.ValueConstants. These examples are extracted from open source projects. 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
@Override
public void process(RequestParam requestParam, ParameterContext parameterContext) {

  parameterContext.setIn(InType.QUERY);
  String name = requestParam.value();
  if (StringUtils.isEmpty(name)) {
    name = requestParam.name();
  }

  parameterContext.setName(name);
  parameterContext.setRequired(requestParam.required());
  if (!ObjectUtils.isEmpty(requestParam.defaultValue()) && !ValueConstants.DEFAULT_NONE
      .equals(requestParam.defaultValue())) {
    parameterContext.setDefaultValue(requestParam.defaultValue());
    parameterContext.setRequired(false);
  }
}
 
Example 2
@Override
public void process(RequestHeader requestHeader, ParameterContext parameterContext) {
  parameterContext.setIn(InType.HEADER);
  parameterContext.setRequired(requestHeader.required());

  if (!ObjectUtils.isEmpty(requestHeader.defaultValue()) && !ValueConstants.DEFAULT_NONE
      .equals(requestHeader.defaultValue())) {
    parameterContext.setDefaultValue(requestHeader.defaultValue());
  }

  String name = requestHeader.name();
  if (StringUtils.isEmpty(name)) {
    name = requestHeader.value();
  }

  parameterContext.setName(name);
}
 
Example 3
Source Project: springdoc-openapi   Source File: AbstractRequestBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Build param parameter.
 *
 * @param parameterInfo the parameter info
 * @param components the components
 * @param requestInfo the request info
 * @param jsonView the json view
 * @return the parameter
 */
private Parameter buildParam(ParameterInfo parameterInfo, Components components, RequestInfo requestInfo,
		JsonView jsonView) {
	Parameter parameter;
	String pName = parameterInfo.getpName();
	String name = StringUtils.isBlank(requestInfo.value()) ? pName : requestInfo.value();
	parameterInfo.setpName(name);

	if (!ValueConstants.DEFAULT_NONE.equals(requestInfo.defaultValue()))
		parameter = this.buildParam(requestInfo.type(), components, parameterInfo, false,
				requestInfo.defaultValue(), jsonView);
	else
		parameter = this.buildParam(requestInfo.type(), components, parameterInfo, requestInfo.required(), null,
				jsonView);
	return parameter;
}
 
Example 4
Source Project: FastBootWeixin   Source File: WxApiParamContributor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
    Class<?> paramType = parameter.getNestedParameterType();
    if (Map.class.isAssignableFrom(paramType)) {
        return;
    }
    WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
    String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
    WxAppAssert.notNull(name, "请添加编译器的-parameter或者为参数添加注解名称");
    if (value == null) {
        if (wxApiParam != null) {
            if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
                return;
            }
        }
        builder.queryParam(name);
    } else if (value instanceof Collection) {
        for (Object element : (Collection<?>) value) {
            element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
            builder.queryParam(name, element);
        }
    } else {
        builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
    }
}
 
Example 5
@Nullable
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext,
		ServerWebExchange exchange) {

	Map<String, MultiValueMap<String, String>> matrixVariables =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(annotation != null, "No MatrixVariable annotation");
	String pathVariable = annotation.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example 6
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with
 * sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.isEmpty()) {
		name = parameter.getParameterName();
		if (name == null) {
			String type = parameter.getNestedParameterType().getName();
			throw new IllegalArgumentException("Name for argument type [" + type + "] not " +
					"available, and parameter name information not found in class file either.");
		}
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
Example 7
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> matrixVariables =
			(Map<String, MultiValueMap<String, String>>) request.getAttribute(
					HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable ann = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVariable = ann.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example 8
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.isEmpty()) {
		name = parameter.getParameterName();
		if (name == null) {
			throw new IllegalArgumentException(
					"Name for argument type [" + parameter.getNestedParameterType().getName() +
					"] not available, and parameter name information not found in class file either.");
		}
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
Example 9
@Override
public void contributeMethodArgument(MethodParameter parameter, @Nullable Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getNestedParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) {
		return;
	}

	RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
	String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ?
			requestParam.name() : parameter.getParameterName());
	Assert.state(name != null, "Unresolvable parameter name");

	parameter = parameter.nestedIfOptional();
	if (value instanceof Optional) {
		value = ((Optional<?>) value).orElse(null);
	}

	if (value == null) {
		if (requestParam != null &&
				(!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) {
			return;
		}
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
Example 10
@Nullable
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext,
		ServerWebExchange exchange) {

	Map<String, MultiValueMap<String, String>> matrixVariables =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(annotation != null, "No MatrixVariable annotation");
	String pathVariable = annotation.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example 11
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with
 * sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.isEmpty()) {
		name = parameter.getParameterName();
		if (name == null) {
			String type = parameter.getNestedParameterType().getName();
			throw new IllegalArgumentException("Name for argument type [" + type + "] not " +
					"available, and parameter name information not found in class file either.");
		}
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
Example 12
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> matrixVariables =
			(Map<String, MultiValueMap<String, String>>) request.getAttribute(
					HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
	MatrixVariable ann = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVariable = ann.pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			vars.forEach((name, values) -> {
				for (String value : values) {
					map.add(name, value);
				}
			});
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example 13
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.isEmpty()) {
		name = parameter.getParameterName();
		if (name == null) {
			throw new IllegalArgumentException(
					"Name for argument type [" + parameter.getNestedParameterType().getName() +
					"] not available, and parameter name information not found in class file either.");
		}
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
Example 14
@Override
public void contributeMethodArgument(MethodParameter parameter, @Nullable Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getNestedParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) {
		return;
	}

	RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
	String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ?
			parameter.getParameterName() : requestParam.name());
	Assert.state(name != null, "Unresolvable parameter name");

	if (value == null) {
		if (requestParam != null &&
				(!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) {
			return;
		}
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
Example 15
Source Project: choerodon-starters   Source File: PropertyJobParam.java    License: Apache License 2.0 5 votes vote down vote up
PropertyJobParam(final JobParam jobParam) {
    this.name = jobParam.name();
    this.type = getParamTypeByClass(jobParam.type()).getValue();
    if (!ValueConstants.DEFAULT_NONE.equals(jobParam.defaultValue())) {
        try {
            this.defaultValue = jobParam.type().getConstructor(String.class).newInstance(jobParam.defaultValue());
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            throw new JobParamDefaultValueParseException(e, jobParam.type(), jobParam.defaultValue());
        }

    }
    this.description = jobParam.description();
}
 
Example 16
@Override
protected String readDefaultValue(ANNOTATION annotation) {
  String defaultValue = pureReadDefaultValue(annotation);
  if (StringUtils.isEmpty(defaultValue) || defaultValue.equals(ValueConstants.DEFAULT_NONE)) {
    return "";
  }
  return defaultValue;
}
 
Example 17
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> matrixVariables =
			(Map<String, MultiValueMap<String, String>>) request.getAttribute(
					HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(matrixVariables)) {
		return Collections.emptyMap();
	}

	MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
	String pathVariable = parameter.getParameterAnnotation(MatrixVariable.class).pathVar();

	if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
		MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
		if (mapForPathVariable == null) {
			return Collections.emptyMap();
		}
		map.putAll(mapForPathVariable);
	}
	else {
		for (MultiValueMap<String, String> vars : matrixVariables.values()) {
			for (String name : vars.keySet()) {
				for (String value : vars.get(name)) {
					map.add(name, value);
				}
			}
		}
	}

	return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
 
Example 18
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.isEmpty()) {
		name = parameter.getParameterName();
		if (name == null) {
			throw new IllegalArgumentException(
					"Name for argument type [" + parameter.getNestedParameterType().getName() +
					"] not available, and parameter name information not found in class file either.");
		}
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
Example 19
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getNestedParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType ||
			"javax.servlet.http.Part".equals(paramType.getName())) {
		return;
	}

	RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
	String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ?
			parameter.getParameterName() : requestParam.name());

	if (value == null) {
		if (requestParam != null) {
			if (!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
				return;
			}
		}
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
Example 20
Source Project: FastBootWeixin   Source File: WxApiMethodInfo.java    License: Apache License 2.0 5 votes vote down vote up
private String getMethodWxApiRequestPath(Method method) {
    WxApiRequest wxApiRequest = AnnotatedElementUtils.findMergedAnnotation(method, WxApiRequest.class);
    if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.path()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.path())) {
        // 默认情况下取方法名为变量名,尝试从环境变量中获取信息
        return WxContextUtils.resolveStringValue("${" + this.wxApiTypeInfo.getPropertyPrefix() + "." + method.getName() + "}");
    }
    return wxApiRequest.path();
}
 
Example 21
Source Project: FastBootWeixin   Source File: WxApiExecutor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 要发送文件,使用这种方式,请查看源码:FormHttpMessageConverter
 *
 * @param wxApiMethodInfo
 * @param args
 * @return the result
 */
private Object getFormBody(WxApiMethodInfo wxApiMethodInfo, Object[] args) {
    MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
    wxApiMethodInfo.getMethodParameters().stream()
            .filter(p -> !BeanUtils.isSimpleValueType(p.getParameterType()) || p.hasParameterAnnotation(WxApiForm.class) || p.hasParameterAnnotation(WxApiBody.class))
            .forEach(p -> {
                // 为空则直接返回不加这个参数
                if (args[p.getParameterIndex()] == null) {
                    return;
                }
                WxApiForm wxApiForm = p.getParameterAnnotation(WxApiForm.class);
                String paramName;
                Object param;
                if (wxApiForm == null || ValueConstants.DEFAULT_NONE.equals(wxApiForm.value())) {
                    paramName = p.getParameterName();
                } else {
                    paramName = wxApiForm.value();
                }
                // 加入Assert
                WxAppAssert.notNull(paramName, "请添加编译器的-parameter或者为参数添加注解名称");
                if (WxWebUtils.isMutlipart(p.getParameterType())) {
                    param = getFormResource(args[p.getParameterIndex()]);
                } else {
                    param = args[p.getParameterIndex()];
                }
                params.add(paramName, param);
            });
    return params;
}
 
Example 22
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.length() == 0) {
		name = parameter.getParameterName();
		if (name == null) {
			throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() +
					"] not available, and parameter name information not found in class file either.");
		}
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
Example 23
/**
 * Update the contextPath, servletPath, and pathInfo of the request.
 */
private void updatePathRequestProperties(MockHttpServletRequest request, String requestUri) {
	Assert.isTrue(requestUri.startsWith(this.contextPath),
			"requestURI [" + requestUri + "] does not start with contextPath [" + this.contextPath + "]");
	request.setContextPath(this.contextPath);
	request.setServletPath(this.servletPath);
	if (ValueConstants.DEFAULT_NONE.equals(this.pathInfo)) {
		Assert.isTrue(requestUri.startsWith(this.contextPath + this.servletPath),
				"Invalid servletPath [" + this.servletPath + "] for requestURI [" + requestUri + "]");
		String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
		this.pathInfo = (StringUtils.hasText(extraPath)) ? extraPath : null;
	}
	request.setPathInfo(this.pathInfo);
}
 
Example 24
Source Project: wadl-tools   Source File: ParamFromRequestParamBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Param build(Method javaMethod, int paramIndex, Annotation paramAnnotation) {
    final RequestParam requestParam = (RequestParam) paramAnnotation;
    final Param param = new Param()
            .withName(discoverParamName(javaMethod, paramIndex, requestParam.value()))
            .withStyle(ParamStyle.QUERY)
            .withRequired(requestParam.required())
            .withType(grammarsDiscoverer.discoverQNameFor(new ClassMetadataFromParam(javaMethod, paramIndex)));

    if (!ValueConstants.DEFAULT_NONE.equals(requestParam.defaultValue())) {
        param.setDefault(requestParam.defaultValue());
    }
    return param;
}
 
Example 25
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
	SessionAttribute ann = parameter.getParameterAnnotation(SessionAttribute.class);
	Assert.state(ann != null, "No SessionAttribute annotation");
	return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE);
}
 
Example 26
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
	RequestAttribute ann = parameter.getParameterAnnotation(RequestAttribute.class);
	Assert.state(ann != null, "No RequestAttribute annotation");
	return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE);
}
 
Example 27
@Nullable
@Override
protected Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) {
	Map<String, MultiValueMap<String, String>> pathParameters =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	MatrixVariable ann = param.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVar = ann.pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = param.getNestedParameterType().getName();
					throw new ServerErrorException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.",
							param, null);
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 28
RequestParamNamedValueInfo() {
	super("", false, ValueConstants.DEFAULT_NONE);
}
 
Example 29
public PathVariableNamedValueInfo(PathVariable annotation) {
	super(annotation.name(), annotation.required(), ValueConstants.DEFAULT_NONE);
}
 
Example 30
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
	SessionAttribute ann = parameter.getParameterAnnotation(SessionAttribute.class);
	Assert.state(ann != null, "No SessionAttribute annotation");
	return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE);
}