Java Code Examples for org.springframework.web.bind.annotation.MatrixVariable#pathVar()
The following examples show how to use
org.springframework.web.bind.annotation.MatrixVariable#pathVar() .
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: MatrixVariableMapMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@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 2
Source File: MatrixVariableMapMethodArgumentResolver.java From spring-analysis-note with MIT License | 5 votes |
@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 3
Source File: MatrixVariableMapMethodArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
@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 4
Source File: MatrixVariableMapMethodArgumentResolver.java From java-technology-stack with MIT License | 5 votes |
@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 5
Source File: MatrixVariableMethodArgumentResolver.java From spring-analysis-note with MIT License | 4 votes |
@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 6
Source File: MatrixVariableMethodArgumentResolver.java From spring-analysis-note with MIT License | 4 votes |
@Override @SuppressWarnings("unchecked") @Nullable protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>) request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (CollectionUtils.isEmpty(pathParameters)) { return null; } MatrixVariable ann = parameter.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 = parameter.getNestedParameterType().getName(); throw new ServletRequestBindingException( "Found more than one match for URI path parameter '" + name + "' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate."); } 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 7
Source File: MatrixVariableMethodArgumentResolver.java From java-technology-stack with MIT License | 4 votes |
@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 8
Source File: MatrixVariableMethodArgumentResolver.java From java-technology-stack with MIT License | 4 votes |
@Override @SuppressWarnings("unchecked") @Nullable protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>) request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (CollectionUtils.isEmpty(pathParameters)) { return null; } MatrixVariable ann = parameter.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 = parameter.getNestedParameterType().getName(); throw new ServletRequestBindingException( "Found more than one match for URI path parameter '" + name + "' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate."); } 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; } }