This is an automated email from the ASF dual-hosted git repository. fschumacher pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit e70ef8567bbe4b852ecfff41add0c43ba36d7fa6 Author: Felix Schumacher <[email protected]> AuthorDate: Fri Oct 25 15:38:10 2019 +0200 Add more documentation about usage of RewriteMap Add a more detailed example by providing a sample implementation and a hopefully more clear example rewrite.config. --- webapps/docs/changelog.xml | 4 ++++ webapps/docs/rewrite.xml | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index eb9e74d..87e5d44 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -55,6 +55,10 @@ <bug>63832</bug>: Properly mark container as FAILED when a JVM error occurs on stop. (remm) </fix> + <add> + Add more details on the usage of <code>RewriteMap</code> + functionality in the <code>RewriteValve</code>. (fschumacher) + </add> </changelog> </subsection> <subsection name="Coyote"> diff --git a/webapps/docs/rewrite.xml b/webapps/docs/rewrite.xml index 142680c..82b0b77 100644 --- a/webapps/docs/rewrite.xml +++ b/webapps/docs/rewrite.xml @@ -17,6 +17,7 @@ --> <!DOCTYPE document [ <!ENTITY project SYSTEM "project.xml"> + <!ENTITY ndash "–"> ]> <document url="index.html"> @@ -404,6 +405,52 @@ public interface RewriteMap { public String lookup(String key); }]]></source> + <p>The referenced implementation of such a class – in our example <code>rewriteMapClassName</code> – + will be instantiated and initialized with the optional parameter – <code>optionalParameters</code> from above + (be careful with whitespace) – by calling <code>setParameters(String)</code>. That instance + will then be registered under the name given as the first paramter of <code>RewriteMap</code> rule.</p> + + <p>That instance will be given the the lookup value that is configured in the corresponding <code>RewriteRule</code> by + calling <code>lookup(String)</code>. Your implementation is free to return <code>null</code> to indicate, + that the given default should be used, or to return a replacement value.</p> + + <p>Say, you want to implement a rewrite map function that converts all lookup keys to uppercase. You + would start by implementing a class that implements the <code>RewriteMap</code> interface.</p> + +<source><![CDATA[package example.maps; + +import org.apache.catalina.valves.rewrite.RewriteMap; + +public class UpperCaseMap implements RewriteMap { + + @Override + public String setParameters(String params) { + // nothing to be done here + return null; + } + + @Override + public String lookup(String key) { + if (key == null) { + return null; + } + return key.toUpperCase(); + } + +}]]></source> + + <p>Compile this class, put it into a jar and place that jar in <code>${CATALINA_BASE}/lib</code>.</p> + + <p>Having done that, you can now define a map with the <code>RewriteMap</code> directive + and further on use that map in a <code>RewriteRule</code>.</p> + +<source>RewriteMap uc example.maps.UpperCaseMap + +RewriteRule ^/(.*)$ ${uc:$1} +</source> + + <p>With this setup a request to the url path <code>/index.html</code> would get routed + to <code>/INDEX.HTML</code>.</p> </subsection> <subsection name="RewriteRule"> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
