in gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Matcher.java [278:330]
private Match createMatch( MatchSegment bestMatchSegment, PathNode bestPath, QueryNode bestQuery, Template input ) {
Match match = null;
if( bestPath != null ) { //&& ( bestQuery != null || !bestPath.hasQueries() ) ) {
if( bestQuery != null ) {
match = new Match( bestQuery.template, bestQuery.value );
} else {
match = new Match( bestPath.template, bestPath.value );
}
MatchParams matchParams = new MatchParams();
// Add the matching query segments to the end of the list.
if( bestQuery != null ) {
Map<String,Query> inputQuery = input.getQuery();
for( Query templateSegment : bestQuery.template.getQuery().values() ) {
Query inputSegment = inputQuery.get( templateSegment.getQueryName() );
if( inputSegment != null && templateSegment.matches( inputSegment ) ) {
extractSegmentParams( templateSegment, inputSegment, matchParams );
}
}
}
// If the template has the "extra" query queryParam then collect query params that were
// not already matched.
if( bestQuery != null ) {
Query extra = bestQuery.template.getExtra();
if( extra != null ) {
String paramName = extra.getParamName();
if( paramName != null && !paramName.isEmpty()) {
for( Query query: input.getQuery().values() ) {
String queryName = query.getQueryName();
if( matchParams.resolve( queryName ) == null ) {
for( Segment.Value value: query.getValues() ) {
matchParams.addValue( queryName, value.getEffectivePattern() );
}
}
}
}
}
}
// Walk back up the matching segment tree.
MatchSegment matchSegment = bestMatchSegment;
while( matchSegment != null && matchSegment.pathNode.depth > 0 ) {
extractSegmentParams( matchSegment.templateSegment, matchSegment.inputSegment, matchParams );
matchSegment = matchSegment.parentMatch;
}
match.params = matchParams;
}
return match;
}