Path parameters allow associating a portion of the request path with a parameter. Such parameter will match any non empty portions of text except the / character (that is the [^/]+ regular expression). Otherwise, they can be associated with a regular expression for matching specific patterns. Path parameters are mandatory for matching since they are a part of the request path, however it is allowed to write regular expression matching an empty value.
Routing: Route is accepted if the regular expression is matched.
Rendering: The system will select a route to render an URL if all route parameters are always matched.
Encoding
Path parameters may contain the '/' character which is a reserved char for the URI path. This case is specially handled by the navigation controller by using a special character to replace the '/' literals. By default, the character is the colon ":" and can be changed to other possible values (see controller XML schema for possible values) to give a greater amount of flexibility.
This encoding is applied only when the encoding is performed for parameters having a mode set to the default-form
value, for instance, it does not happen for navigation node URI (for which / is encoded literally). The separator escape char can still be used but under it is percent escaped form, so by default, a path parameter value containing the colon ":" would be encoded as %3A
and conversely the %3A
value will be decoded as the colon ":".
For example, when no pattern is defined, the default one [^/]+ will be used:
<route path="/{gtn:path}">
</route>
As a result of the example above, routing and rendering are as below:
Routing and Rendering Path "/foo" <--> the map (gtn:path=foo) Path "/foo:bar" <--> the map (gtn:path=foo/bar)
If the request path contains another "/" char, it will not work. The default encoding mode is default-form. In the example above, "/foo/bar" is not matched, so the system returns an empty parameter map.
However, this problem could be solved with the following configuration:
<route path="/{gtn:path}">
<path-param encoding="preserve-path" qname="gtn:path">
<pattern>.*</pattern>
</path-param>
</route>
The ".*" declaration allows matching any char sequence.
The "preserve-path" encoding tells the engine that the "/" chars should be handled by the path parameter itself as they have a special meaning for the router. Without this special encoding, "/" would be rendered as the ":" character and conversely the ":" character would be matched as the "/" character.