Consolidate matrix vars parsing in HttpRequestPathHelper

Restore matrix variable parsing code not resorting to the use of
WebUtils which brings Servlet API dependencies with it.

Instead the parsing logic is now exposed through HttpRequestPathHelper
which already contained the decoding logic and also the knowledge of
whether to decode the parsed variables or not.

Issue: SPR-15397
This commit is contained in:
Rossen Stoyanchev
2017-06-02 15:52:44 -04:00
parent d2685dfe67
commit 4244df740b
3 changed files with 129 additions and 9 deletions

View File

@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import org.springframework.http.HttpHeaders;
@@ -34,7 +35,9 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.InvalidMediaTypeException;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.result.condition.NameValueExpression;
@@ -44,7 +47,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebInputException;
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
import org.springframework.web.server.support.LookupPath;
import org.springframework.web.util.WebUtils;
/**
* Abstract base class for classes for which {@link RequestMappingInfo} defines
@@ -145,19 +148,16 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
continue;
}
String matrixVariables;
String semicolonContent;
int semicolonIndex = uriVarValue.indexOf(';');
if ((semicolonIndex == -1) || (semicolonIndex == 0) || (equalsIndex < semicolonIndex)) {
matrixVariables = uriVarValue;
semicolonContent = uriVarValue;
}
else {
matrixVariables = uriVarValue.substring(semicolonIndex + 1);
semicolonContent = uriVarValue.substring(semicolonIndex + 1);
uriVariables.put(uriVar.getKey(), uriVarValue.substring(0, semicolonIndex));
}
MultiValueMap<String, String> vars = WebUtils.parseMatrixVariables(matrixVariables);
result.put(uriVar.getKey(), getPathHelper().decodeMatrixVariables(exchange, vars));
result.put(uriVar.getKey(), getPathHelper().parseMatrixVariables(exchange, semicolonContent));
}
return result;
}