Type: Technical Documentation
Affects Version/s: 7.4.X, Master
Fix Version/s: None
Sprint:Iteration 45, Iteration 46, Iteration 47, Iteration 48, Iteration 49, Iteration 50, AppSec Iteration 51, AppSec Iteration 52, AppSec Iteration 53, AppSec Iteration 54, AppSec Iteration 55, AppSec Iteration 56
Type of Documentation:Developer
Because we have different URL Matching procedures/logics across portal, and their complexity is linear with the number of patterns to match and the length of the patterns. This library implements servlet spec URL Matching procedures and is constant with regards to the number of patterns and only depends on the length of the longest pattern to match.
It solves the problem listed in why does this feature exist?, by unifying URL Matching procedures to those of servlet spec, and being performant.
Developers for portal can use this URL Pattern Mapper library to store URL Patterns and then matching URLs. See example in PortalCORSServletFilter.java.
Developers don't have to implement their URL Matching logic and they can be certain the library is correct and performs nicely.
It allows developers to match URLs. Nothing is changed in terms of stored data.
Typically the URL Pattern Mapper consumes a pre-defined URL Patterns (created by developers or set by admins), and builds a struct of URLPatternMapper, then it will return you the matched data that paired with the pattern for your input URLs.
It is not expected for developers to extend this library.
Well, no one wants to maintain multiple sets of code that does similar things, and everyone loves running fast.
List the steps a developer needs to take to implement this feature, or a user needs to perform in order to use this feature.
For developers to use this library
They need to import the module in build.gradle as compileOnly project(":core:petra:petra-url-pattern-mapper"),
then they need to make Mapping from the URL Pattern to whatever data he wants to pair up.
Calling URLPatternMapperFactory.create() with the mapping will create the instance of URLPatternMapper for you.
With previous steps completed, you can now find the matched URL Pattern(s) with any given URL by calling URLPatternMapper.getValue(String), or URLPatternMapper.getValues(String). If performance is important to your usage then you can even use URLPatternMapper.consumeValues() to avoid creating an intermediate list.
Provide example code illustrating an example of this feature. Explain what the code does and how it works.
Interface URLPatternMapper, this interface defines what a developer retrieve from an URLPatternMapper.
Factory URLPatternMapperFactory, this class will instantiate either DynamicSizeTrieURLPatternMapper or a StaticSizeTrieURLPatternMapper based on the number of patterns need to be stored.
Concrete implemetation, DynamicSizeTrieURLPatternMapper this implementation has an underlying data structure of Trie/prefix tree.
Concrete implemetation, StaticSizeTrieURLPatternMapper this implementation also has an underlying data structure of Trie/prefix tree, but we store the index of patterns to a long primitive so that this implementation runs even faster, at a cost of limited number(64) of patterns can be stored.