53
53
import java .util .StringTokenizer ;
54
54
import java .util .TimeZone ;
55
55
import java .util .function .Function ;
56
+ import java .util .function .Predicate ;
56
57
57
58
import javax .net .ssl .SSLContext ;
58
59
import javax .servlet .http .HttpServletRequest ;
@@ -155,7 +156,8 @@ public static Map<String, Object> getParameterMap(HttpServletRequest req, Set<?
155
156
.collect (toMap (Map .Entry ::getKey , pair -> transformParamValue (pair .getValue ())));
156
157
157
158
// Pseudo-parameters passed in the URI path overrides the ones from the regular URI parameters
158
- params .putAll (getPathInfoOnlyParameterMap (req .getPathInfo (), nameSet , includeOrSkip ));
159
+ params .putAll (getPathInfoOnlyParameterMap (req .getPathInfo (),
160
+ name -> nameSet == null || !(includeOrSkip ^ nameSet .contains (name ))));
159
161
160
162
// If nothing is found in the parameters, try to find something in the multi-part map.
161
163
Map <String , Object > multiPartMap = params .isEmpty () ? getMultiPartParameterMap (req ) : Collections .emptyMap ();
@@ -317,12 +319,10 @@ public static Map<String, Object> getQueryStringOnlyParameterMap(String queryStr
317
319
* This is an obsolete syntax for passing parameters to request handlers.
318
320
*
319
321
* @param path the URI path part which can be {@code null}
320
- * @param nameSet the set of parameters keys to include or skip
321
- * @param includeOrSkip toggle where {@code true} means including and {@code false} means skipping
322
+ * @param pred the predicate filtering parameter names
322
323
* @return a canonicalized parameter map.
323
324
*/
324
- static Map <String , Object > getPathInfoOnlyParameterMap (String path , Set <? extends String > nameSet ,
325
- boolean includeOrSkip ) {
325
+ static Map <String , Object > getPathInfoOnlyParameterMap (String path , Predicate <String > pred ) {
326
326
String path$ = Optional .ofNullable (path ).orElse ("" );
327
327
Map <String , List <String >> allParams = Arrays .stream (path$ .split ("/" ))
328
328
.filter (segment -> segment .startsWith ("~" ) && segment .contains ("=" ))
@@ -332,15 +332,15 @@ static Map<String, Object> getPathInfoOnlyParameterMap(String path, Set<? extend
332
332
// Filter and canonicalize the parameter map.
333
333
Function <List <String >, Object > canonicalize = val -> (val .size () == 1 ) ? val .get (0 ) : val ;
334
334
return allParams .entrySet ().stream ()
335
- .filter (e -> nameSet == null || !( includeOrSkip ^ nameSet . contains ( e .getKey () )))
335
+ .filter (pair -> pred . test ( pair .getKey ()))
336
336
.collect (collectingAndThen (toMap (Map .Entry ::getKey , canonicalize .compose (Map .Entry ::getValue )),
337
337
UtilHttp ::canonicalizeParameterMap ));
338
338
}
339
339
340
340
public static Map <String , Object > getUrlOnlyParameterMap (HttpServletRequest request ) {
341
341
// NOTE: these have already been through canonicalizeParameterMap, so not doing it again here
342
342
Map <String , Object > paramMap = getQueryStringOnlyParameterMap (request .getQueryString ());
343
- paramMap .putAll (getPathInfoOnlyParameterMap (request .getPathInfo (), null , true ));
343
+ paramMap .putAll (getPathInfoOnlyParameterMap (request .getPathInfo (), x -> true ));
344
344
return paramMap ;
345
345
}
346
346
0 commit comments