From dca9e95f5ca0dc24262e7b4e836e9f772d793570 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 20 Oct 2023 09:34:13 +1300 Subject: [PATCH 1/5] 5.1 docs --- README.md | 4 +- build.xml | 2 +- container-test/example-webapp/pom.xml | 2 +- .../test-with-testcontainers/pom.xml | 2 +- pom.xml | 4 +- src/doc/manual/5.0/introduction.html | 11 - src/doc/manual/5.1/doc.css | 103 ++ src/doc/manual/5.1/guide.html | 819 +++++++++ src/doc/manual/5.1/index.html | 1493 +++++++++++++++++ src/doc/manual/5.1/introduction.html | 456 +++++ src/doc/manual/5.1/urf-100.png | Bin 0 -> 3530 bytes .../5.1/urlrewrite-conf-overview-sample.html | 270 +++ src/doc/manual/5.1/urlrewrite.xml | 97 ++ src/doc/manual/guide.html | 2 +- src/doc/manual/index.html | 2 +- .../web/filters/urlrewrite/ConfHandler.java | 9 +- src/test/webapp/WEB-INF/urlrewrite.xml | 4 +- 17 files changed, 3254 insertions(+), 26 deletions(-) create mode 100644 src/doc/manual/5.1/doc.css create mode 100644 src/doc/manual/5.1/guide.html create mode 100644 src/doc/manual/5.1/index.html create mode 100644 src/doc/manual/5.1/introduction.html create mode 100644 src/doc/manual/5.1/urf-100.png create mode 100644 src/doc/manual/5.1/urlrewrite-conf-overview-sample.html create mode 100644 src/doc/manual/5.1/urlrewrite.xml diff --git a/README.md b/README.md index f6a78866..a687fcd3 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,12 @@ See the [manual](https://tuckey.org/urlrewrite/manual/4.0/index.html) for more i ## Quick Start - * Add Maven dependency below or add urlrewritefilter-5.1.2.jar directly into your WEB-INF/lib directory. + * Add Maven dependency below or add urlrewritefilter-5.1.3.jar directly into your WEB-INF/lib directory. ```xml org.tuckey urlrewritefilter - 5.1.2 + 5.1.3 ``` diff --git a/build.xml b/build.xml index 35fa1c1f..3d4fddbb 100644 --- a/build.xml +++ b/build.xml @@ -7,7 +7,7 @@ - + diff --git a/container-test/example-webapp/pom.xml b/container-test/example-webapp/pom.xml index a10d846d..f1512ea5 100644 --- a/container-test/example-webapp/pom.xml +++ b/container-test/example-webapp/pom.xml @@ -58,7 +58,7 @@ org.tuckey urlrewritefilter - 5.1.2 + 5.1.3 jakarta.servlet diff --git a/container-test/test-with-testcontainers/pom.xml b/container-test/test-with-testcontainers/pom.xml index fd54656c..154a9f56 100644 --- a/container-test/test-with-testcontainers/pom.xml +++ b/container-test/test-with-testcontainers/pom.xml @@ -47,7 +47,7 @@ org.tuckey urlrewritefilter - 5.1.2 + 5.1.3 diff --git a/pom.xml b/pom.xml index f666562a..d42a667a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.tuckey urlrewritefilter jar - 5.1.2 + 5.1.3 UrlRewriteFilter http://www.tuckey.org/urlrewrite/ 2001 @@ -24,7 +24,7 @@ - 5.0 + 5.1 2022 UTF-8 UTF-8 diff --git a/src/doc/manual/5.0/introduction.html b/src/doc/manual/5.0/introduction.html index 16822954..77c6d147 100644 --- a/src/doc/manual/5.0/introduction.html +++ b/src/doc/manual/5.0/introduction.html @@ -188,17 +188,6 @@

License

Changelog

    -
  • 5.1.2 -
      -
    • Fix: Add v5 DTD
    • -
    • Docs: Add 5 references for readme and docs
    • -
    -
  • -
  • 5.1.1 -
      -
    • Changed to be fully based on jakarta servlet API 5
    • -
    -
  • 5.0.0
    • Removed Annotation processor
    • diff --git a/src/doc/manual/5.1/doc.css b/src/doc/manual/5.1/doc.css new file mode 100644 index 00000000..6cf3363f --- /dev/null +++ b/src/doc/manual/5.1/doc.css @@ -0,0 +1,103 @@ + + +@import url("http://www.tuckey.org/res/bootstrap/css/bootstrap.css"); +@import url("http://fonts.googleapis.com/css?family=Open+Sans:400,700italic"); + +body { + font-family: 'open sans', Sans-Serif; +} +.top { + margin-top: 20px; + border-top: 4px solid black; +} +.footer, #footer { + margin-top: 50px; + padding-top: 10px; + border-top: 4px solid black; + margin-bottom: 100px; +} +a { + color: #4979c0; +} + +#main h1 { + border-bottom: none; + font-size: 24px; + margin-top: 0; +} +h1, h2 { + text-align: center; + font-weight: 700; + font-style: italic; +} +h1 { + margin-top: 15px; + margin-bottom: 30px; + font-size: 50px; + line-height: 60px; +} +h2 { + border-bottom: none; + margin-top: 40px; + margin-bottom: 20px; +} +h3 { + border-bottom: none; + margin-top: 20px; + margin-bottom: 10px; +} +big { + font-size: 20px; + line-height: 25px; +} + + +#logo { + vertical-align: middle; +} + +#masthead { + -moz-border-radius-topright: 20px; +} + +#masthead a { + text-decoration: none; + color: black; +} + +hr { + border: 0px; + background-color: #c0c0c0; +} + +pre { + margin-top: 5px; + margin-bottom: 5px; +} + +.err { + color: #ff0000; +} + +#menu ul { + list-style-type: none; + margin-left: .5em; + padding-left: .5em; + margin-top: 7px; +} +#menu li { + margin-bottom: 7px; +} + +#main { + min-height: 400px; +} + +#footer { + text-align: center; + font-size: small; +} + +#footer a { + text-decoration: none; +} diff --git a/src/doc/manual/5.1/guide.html b/src/doc/manual/5.1/guide.html new file mode 100644 index 00000000..e65093d1 --- /dev/null +++ b/src/doc/manual/5.1/guide.html @@ -0,0 +1,819 @@ + + + + UrlRewriteFilter - Examples + + + + + + +
      +
      +

      + + UrlRewriteFilter 5.1.3

      +
      + +
      + + +
      + + +

      Examples

      + +

      Redirect one url

      + +
      
      +    <rule>
      +        <from>^/some/old/page\.html$</from>
      +        <to type="redirect">/very/new/page.html</to>
      +    </rule>
      +
      + +
      
      +    <rule match-type="wildcard">
      +        <from>/some/old/page.html</from>
      +        <to type="redirect">/very/new/page.html</to>
      +    </rule>
      +
      + +

      Redirect docs in a directory to another using wildcard engine.

      + +
      
      +    <urlrewrite default-match-type="wildcard">
      +
      +    <rule>
      +        <from>/some/old/*.doc</from>
      +        <to type="redirect">/very/new/$1.doc</to>
      +    </rule>
      +
      +    </urlrewrite>
      +
      + +

      Tiny/Freindly url

      + +
      
      +    <rule>
      +        <from>^/zebra$</from>
      +        <to type="redirect">/big/ugly/url/1,23,56,23132.html</to>
      +    </rule>
      +
      + +

      Default page as another (requests to / will be redirected)

      + +
      
      +    <rule>
      +        <from>^/$</from>
      +        <to type="redirect">/opencms/opencms/index.html</to>
      +    </rule>
      +
      + +

      Perform security checks in a centralised place

      + +
      
      +    <rule>
      +        <condition type="user-in-role" operator="notequal">admin</condition>
      +        <condition type="user-in-role" operator="notequal">bigboss</condition>
      +        <from>^/admin/(.*)$</from>
      +        <to>/go-away-please.html</to>
      +    </rule>
      +
      + + +

      Check that users are using the correct domain name to get to your site. ie, users gong to http://example.com/blah + will be redirected to http://www.example.com/blah

      + +
      
      +    <rule>
      +        <name>Domain Name Check</name>
      +        <condition name="host" operator="notequal">www.example.com</condition>
      +        <from>^(.*)$</from>
      +        <to type="redirect">http://www.example.com/context$1</to>
      +    </rule>
      +
      + + +

      Disable access to a directory.

      + +
      
      +    <rule>
      +        <name>Disable Directory</name>
      +        <from>^/notliveyet/.*$</from>
      +        <set type="status">403</set>
      +        <to>null</to>
      +    </rule>
      +
      + +

      Redirect a directory (for moved content)

      + +
      
      +    <rule>
      +        <from>^/some/olddir/(.*)$</from>
      +        <to type="redirect">/very/newdir/$1</to>
      +    </rule>
      +
      + +

      Clean a URL

      + +
      
      +    <rule>
      +        <from>^/products/([0-9]+)$</from>
      +        <to>/products/index.jsp?product_id=$1</to>
      +    </rule>
      +
      + +

      e.g. /products/1234 will be passed on to /products/index.jsp?product_id=1234 + without the user noticing.

      + +
      
      +    <rule>
      +        <from>^/world/([a-z]+)/([a-z]+)$</from>
      +        <to>/world.jsp?country=$1&amp;city=$2</to>
      +    </rule>
      +
      + +

      e.g. /world/unitedstates/newyork will be passed on to /world.jsp?country=unitedstates&city=newyork +

      + +

      Browser detection

      + +
      
      +    <rule>
      +        <condition name="user-agent">Mozilla/[1-4]</condition>
      +        <from>^/some/page\.html$</from>
      +        <to>/some/page-for-old-browsers.html</to>
      +    </rule>
      +
      + +

      e.g. will pass the request for /some/page.html on to /some/page-for-old-browsers.html + only for older browsers whose user agent strings match Mozilla/1, Mozilla/2, + Mozilla/3 or Mozilla/4.

      + + +

      Security. Preclude certain types of method from you web application.

      + +
      
      +    <rule>
      +        <condition type="method" next="or">PROPFIND</condition>
      +        <condition type="method">PUT</condition>
      +        <from>.*</from>
      +        <to type="redirect">/bad-method.html</to>
      +    </rule>
      +
      + + +

      Sunday Specials

      + +
      
      +    <rule>
      +        <condition type="dayofweek">1</condition>
      +        <from>^/products/$</from>
      +        <to>/products/sunday-specials.html</to>
      +    </rule>
      +
      + + +

      Set the "Cache-Control" HTTP response header for all requests

      + +
      
      +    <rule>
      +        <from>.*</from>
      +        <set type="response-header" name="Cache-Control">max-age=3600, must-revalidate</set>
      +    </rule>
      +
      + +

      Forward a request to a servlet

      + +
      
      +    <rule>
      +        <from>^/products/purchase$</from>
      +        <set name="action">purchase</set>
      +        <to>/servlets/ProductsServlet</to>
      +    </rule>
      +
      + +

      e.g. the request /products/purchase will be forwarded to /servlets/ProductsServlet and + inside + the servlet request.getAttribute("action") will return purchase.

      + +

      Set an "Expires" HTTP header 6 hours into the future for js, css and gif files

      + +
      
      +    <rule>
      +        <from>^.*\.(js|css|gif)$</from>
      +        <set type="expires">6 hours</set>
      +    </rule>
      +
      + +

      Hide jsessionid for requests from googlebot.

      + +
      
      +  <outbound-rule>
      +       <name>Strip URL Session ID's</name>
      +       <note>
      +           Strip ;jsession=XXX from urls passed through
      +response.encodeURL().
      +           The characters ? and # are the only things we can use to
      +find out where the jsessionid ends.
      +           The expression in 'from' below contains three capture
      +groups, the last two being optional.
      +               1, everything before ;jesessionid
      +               2, everything after ;jesessionid=XXX starting with a ?
      +(to get the query string) up to #
      +               3, everything ;jesessionid=XXX and optionally ?XXX
      +starting with a # (to get the target)
      +           eg,
      +           from index.jsp;jsessionid=sss?qqq to index.jsp?qqq
      +           from index.jsp;jsessionid=sss?qqq#ttt to index.jsp?qqq#ttt
      +           from index.jsp;jsessionid=asdasdasdsadsadasd#dfds -
      +index.jsp#dfds
      +           from u.jsp;jsessionid=wert.hg - u.jsp
      +           from /;jsessionid=tyu - /
      +       </note>
      +       <condition name="user-agent">googlebot</condition>
      +       <from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
      +       <to>$1$2$3</to>
      +   </outbound-rule>
      +
      + +

      Permanently redirect incoming URLs containing jsessionid.

      + +
      
      +  <rule>
      +       <name>Strip URL Session ID's</name>
      +       <note>
      +           Strip ;jsession=XXX from urls passed through
      +response.encodeURL().
      +           The characters ? and # are the only things we can use to
      +find out where the jsessionid ends.
      +           The expression in 'from' below contains three capture
      +groups, the last two being optional.
      +               1, everything before ;jesessionid
      +               2, everything after ;jesessionid=XXX starting with a ?
      +(to get the query string) up to #
      +               3, everything ;jesessionid=XXX and optionally ?XXX
      +starting with a # (to get the target)
      +           eg,
      +           from index.jsp;jsessionid=sss?qqq to index.jsp?qqq
      +           from index.jsp;jsessionid=sss?qqq#ttt to index.jsp?qqq#ttt
      +           from index.jsp;jsessionid=asdasdasdsadsadasd#dfds -
      +index.jsp#dfds
      +           from u.jsp;jsessionid=wert.hg - u.jsp
      +           from /;jsessionid=tyu - /
      +       </note>
      +       <condition type="requested-session-id-from-url" operator="equal">true</condition>
      +       <from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
      +       <to type="permanent-redirect">$1$2$3</to>
      +   </rule>
      +
      + + + +

      Method Invocation

      + +

      The standard servlet mapping that is done via web.xml is rather limiting. Only *.xxx or /xxxx/*, no abilty to have + any sort of smart matching. Using UrlRewriteFilter any rule when matched can be set to run method(s) on a class.

      + +

      Invoke a servlet directly

      + +
      
      +    <rule>
      +    <from>^/products/purchase$</from>
      +    <run class="com.blah.web.MyServlet" method="doGet" />
      +    </rule>
      +
      + +

      This will invoke doGet(HttpServletRequest request, HttpServletResponse response) when the "from" is + matched on a request. (remeber this method needs to be public!)

      + +

      Use it to delagate cleanly to your methods

      + +
      
      +    <rule>
      +        <from>^/pref-editor/addresses$</from>
      +        <run class="com.blah.web.PrefsServlet" method="runAddresses" />
      +    </rule>
      +    <rule>
      +        <from>^/pref-editor/phone-nums$</from>
      +        <run class="com.blah.web.PrefsServlet" method="runPhoneNums" />
      +    </rule>
      +
      + +

      Browser based delagation to your methods

      + +
      
      +    <rule>
      +        <condition name="user-agent">Mozilla/[1-4]</condition>
      +        <from>^/content/.*$</from>
      +        <run class="com.blah.web.ContentServlet" method="runForOldBrowsers" />
      +    </rule>
      +    <rule>
      +        <condition name="user-agent" operator="notequal">Mozilla/[1-4]</condition>
      +        <from>^/content/.*$</from>
      +        <run class="com.blah.web.GeneralServlet" method="runRobotMonitor" />
      +        <run class="com.blah.web.ContentServlet" method="runForNewBrowsers" />
      +    </rule>
      +
      + +

      When the method specified in the "run" is invoked it has full control over the request and response as if it were a + servlet.

      + + + + + + + +

      URL Abstraction

      + +

      Both incoming request and embedded links in JSP's can be rewritten allowing full URL abstraction.

      + +
      
      +    <rule>
      +        <from>^/tidy/page$</from>
      +        <to>/old/url/scheme/page.jsp</to>
      +    </rule>
      +    <outbound-rule>
      +        <from>^/old/url/scheme/page.jsp$</from>
      +        <to>/tidy/page</to>
      +    </outbound-rule>
      +
      + +

      Any incoming requests for /tidy/page will be transparently forwarded to + /old/url/scheme/page.jsp.

      + +

      If you use JSTL your JSP page would have something like:

      +
      <a href="<c:url value="/old/url/scheme/page.jsp"/>">some link</a>
      + +

      This will be rewritten upon output to:

      +
      <a href="/tidy/page">some link</a>
      + +

      Or if you use standard JSP:

      +
      <a href="<%= response.encodeURL("/old/url/scheme/page.jsp") %>">some link</a>
      + +

      Will generate output like:

      +
      <a href="/tidy/page">some link</a>
      + + + + +

      mod_rewrite vs UrlRewriteFilter

      + + +

      Examples of mod_rewrite style conf vs UrlRewriteFilter conf are below, there are all examples copied directly from + Apache 2.0's official rewrite guide.

      + +
      
      +
      +<rule>
      +    <name>Canonical URLs</name>
      +    <note>
      +        On some webservers there are more than one URL for a resource. Usually there are canonical URLs (which
      +        should be actually used and distributed) and those which are just shortcuts, internal ones, etc. Independent
      +        of which URL the user supplied with the request he should finally see the canonical one only.
      +
      +        We do an external HTTP redirect for all non-canonical URLs to fix them in the location view of the Browser
      +        and for all subsequent requests. In the example ruleset below we replace /~user by the canonical /u/user and
      +        fix a missing trailing slash for /u/user.
      +
      +        RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
      +        RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]
      +    </note>
      +    <from>^/~([^/]+)/?(.*)</from>
      +    <to type="redirect">/u/$1/$2</to>
      +</rule>
      +<rule>
      +    <from>^/([uge])/([^/]+)$</from>
      +    <to type="redirect">/$1/$2/</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Canonical Hostnames</name>
      +    <note>
      +        The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which
      +        may be used to reach the same site. For example, if you wish to force the use of www.example.com instead of
      +        example.com, you might use a variant of the following recipe.
      +
      +        RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
      +        RewriteCond %{HTTP_HOST} !^$
      +        RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]
      +    </note>
      +    <condition name="host" operator="notequal">^fully\.qualified\.domain\.name</condition>
      +    <condition name="host" operator="notequal">^$</condition>
      +    <from>^/(.*)</from>
      +    <to type="redirect" last="true">http://fully.qualified.domain.name/$1</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Moved DocumentRoot</name>
      +    <note>
      +        Usually the DocumentRoot of the webserver directly relates to the URL "/". But often this data is not
      +        really of top-level priority, it is perhaps just one entity of a lot of data pools. For instance at our
      +        Intranet sites there are /e/www/ (the homepage for WWW), /e/sww/ (the homepage for the Intranet) etc. Now
      +        because the data of the DocumentRoot stays at /e/www/ we had to make sure that all inlined images and other
      +        stuff inside this data pool work for subsequent requests.
      +
      +        We just redirect the URL / to /e/www/. While is seems trivial it is actually trivial with mod_rewrite, only.
      +        Because the typical old mechanisms of URL Aliases (as provides by mod_alias and friends) only used prefix
      +        matching. With this you cannot do such a redirection because the DocumentRoot is a prefix of all URLs.
      +        With mod_rewrite it is really trivial:
      +
      +        RewriteRule ^/$ /e/www/ [R]
      +    </note>
      +    <from>^/$</from>
      +    <to type="redirect">/e/www/</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Trailing Slash Problem</name>
      +    <note>
      +        Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories.
      +        If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then
      +        the server searches for a file named foo. And because this file is a directory it complains. Actually it
      +        tries to fix it itself in most of the cases, but sometimes this mechanism need to be emulated by you. For
      +        instance after you have done a lot of complicated URL rewritings to CGI scripts etc.
      +
      +        The solution to this subtle problem is to let the server add the trailing slash automatically. To do this
      +        correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If
      +        we only did a internal rewrite, this would only work for the directory page, but would go wrong when any
      +        images are included into this page with relative URLs, because the browser would request an in-lined object.
      +        For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the
      +        external redirect!
      +    </note>
      +    <from>^/~quux/foo$</from>
      +    <to type="redirect">/~quux/foo/</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Move Homedirs to Different Webserver</name>
      +    <note>
      +        Many webmasters have asked for a solution to the following situation: They wanted to redirect just all
      +        homedirs on a webserver to another webserver. They usually need such things when establishing a newer
      +        webserver which will replace the old one over time.
      +
      +        The solution is trivial with mod_rewrite (and UrlRewriteFilter). On the old webserver we just redirect all
      +        /~user/anypath URLs to http://newserver/~user/anypath.
      +
      +        RewriteRule ^/~(.+) http://newserver/~$1 [R,L]
      +    </note>
      +    <from>^/~(.+)</from>
      +    <to type="redirect" last="true">http://newserver/~$1</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Structured Homedirs</name>
      +    <note>
      +        Some sites with thousands of users usually use a structured homedir layout, i.e. each homedir is in a
      +        subdirectory which begins for instance with the first character of the username. So, /~foo/anypath is
      +        /home/f/foo/.www/anypath while /~bar/anypath is /home/b/bar/.www/anypath.
      +
      +        We use the following ruleset to expand the tilde URLs into exactly the above layout.
      +
      +        RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3
      +    </note>
      +    <from>^/~(([a-z])[a-z0-9]+)(.*)</from>
      +    <to>/home/$2/$1/.www$3</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Redirect Homedirs For Foreigners</name>
      +    <note>
      +        We want to redirect homedir URLs to another webserver www.somewhere.com when the requesting user does not
      +        stay in the local domain ourdomain.com. This is sometimes used in virtual host contexts.
      +
      +        Just a rewrite condition:
      +
      +        RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$
      +        RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L]
      +    </note>
      +    <condition name="host">!^.+\.ourdomain\.com$</condition>
      +    <from>^(/~.+)</from>
      +    <to type="redirect" last="true">http://www.somewhere.com/$1</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Time-Dependent Rewriting</name>
      +    <note>
      +        When tricks like time-dependent content should happen a lot of webmasters still use CGI scripts which do for
      +        instance redirects to specialized pages. How can it be done via mod_rewrite?
      +
      +        There are a lot of types in conjunction with operators we can do time-dependent redirects:
      +
      +        RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700
      +        RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
      +        RewriteRule ^foo\.html$ foo.day.html
      +        RewriteRule ^foo\.html$ foo.night.html
      +    </note>
      +    <condition type="hourofday" operator="greater">7</condition>
      +    <condition type="hourofday" operator="less">19</condition>
      +    <from>^foo\.html$</from>
      +    <to>foo.day.html</to>
      +</rule>
      +<rule>
      +    <from>^foo\.html$</from>
      +    <to>foo.night.html</to>
      +</rule>
      +
      +
      +<rule>
      +    <name></name>
      +    <note>
      +        Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for
      +        backward compatibility. Actually we want that users of the old URL even not recognize that the pages was
      +        renamed.
      +
      +        We rewrite the old URL to the new one internally via the following rule:
      +
      +        RewriteBase /~quux/
      +        RewriteRule ^foo\.html$ bar.html
      +    </note>
      +    <from>^/~quux/foo\.html$</from>
      +    <to>/~quux/bar.html</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>From Old to New (extern)</name>
      +    <note>
      +        Assume again that we have recently renamed the page foo.html to bar.html and now want to provide the old URL
      +        for backward compatibility. But this time we want that the users of the old URL get hinted to the new one,
      +        i.e. their browsers Location field should change, too.
      +
      +        We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view:
      +
      +        RewriteBase /~quux/
      +        RewriteRule ^foo\.html$ bar.html [R]
      +    </note>
      +    <from>^/~quux/foo\.html$</from>
      +    <to type="redirect">/~quux/bar.html</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Browser Dependent Content</name>
      +    <note>
      +        At least for important top-level pages it is sometimes necessary to provide the optimum of browser dependent
      +        content, i.e. one has to provide a maximum version for the latest Netscape variants, a minimum version for
      +        the Lynx browsers and a average feature version for all others.
      +
      +        We cannot use content negotiation because the browsers do not provide their type in that form. Instead we
      +        have to act on the HTTP header "User-Agent". The following condig does the following: If the HTTP header
      +        "User-Agent" begins with "Mozilla/3", the page foo.html is rewritten to foo.NS.html and and the rewriting
      +        stops. If the browser is "Lynx" or "Mozilla" of version 1 or 2 the URL becomes foo.20.html. All other
      +        browsers receive page foo.32.html. This is done by the following ruleset:
      +
      +        RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
      +        RewriteRule ^foo\.html$ foo.NS.html [L]
      +
      +        RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
      +        RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*
      +        RewriteRule ^foo\.html$ foo.20.html [L]
      +
      +        RewriteRule ^foo\.html$ foo.32.html [L]
      +    </note>
      +    <condition name="user-agent">^Mozilla/3.*</condition>
      +    <from>^foo\.html$</from>
      +    <to last="true">foo.NS.html</to>
      +</rule>
      +<rule>
      +    <condition name="user-agent" next="or">^Lynx/.*</condition>
      +    <condition name="user-agent">^Mozilla/[12].*</condition>
      +    <from>^foo\.html$</from>
      +    <to last="true">foo.20.html</to>
      +</rule>
      +<rule>
      +    <from>^foo\.html$</from>
      +    <to last="true">foo.32.html</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>From Static to Dynamic</name>
      +    <note>
      +        How can we transform a static page foo.html into a dynamic variant foo.cgi in a seamless way, i.e. without
      +        notice by the browser/user.
      +
      +        We just rewrite the URL to the jsp/servlet and force the correct MIME-type so it gets really run as
      +        a CGI-script. This way a request to /~quux/foo.html internally leads to the invocation of /~quux/foo.jsp.
      +
      +        RewriteBase /~quux/
      +        RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi]
      +    </note>
      +    <from>^/~quux/foo\.html$</from>
      +    <to>/~quux/foo.jsp</to>
      +</rule>
      +
      +<rule>
      +    <name>Blocking of Robots</name>
      +    <note>
      +        How can we block a really annoying robot from retrieving pages of a specific webarea? A /robots.txt file
      +        containing entries of the "Robot Exclusion Protocol" is typically not enough to get rid of such a robot.
      +
      +        We use a ruleset which forbids the URLs of the webarea /~quux/foo/arc/ (perhaps a very deep directory
      +        indexed area where the robot traversal would create big server load). We have to make sure that we forbid
      +        access only to the particular robot, i.e. just forbidding the host where the robot runs is not enough.
      +        This would block users from this host, too. We accomplish this by also matching the User-Agent HTTP header
      +        information.
      +
      +        RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*
      +        RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$
      +        RewriteRule ^/~quux/foo/arc/.+ - [F]
      +    </note>
      +    <condition name="user-agent">^NameOfBadRobot.*</condition>
      +    <condition type="remote-addr">^123\.45\.67\.[8-9]$</condition>
      +    <from>^/~quux/foo/arc/.+</from>
      +    <set type="status">403</set>
      +    <to>null</to>
      +</rule>
      +
      +
      +<rule>
      +    <name>Blocked Inline-Images</name>
      +    <note>
      +        Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are
      +        nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because
      +        it adds useless traffic to our server.
      +
      +        While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser
      +        sends a HTTP Referer header.
      +
      +        RewriteCond %{HTTP_REFERER} !^$
      +        RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
      +        RewriteRule .*\.gif$ - [F]
      +    </note>
      +    <condition name="referer" operator="notequal">^$</condition>
      +    <condition name="referer" operator="notequal">^http://www.quux-corp.de/~quux/.*$</condition>
      +    <from>.*\.gif$</from>
      +    <set type="status">403</set>
      +    <to>null</to>
      +</rule>
      +
      +<rule>
      +    <name>Blocked Inline-Images example 2</name>
      +    <note>
      +        RewriteCond %{HTTP_REFERER} !^$
      +        RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$
      +        RewriteRule ^inlined-in-foo\.gif$ - [F]
      +    </note>
      +    <condition name="referer" operator="notequal">^$</condition>
      +    <condition name="referer" operator="notequal">.*/foo-with-gif\.html$</condition>
      +    <from>^inlined-in-foo\.gif$</from>
      +    <set type="status">403</set>
      +    <to>null</to>
      +</rule>
      +
      +
      + + + + + +

      Extending UrlRewriteFilter

      + + +

      To extend the basic rule functionality make a subclass of org.tuckey.web.filters.urlrewrite.extend.RewriteRule

      + +

      For an example of an extended rule see: +
      src/java/org/tuckey/web/filters/urlrewrite/sample/SampleRewriteRule.java +

      + +

      A "class-rule" is configured by adding it into urlrewrite.xml as follows:

      + +
      <class-rule class="org.tuckey.web.filters.urlrewrite.TestRuleObj"/>
      + +

      Or for a method with a name other than "matches":

      +
      <class-rule class="org.tuckey.web.filters.urlrewrite.TestRuleObj" method="trial"/>
      + + + +
      +
      + + + + + + diff --git a/src/doc/manual/5.1/index.html b/src/doc/manual/5.1/index.html new file mode 100644 index 00000000..599a20f2 --- /dev/null +++ b/src/doc/manual/5.1/index.html @@ -0,0 +1,1493 @@ + + + + UrlRewriteFilter - Manual + + + + + + +
      +
      +

      + + UrlRewriteFilter 5.1.3

      +
      + +
      + + +
      + +

      Manual

      + + +

      Community support is available at UrlRewrite on StackOverflow.

      + +

      Read examples of usage and a + sample of the ant task report. + If you have any suggestions/examples for this manual please post them to the + group.

      + + + +

      Install

      + +
        +
      1. Add Maven dependency below or add + urlrewritefilter-5.1.3.jar + directly into your WEB-INF/lib directory. +
        <dependency>
        +    <groupId>org.tuckey</groupId>
        +    <artifactId>urlrewritefilter</artifactId>
        +    <version>5.1.3</version>
        +</dependency>
      2. +
      3. Add the following to your WEB-INF/web.xml (add it near the top above your + servlet mappings (if you have any)): (see filter + parameters for more options) +
        <filter>
        +    <filter-name>UrlRewriteFilter</filter-name>
        +    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        +</filter>
        +<filter-mapping>
        +    <filter-name>UrlRewriteFilter</filter-name>
        +    <url-pattern>/*</url-pattern>
        +    <dispatcher>REQUEST</dispatcher>
        +    <dispatcher>FORWARD</dispatcher>
        +</filter-mapping>
      4. +
      5. Add urlrewrite.xml + into your WEB-INF directory. (src/main/webapp/WEB-INF/ for Maven users)
      6. +
      7. Restart the context.
      8. +
      + +

      You can visit http://127.0.0.1:8080/rewrite-status + (or whatever the address of your local webapp and context) + to see output (note: this page is only viewable from localhost).

      + + + +

      Filter Parameters

      + +

      There are a few advanced filter parameters for enabling conf file reloading etc. There are self-explanatory.

      + +
      +<filter>
      +    <filter-name>UrlRewriteFilter</filter-name>
      +    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
      +
      +    <!-- set the amount of seconds the conf file will be checked for reload
      +    can be a valid integer (0 denotes check every time,
      +    -1 denotes no reload check, default -1) -->
      +    <init-param>
      +        <param-name>confReloadCheckInterval</param-name>
      +        <param-value>60</param-value>
      +    </init-param>
      +
      +    <!-- if you need to the conf file path can be changed
      +    it is specified as a path relative to the root of your context
      +    (default /WEB-INF/urlrewrite.xml) -->
      +    <init-param>
      +        <param-name>confPath</param-name>
      +        <param-value>/WEB-INF/urlrewrite.xml</param-value>
      +    </init-param>
      +
      +    <!-- sets up log level (will be logged to context log)
      +    can be: slf4j, TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL,
      +    sysout:{level} (ie, sysout:DEBUG)
      +    if you are having trouble using normal levels use sysout:DEBUG
      +    (default WARN) -->
      +    <init-param>
      +        <param-name>logLevel</param-name>
      +        <param-value>DEBUG</param-value>
      +    </init-param>
      +
      +    <!-- you can change status path so that it does not
      +    conflict with your installed apps (note, defaults
      +    to /rewrite-status) note, must start with / -->
      +    <init-param>
      +        <param-name>statusPath</param-name>
      +        <param-value>/status</param-value>
      +    </init-param>
      +
      +    <!-- you can disable status page if desired
      +    can be: true, false (default true) -->
      +    <init-param>
      +        <param-name>statusEnabled</param-name>
      +        <param-value>true</param-value>
      +    </init-param>
      +
      +    <!-- you may want to allow more hosts to look at the status page
      +    statusEnabledOnHosts is a comma delimited list of hosts, * can
      +    be used as a wildcard (defaults to "localhost, local, 127.0.0.1") -->
      +    <init-param>
      +        <param-name>statusEnabledOnHosts</param-name>
      +        <param-value>localhost, dev.*.myco.com, *.uat.mycom.com</param-value>
      +    </init-param>
      +
      +    <!-- you may want to allow more hosts to look at the status page
      +    statusEnabledOnHosts is a comma delimited list of hosts, * can
      +    be used as a wildcard (defaults to "localhost, local, 127.0.0.1") -->
      +    <init-param>
      +        <param-name>statusEnabledOnHosts</param-name>
      +        <param-value>localhost, dev.*.myco.com, *.uat.mycom.com</param-value>
      +    </init-param>
      +
      +    <!-- defaults to false. use mod_rewrite style configuration file (if this is true and confPath
      +    is not specified confPath will be set to /WEB-INF/.htaccess) -->
      +    <init-param>
      +        <param-name>modRewriteConf</param-name>
      +        <param-value>false</param-value>
      +    </init-param>
      +
      +    <!-- load mod_rewrite style configuration from this parameter's value.
      +            note, Setting this parameter will mean that all other conf parameters are ignored.
      +        <init-param>
      +            <param-name>modRewriteConfText</param-name>
      +            <param-value>
      +                RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R]
      +                RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]
      +            </param-value>
      +        </init-param>
      +    -->
      +
      +    <!-- defaults to false. allow conf file to be set by calling /rewrite-status/?conf=/WEB-INF/urlrewrite2.xml
      +            designed to be used for testing only
      +        <init-param>
      +            <param-name>allowConfSwapViaHttp</param-name>
      +            <param-value>false</param-value>
      +        </init-param>
      +    -->
      +
      +</filter>
      +
      +<filter-mapping>
      +    <filter-name>UrlRewriteFilter</filter-name>
      +    <url-pattern>/*</url-pattern>
      +    <dispatcher>REQUEST</dispatcher>
      +    <dispatcher>FORWARD</dispatcher>
      +</filter-mapping>
      +
      + +

      Note, setting logLevel to slf4j will cause the built in logging to + call slf4j as if it was the logging framework, + obviously you will need to have the jar for slf4j in your classpath.

      + + + +

      Configuration File WEB-INF/urlrewrite.xml

      + + + + + +
      + + <urlrewrite>   + <rule>   + <outbound-rule>   + <class-rule> +
      + <name>   + <note>   + <condition>   + <from>   + <to>   + <set>   + <run>   +
      + Back References   + Variables   + Functions   +
      +
      +
      + +

      Configuration is done via a simple XML file that lives in your WEB-INF folder. It should be named + urlrewrite.xml. + It may be helpful to read the UrlRewriteFilter DTD + (Document Type Definition). Please also make sure you look at the examples. A simple + configuration file looks like:

      + +
      +<?xml version="1.0" encoding="utf-8"?>
      +
      +<!DOCTYPE urlrewrite
      +    PUBLIC "-//tuckey.org//DTD UrlRewrite 5.1//EN"
      +    "http://www.tuckey.org/res/dtds/urlrewrite5.1.dtd">
      +
      +<urlrewrite>
      +
      +    <rule>
      +       <from>^/some/olddir/(.*)$</from>
      +       <to type="redirect">/very/newdir/$1</to>
      +    </rule>
      +
      +    <rule match-type="wildcard">
      +       <from>/blog/archive/**</from>
      +       <to type="redirect">/roller/history/$1</to>
      +    </rule>
      +
      +</urlrewrite>
      +
      + + +

      The urlrewrite.xml file must have a root element called "urlrewrite" and must contain + at least one "rule" element.

      + +

      A "rule" must contain a "from" and a "to", and can have zero or more "condition" elements and zero or more and/or + "set" elements.

      + +

      When a "rule" is processed against an incoming request, all the "condition" elements must be met, then + the "from" will be applied to the request URL and the final URL generated by applying the + "to" to the "from" pattern. So long as the rule has matched then the "set" will be run.

      + + + +

      When executing a rule the filter will (very simplified) loop over all rules and for each do something like this psuedo code:

      + +
      +Pattern.compile(<from> element);
      +pattern.matcher(request url);
      +matcher.replaceAll(<to> element);
      +if ( <condition> elements match && matcher.find() ) {
      +    handle <set> elements (if any)
      +    execute <run> elements (if any)
      +    perform <to> element (if any)
      +}
      +
      + + + +

      <urlrewrite> element

      + +

      The top level element.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      default-match-type
      (optional)
      regex (default)All rules and thier conditions will be processed using the Java Regular Expression engine (unless + match-type is specified on a rule).
      wildcardAll rules and thier conditions will be processed using the Wildcard Expression + engine + (unless match-type is specified on a rule).
      decode-using
      (optional)
      header,utf8 (default)When URL is decoded request.getCharacterEncoding() will be used, if that is empty UTF-8 will be used. +
      nullDo not decode at all. (note, this means the literal string null e.g. decode-using="null")
      headerOnly use request.getCharacterEncoding() to decode.
      [encoding]Only use a specific character encoding eg, ISO-8859-1. + See Java Charset Object + for all character encodings. +
      header,[encoding] + When URL is decoded request.getCharacterEncoding() will be used, if that is empty a specific character + encoding eg, ISO-8859-1. + See Java Charset Object + for all character encodings. +
      use-query-string
      (optional)
      false (default)The query string will not be appended to the url that the "from" element matches against.
      trueThe query string will be appended to the url that the "from" element matches against.
      use-context
      (optional)
      false (default)The context path will not be added to the url that the "from" element matches against.
      trueThe context path will be added to the url that the "from" element matches against.
      + + + +

      <rule> element

      + +

      Zero or more. The basis of a rule.

      + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      enabled
      (optional)
      true (default)Enable this rule.
      falseDisable this rule.
      match-type
      (optional)
      regex (default)This rule and it's conditions will be processed using the Java Regular Expression engine.
      wildcardThis rule and it's conditions will be processed using the Wildcard Expression engine. +
      + +

      In the following example requests for /world/usa/nyc will be transparently forwarded to + /world.jsp

      + +
      +<rule match-type="regex">
      +   <from>^/world/([a-z]+)/([a-z]+)$</from>
      +   <to>/world.jsp</to>
      +</rule>
      +
      + +
      +<rule match-type="wildcard">
      +   <from>/world/*/*</from>
      +   <to>/world.jsp</to>
      +</rule>
      +
      + + + +

      <outbound-rule> element

      + +

      Zero or more. This is very similar to a normal rule but it is used for rewriting urls that go through + response.encodeURL().

      + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      enabled
      (optional)
      true (default)Enable this rule.
      falseDisable this rule.
      encodefirst
      (optional)
      false (default)Run encodeURL() after running this outbound rule.
      trueRun encodeURL() before running this outbound rule.
      + +

      May contain "run", "from", "to" and "set" element(s) also. Example:

      + +
      +<outbound-rule>
      +    <from>^/world.jsp?country=([a-z]+)&amp;city=([a-z]+)$</from>
      +    <to>/world/$1/$2</to>
      +</outbound-rule>
      +
      + +

      Using the example above JSP's with the code +
      <a href="<%= response.encodeURL("/world.jsp?country=usa&amp;city=nyc") + %>">nyc</a> +
      will output +
      <a href="/world/usa/nyc">nyc</a> +

      + +

      Or JSTL +
      <a href="<c:url value="/world.jsp?country=${country}&amp;city=${city}" + />">nyc</a> +
      will output +
      <a href="/world/usa/nyc">nyc</a> +

      + +

      Note, If you are using JSTL (ie, <c:url) this will work also.

      + + + +

      <name> element

      + +

      An optional element used for documenting the name of the rule. This can be used with rule and outbound-rule. + See ant task.

      + +
      +<rule>
      +    <name>World Rule</name>
      +    <from>^/world/([a-z]+)/([a-z]+)$</from>
      +    <to>/world.jsp?country=$1&amp;city=$2</to>
      +</rule>
      +
      + + + +

      <note> element

      + +

      A simple optional element used for documentation of the rule. This can be used with rule and outbound-rule. + See ant task.

      + +
      +<rule>
      +    <name>World Rule</name>
      +    <note>
      +        Cleanly redirect world requests to JSP,
      +        a country and city must be specified.
      +    </note>
      +    <from>^/world/([a-z]+)/([a-z]+)$</from>
      +    <to>/world.jsp</to>
      +</rule>
      +
      + + + +

      <condition> element

      + +

      An element that lets you choose conditions for the rule. Note, all conditions must be met for the rule to be run + (unless "next" is set to "or" obvoiusly).

      + +

      Value can be any Regular Expression.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      type
      (optional)
      header (default)If used, the header name must be specified in the "name" attribute.
      methodThe method of the request. GET, POST, HEAD etc.
      portThe port that the web application server is running on.
      time + Current time at the server (this will be the number of seconds since 00:00:00 1970-01-01 UTC otherwise known as unix + time). +
      i.e. (new Date()).getTime() +
      This can be used for making sure content goes live only at a time you set. +
      year + Current year at the server. +
      i.e. (Calendar.getInstance()).get(Calendar.YEAR) +
      month + Month at the server. January is 0 +
      i.e. (Calendar.getInstance()).get(Calendar.MONTH) +
      dayofmonth + Day of the month at the server. March first is 1 +
      i.e. (Calendar.getInstance()).get(Calendar.DAY_OF_MONTH) +
      dayofweek + Day of the week at the server. Saturday is 1, Sunday is 7 +
      i.e. (Calendar.getInstance()).get(Calendar.DAY_OF_WEEK) +
      ampm + AM or PM time at the server. +
      i.e. (Calendar.getInstance()).get(Calendar.AM_PM) +
      hourofday + The hour of the day (24 hour clock) at the server. 10pm is 22 +
      i.e. (Calendar.getInstance()).get(Calendar.HOUR_OF_DAY) +
      minute + The minute field of the current time at the server. +
      i.e. (Calendar.getInstance()).get(Calendar.MINUTE) +
      second + The second field of the current time at the server. +
      i.e. (Calendar.getInstance()).get(Calendar.SECOND) +
      millisecond + The millisecond field of the current time at the server. +
      i.e. (Calendar.getInstance()).get(Calendar.MILLISECOND) +
      attribute + Will check the value of a request attribute (don't confuse this with parameter!), name must be set when + using this type. +
      i.e. request.getAttribute([name]) + +
      auth-type + Will check the value of a request attribute (don't confuse this with parameter!) +
      i.e. request.getAuthType() + +
      character-encoding + The character encoding of the imcoming request. +
      i.e. request.getCharacterEncoding() + +
      content-length + The length of the imcoming request (can be useful if you want to deny large requests). +
      i.e. request.getContentLength() + +
      content-type + The type of the imcoming request. (this is probably not that useful) +
      i.e. request.getContentType() + +
      context-path + The context path of the imcoming request. +
      i.e. request.getContextPath() + +
      cookie + The value of a cookie, note, name must be specified to use this +
      i.e. request.getCookies() + the find we the one with [name] specified and check the value. +
      parameter + A tidier way of checking request parameters than looking for them in the query string. This will check for the + parameter in GET or POST, note, name must be specified. +
      i.e. request.getParameter([name]) + +
      path-info + i.e. request.getPathInfo() + +
      path-translated + i.e. request.getPathTranslated() + +
      protocolThe protocol used to make the request, e.g. HTTP/1.1 +
      i.e. request.getProtocol() + +
      query-stringThe query string used to make the request (if any), e.g. id=2345&name=bob +
      i.e. request.getQueryString() + +
      remote-addrThe IP address of the host making the request, e.g. 123.123.123.12 +
      i.e. request.getRemoteAddr() + +
      remote-hostThe host name of the host making the request, e.g. 123qw-dsl.att.com (note, + this will only work if your app server is configured to lookup host names, most aren't). +
      i.e. request.getRemoteHost() + +
      remote-userThe login of the user making this request, if the user has been authenticated, e.g. bobt +
      i.e. request.getRemoteUser() + +
      requested-session-idReturns the session ID specified by the client, e.g. 2344asd234sada4 +
      i.e. request.getRequestedSessionId() + +
      requested-session-id-from-cookieWhether the requested session ID is from a cookie or not +
      i.e. request.isRequestedSessionIdFromCookie() + +
      requested-session-id-from-urlWhether the requested session ID is from the URL or not +
      i.e. request.isRequestedSessionIdFromURL() + +
      requested-session-id-validWhether the requested session ID is valid or not +
      i.e. request.isRequestedSessionIdValid() + +
      request-uriReturns the part of this request's URL from the protocol name up to the query + string in the first line of the HTTP request +
      i.e. request.getRequestURI() + +
      request-urlReconstructs the URL the client used to make the request. The returned URL + contains a protocol, server name, port number, and server path, but it does not include query string parameters. +
      i.e. request.getRequestURL() + +
      session-attribute + (note, name must be set) +
      i.e. session.getAttribute([name]) + +
      session-isnew + Weather the session is new or not. +
      i.e. session.isNew() + +
      server-name + The host name of the server to which the request was sent (from the host header not the machine name). +
      i.e. request.getServerName() + +
      scheme + The scheme used for the request, e.g. http or https +
      i.e. request.getScheme() + +
      user-in-role + (Note, the value for this cannot be a regular expression) +
      i.e. request.isUserInRole([value]) + +
      name
      (optional)
      (can be anything)If type is header, this specifies the name of the HTTP header used to run the value + against.
      next
      (optional)
      and (default)The next "rule" and this "rule" must match.
      orThe next "rule" or this "condition" may match.
      operator
      (optional)
      equal (default)Equals. The operator to be used when the condition is run, the regular expression matches or the values are + equal.
      notequalNot equal to. (i.e. request value != condition value).
      greaterGreater than. (i.e. request value > condition value). Note, this operator only work with + numeric + rule types.
      lessLess than. (i.e. request value < condition value). Note, this operator only work with numeric + rule types.
      greaterorequalGreater to or equal to. (i.e. request value >= condition value). Note, this operator + only + work with numeric rule types.
      lessorequalLess than or equal to. (i.e. request value <= condition value). Note, this operator only + work with numeric rule types.
      + +

      Examples:

      + +
      +<condition name="user-agent" operator="notequal">Mozilla/[1-4]</condition>
      +
      +<condition type="user-in-role" operator="notequal">bigboss</condition>
      +
      +<condition name="host" operator="notequal">www.example.com</condition>
      +
      +<condition type="method" next="or">PROPFIND</condition>
      +<condition type="method">PUT</condition>
      +
      + + + +

      <from> element

      + +

      You must always have exactly one from for each rule or outbound-rule. Value can be a regular expression in the + Perl5 style. Note, from url's are relative to the context.

      + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      casesensitive
      (optional)
      false (default)This value will be matched using case insentitive match. ie, "/WellingtoN" will match "/wellington". +
      trueThis value will be matched using case sentitive match. ie, "/aAa" will NOT match "/aaa". +
      + +

      Example:

      + +
      +<from>^/world/([a-z]+)$</from>
      +
      + + +

      <to> element

      + +

      Value can be a regular replacement expression in the Perl5 style.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      type
      (optional)
      forward (default)Requests matching the "conditions" for this "rule", and the URL in the "from" element will be internally + forwarded + to the URL specified in the "to" element. Note: In this case the "to" URL must be in the same context as + UrlRewriteFilter. This is the same as doing: +
      RequestDispatcher rq = request.getRequestDispatcher([to value]); +
      rq.forward(request, response);
      +
      passthroughIdentical to "forward".
      redirectRequests matching the "conditions" and the "from" for this rule will be HTTP redirected. + This is the same a doing: +
      HttpServletResponse.sendRedirect([to value]))
      permanent-redirectThe same as doing: +
      response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); +
      response.setHeader("Location", [to value]);
      +
      (note, SC_MOVED_PERMANENTLY is HTTP status code 301)
      temporary-redirectThe same as doing: +
      response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); +
      response.setHeader("Location", [to value]);
      +
      (note, SC_MOVED_TEMPORARILY is HTTP status code 302)
      pre-include
      post-include
      proxyThe request will be proxied to the full url specified. commons-http and commons-codec must both be in the + classpath to use this feature. +
      last
      (optional)
      false (default)The rest of the "rules" will be processed if this one succeeds.
      trueNo more "rules" will be processed if this one is a match.
      encode
      (optional)
      false (default if under rule)response.encodeURL([to]) + will be run on the to url before performing the rewrite.
      true (default if under outbound-rule)response.encodeURL([to]) + will NOT be called.
      context
      (optional)
      If your application server is configured to allow "cross context" communication then this attribute can be used + to forward (and only forward, not redirect or other "to" types) requests to a named servlet context. +
      +
      On Tomcat, for instance, the application contexts in the server configuration (server.xml or + context.xml) need the option crossContext="true". For instance, the two applications mentioned before + ("app" and "forum") have to be defined as: +
      +
      <Context docBase="app" path="/app" reloadable="true" crossContext="true"/> +
      <Context docBase="forum" path="/forum" reloadable="true" crossContext="true"/> +
      qsappend
      (optional)
      false (default)
      trueAppend the query string to the to url when redirecting or forwarding.
      + +

      Note, "to" can be null ie, <to>null</to>, this will mean that the request will go no + further if the rule is matched (ie, this filter will not call chain.doFilter).

      + +

      If "to" is set to -, no substitution will take place and the request will go on like nothing happened (ie, this filter will call chain.doFilter).

      + +
      +<to>/world.jsp?country=$1</to>
      +
      + +

      To elements can contain backreferences and variables.

      + + +

      Backreferences

      + +
      +%N
      +
      + +

      Provides access to the grouped parts (parentheses) of the pattern from the last matched Condition + in the current rule. + N must be less than 10 and greater than 0 (i.e. %1, %2, %3 etc).

      + + +

      Variables

      + +
      +%{VARIABLE-NAME}
      +
      + +

      Any valid condition type can be used as a variable name. ie, + '%{port}' will be translated to '80', + '%{year}' to '2005', + '%{cookie:myCookie}' would be translated to + 'myCookieValue' (assuming the user had a cookie named myCookie with the value myCookieValue).

      + +

      Valid types are condition types, see condition for a full description.

      + + +

      Functions

      + +
      +${FUNCTION:PARAMS}
      +
      + +

      Functions can be places in set and to elements.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameExampleExample ReturnsExplanation
      replace${replace:my cat is a blue cat:cat:dog}my dog is a blue dog
      replaceFirst${replaceFirst:my cat is a blue cat:cat:dog}my cat is a blue dog
      escape${escape:utf8:a b c}a+b+cEscapes/Encodes string using URLEncoder.encode using the specified encoding.
      unescape${unescape:utf8:a+b+c}a b cUnescapes/Unencodes string using URLEncoder.decode using the specified encoding.
      lower${lower:Hello World}hello world
      upper${upper:hello}HELLO
      trim${trim: abc def }abc def
      + + + +

      <set> element

      + +

      Allows you to set varous things if the rule is matched.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible ValueExplanation
      type
      (optional)
      request (default)The same as request.setAttribute([name], + [value]) + (note, name must be set).
      sessionThe same as request.getSesison(true).setAttribute([name], + [value]) + (note, name must be set).
      response-headerThe same as response.setHeader([name], + [value]) + (note, name must be set).
      cookie + Value can be in the format "[value][:domain[:lifetime[:path]]]". + This sets a cookie on the client's browser. The cookie's name is specified by the name attribute. The domain + field is the domain of the cookie, such as '.apache.org',the optional lifetime is the lifetime of the cookie + in seconds, and the optional path is the path of the cookie (note, name must be set). +
      statusThe same as response.setStatus([value]) +
      content-typeThe same as response.setContentType([value]) +
      charsetThe same as response.setCharacterEncoding([value]) +
      expiresWill set the Expires HTTP header by adding the time specified and current time + (this is mod_expires style). Syntax "{num type}*". + Units can be (singular or plural); + years, months, weeks, days, hours, minutes, seconds. +
      eg, "1 day 2 seconds", "3 hours", "1 year 1 hour" +
      localeThe same as response.setLocale([value]) + + specify the Locale in the format + (valid + locales are, zh, zh-CN, zh-CN-southern i.e. "-" separating the language, country and variant (if any)). +
      parameterEnables you to override a request.getParameter(String) with a custom value
      methodEnables you to override request.getMethod() with a custom value
      name
      (optional)
      (can be anything)If type is request, session, response-header, cookie this specifies the name item.
      + +

      In the following example a request attribute "client" will be set to "AvantGo" or "Samsung SCH-6100", this can be + fetched in a servlet or + JSP using request.getAttribute("client").

      + +
      +<rule>
      +    <condition name="user-agent">Mozilla/3\.0 (compatible; AvantGo .*)</from>
      +    <from>.*</from>
      +    <set name="client">AvantGo</set>
      +</rule>
      +<rule>
      +    <condition name="user-agent">UP\.Browser/3.*SC03 .* </from>
      +    <from>.*</from>
      +    <set name="client">Samsung SCH-6100</set>
      +</rule>
      +
      + +

      It is also possible to use regular replacement expressions as part of the + value similar to their usage in <to> elements:

      + +
      +<rule>
      +    <from>/products/(.*)/(.*)/index.html</from>
      +    <set name="urlrewrite.product.slug">$1</set>
      +    <set name="urlrewrite.product.id">$2</set>
      +    <to>/products?slug=$1&id=$2</to>
      +</rule>
      +
      + + +

      <run> element

      + +

      Allows you to run a method on an object when a rule and it's conditions are matched.

      + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributePossible valueExplanation
      class The class you want to run a method on. Must be a fully qualified name.
      method (optional)run (default)The method you want to run, the method must have the parameters (HttpServletRequest, HttpServletResponse) + e.g. run(HttpServletRequest request, HttpServletResponse response) +
      Note, if init(ServletConfig) or destroy() is found they will be run at when + creating + or destroying an instance. +
      neweachtime (optional)false (default)One instance for each UrlRewriteFilter instance.
      trueA new instance of the class will be created before running each time set to true.
      + +

      When the rule in the following example is matched, WorldServlet.goGet(HttpServletRequest, + HttpServletResponse) + will be invoked, the request will then be forwarded to /world-presentation.jsp.

      + +
      +<rule>
      +    <from>^/world/[a-z]+/[a-z]+$</from>
      +    <run class="com.blah.web.WorldServlet" method="doGet" />
      +    <to>/world-presentation.jsp</to>
      +</rule>
      +
      + +

      Note, you can specify init-param's the same way you would for a servlet.

      + +
      +<run class="com.blah.web.MyServlet" method="doGet">
      +    <init-param>
      +        <param-name>someParamName</param-name>
      +        <param-value>10</param-value>
      +    </init-param>
      +</run>
      +
      + +

      If the method being called throws an Exception the original exception will be re-thrown as if it were the original + if it extends RuntimeException (eg, NullPointer), other exceptions are wrapped in a ServletException and thrown + so your container can handle them.

      + + + +

      <class-rule> element

      + +

      Allows you to run a method every time a request come in for 100% dynamic rules. See the org.tuckey.web.filters.urlrewrite.sample package for an example.

      + + + + + + + + + + + + + + + + + + +
      AttributeExplanation
      classThe class you want to run a method on. Must be a fully qualified name.
      method (optional, default matches)The method you want to run, the method must have the parameters (HttpServletRequest, HttpServletResponse) + e.g. run(HttpServletRequest request, HttpServletResponse response) +
      Note, if init(ServletConfig) or destroy() is found they will be run at when + creating or destroying an instance. +
      last (optional, default trueIf false more rules will be processed following this rule even if it is matched (so that a better match may be found).
      + +

      Example:

      + +
      +<class-rule class="com.blah.web.MyRuleClass" />
      +
      + + + +

      Tips

      + +
        +
      • When you want to put an "&" in a rule you must enter it as the XML entity "&amp;"
      • +
      • For simplicity you might want to start all from's with a ^ and end them with a $. +
        In regular expressions ^ specifies the start of + the string and $ specifies the end. +
        ie, a request for /my/url/path will NOT match + <from>^/url/$</from> but it will match <from>/url/</from> +
        +
      • If using <outbound-rule> remember all urls in your code must be encoded e.g. + <a href="<%= response.encodeURL("/some/olddir/b.jsp") %>">my link</a>
      • +
      • Regular expressions are complex and a bit tricky at times, read + regular expression syntax for + Java. +
      • +
      • If you find regular expressions difficult use Wildcards.
      • +
      • "Context" is important. If you have an app with the context "/myapp" and you request the url + "/myapp/somefolder/somepage.jsp", the container tells UrlRewriteFilter that the url is "/somefolder/somepage.jsp". + This can be confusing, but basically your rules and conditions should not contain the context path + (it will be handled by the container).
      • +
      + + + + + +

      Wildcard Matching Engine

      + +

      The wildcard matching engine can be used instead of regex. It is supported in conditions and rules + where match-type is set to wildcard (or default-match-type is set on the + urlrewrite element

      + +

      e.g. /big/url/* will match /big/url/abc.html but will NOT + match /big/url/abc/dir/ or /big/url/abc/. + +

      /big/url/** will match /big/url/abc.html, /big/url/abc/dir/ and + /big/url/abc/. + +

      You can also use Regular expression style variable replacement, each match of a * will + be available for use in to and set elements using simple $1 + $2 variables.

      + +

      e.g. /my/big/url/* will match /my/big/url/abc.html and $1 + will be set to abc.html.

      + +

      Added in 3.0

      + + + +

      Ant Task

      + +

      An Ant task has been written to allow validate the conf file and generation + of documentation. You can view a sample.

      + +

      Paste the following into your build.xml file, then change the dest + and conf to point to the correct places. Note, the urlrewrite jar + file will need to be in your classpath.

      + +
      +<target name="urlrewrite-doc" depends="compile"
      +    description="UrlRewriteFilter validation and documenting">
      +
      +<taskdef name="urlrewritedoc" classpath="lib/urlrewritefilter-5.1.3.jar"
      +    classname="org.tuckey.web.filters.urlrewrite.UrlRewriteDocTask" />
      +<urlrewritedoc
      +    conf="${build.home}/WEB-INF/urlrewrite.xml"
      +    dest="urlrewrite-conf-overview.html" />
      +</target>
      +
      + + + +

      mod_rewrite Style Configuration

      + +

      Sample web.xml snippet:

      + +
      + <filter>
      +     <filter-name>UrlRewriteFilter</filter-name>
      +     <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
      +
      +     <!-- defaults to false. use mod_rewrite style configuration file (if this is true and confPath
      +     is not specified confPath will be set to /WEB-INF/.htaccess) -->
      +     <init-param>
      +         <param-name>modRewriteConfText</param-name>
      +         <param-value><![CDATA[
      +
      +             # redirect mozilla to another area
      +             RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
      +             RewriteRule  ^/no-moz-here$                 /homepage.max.html  [L]
      +
      +         ]]></param-value>
      +     </init-param>
      +
      + </filter>
      +
      + <filter-mapping>
      +     <filter-name>UrlRewriteFilter</filter-name>
      +     <url-pattern>/*</url-pattern>
      +     <dispatcher>REQUEST</dispatcher>
      +     <dispatcher>FORWARD</dispatcher>
      + </filter-mapping>
      +
      + + +

      OR alternately set modRewriteConf to true in filter parameters and add a WEB-INF/.htaccess file with + your mod_rewrite style configuration in it.

      + +
      +<filter>
      +    <filter-name>UrlRewriteFilter</filter-name>
      +    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
      +
      +    <!-- defaults to false. use mod_rewrite style configuration file (if this is true and confPath
      +    is not specified confPath will be set to /WEB-INF/.htaccess) -->
      +    <init-param>
      +        <param-name>modRewriteConf</param-name>
      +        <param-value>true</param-value>
      +    </init-param>
      +
      +</filter>
      +
      +<filter-mapping>
      +    <filter-name>UrlRewriteFilter</filter-name>
      +    <url-pattern>/*</url-pattern>
      +    <dispatcher>REQUEST</dispatcher>
      +    <dispatcher>FORWARD</dispatcher>
      +</filter-mapping>
      +
      + +

      Sample: WEB-INF/.htaccess

      + +
      +# redirect mozilla to another area
      +RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
      +RewriteRule  ^/no-moz-here$                 /homepage.max.html  [L]
      + 
      + +

      + + Documentation for the original mod_rewrite library + mostly applies, differences are documented below.

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributeExplanation
      RewriteLogLevelSpecified as int, trasnlated as: <= 1 - FATAL, 2 - ERROR, 3 - INFO, 4 - WARN, >= 5 DEBUG
      RewriteLogSYSOUT, SYSERR, slf4j (if not set, servlet context logging will be used)
      RewriteRule + Supported but note: + + + Certain flags not supported: +
        +
      • chain flag [C] not supported
      • +
      • env flag [E] not supported
      • +
      • next flag [N] not supported
      • +
      • nosubreq flag [NS] not supported
      • +
      • Skip flag [S] not supported
      • +
      +
      RewriteBaseNot supported
      RewriteLockNot supported
      RewriteMapNot supported
      RewriteOptionsNot supported
      + + +
      +
      + + + + + + diff --git a/src/doc/manual/5.1/introduction.html b/src/doc/manual/5.1/introduction.html new file mode 100644 index 00000000..fed38b8a --- /dev/null +++ b/src/doc/manual/5.1/introduction.html @@ -0,0 +1,456 @@ + + + + UrlRewriteFilter - Background + + + + + + +
      +
      +

      + + UrlRewriteFilter 5.1.3

      +
      + +
      + + +
      + +

      Background

      + + + +

      A clean URL scheme is very important detail for any quality Web Application. UrlRewriteFilter provides a + toolkit to let you set URL patterns however you want.

      + +

      See Cool URIs don't change, by World Wide Web creator + Tim Berners-Lee, for excellent arguments on why URLs should be clean and usable.

      + +

      With the Apache webserver there is mod_rewrite for URL manipulation.

      + +

      In J2EE land the Servlet specification (by Sun) standardises the approach for dealing with Java web server +programming. We have come a long way from basic Servlets, JSP's, MVC frameworks etc but Java Web Application +Servers such as Tomcat are seldom used as front-line web servers, they almost always have Apache infront of them.

      + +

      If you want to use an app server as a front line web server UrlRewriteFilter will enable you to manage incoming +URL's in a much more flexible way than the app server usually lets you.

      + +

      You can find test cases in the source distribution. UrlRewriteFilter should work on any J2EE web application server + and has been tested using Cargo on the following web application + servers:

      + + + +

      The filter has been designed for maximum performance. Testing has indicated + that it should only slow down a request by 0.0005 of a second under normal circumstances + (depending on hardware and configuration etc.). Take a look at the source in the class + org.tuckey.web.filters.urlrewrite.PerformanceTest.testLoadsOfRules() for more information.

      + + + + +

      License

      + +

      UrlRewriteFilter is distributed under the BSD License. For more information on see + opensource.org/licenses.

      + +

      If you want to purchase ad-hoc support, a support contract or custom development + please email sales@tuckey.co.nz.

      + + + + + + +

      Changelog

      + +
        +
      • 5.1.3 +
          +
        • Fix: Add v5.1 DTD
        • +
        • Docs: Add 5.1 references for readme and docs
        • +
        +
      • +
      • 5.1.2 +
          +
        • Fix: Add 5.0 DTD
        • +
        • Docs: Add 5.0 references for readme and docs
        • +
        +
      • +
      • 5.1.1 +
          +
        • Changed to be fully based on jakarta servlet API 5
        • +
        +
      • +
      • 5.0.0 +
          +
        • Removed Annotation processor
        • +
        +
      • +
      • 4.0.5 +
          +
        • Bug fix for appending query strings breaking URL + (issue 116)
        • +
        +
      • + +
      • 4.0.4 +
          +
        • Changes to build process (not formally released)
        • +
        +
      • + +
      • 4.0.3 +
          +
        • Minor fix for identifying versions
        • +
        +
      • + +
      • 4.0.2 +
          +
        • Bug Fix for gzip filtering
        • +
        +
      • + +
      • 4.0.1 Beta +
          +
        • Rewrite of the way Encoding/Decoding is handled + (issue 27)
        • +
        • Support for file existence tests via new condition type request-filename and operators isdir, isfile, isfilewithsize, notdir, notfile, notfilewithsize + (issue 49)
        • +
        • Support for qsappend + (issue 31)
        • +
        • New condition types requested-session-id-from-cookie, requested-session-id-from-url, requested-session-id-valid
        • +
        • Ability to conditionally GZip responses using the gzip conf element
        • +
        • Fixed bug: ":" char in url results in java.io.UnsupportedEncodingException + (issue 30)
        • +
        • Fixed bug: Wildcard matcher and $ in URL causes exception + (issue 71)
        • +
        • Dropped support for log4j and commons-logging. Just use slf4j instead. This removes 2 x dependencies.
        • +
        + +
      • + +
      • 3.2.0 +
          +
        • Added "no substitution" ability with to element eg, <to>-</to>
        • +
        • In urlrewrite.xml allow rule, class-rule and outbound-rule elements in any order
        • +
        • Fixed bug with handling of references in functions (ie, to allow this: ${replace:$1:-:+} )
        • +
        • Added slf4j logging support for logLevel (filter parameter)
        • +
        • Added function for calculating string length (eg, ${length:asdf} would return 4)
        • +
        • Added "proxy" to type, to enable requests to be proxied to another server
        • +
        • Added "context" attribute to <to> type, to enable requests to sent to other contexts (assuming app server configured to do this)
        • +
        • JDK 6+ Annotation processor
        • +
        • JDK 5 & 6+ Annotation processors included in main jar file
        • +
        • Fixed bug with decoding urls and added ability to specify 'header' type decoding
        • +
        • Added allowConfSwapViaHttp filter parameter to allow configuration swap out at runtime.
        • +
        +
      • +
      • 3.1.0 +
          +
        • Rules are now allowed to have only condition and set elements
        • +
        • Basic functions in "set", and "to" elements eg, ${trim:%1}
        • +
        • Experimental mod_rewrite style configuration
        • +
        • Bug fix: xml entites containing jndi protocol now correctly loaded
        • +
        +
      • +
      • 3.0.4 Beta +
          +
        • Bug fix - cookie value not being set with variable replacement
        • +
        +
      • +
      • 3.0.3 Beta +
          +
        • Bug fix - annotation processor rule sorting
        • +
        • Bug Fix - evaluation boolean result was incorrect on failed condition instance matches
        • +
        +
      • +
      • 3.0.2 Beta +
          +
        • Rule chaining bug fixes
        • +
        +
      • +
      • 3.0.1 Beta +
          +
        • Added "class-rule" element to enable 100% dynamic "Java Rules"
        • +
        • Added experimental UrlrewriteTestCase to help with testing (see the source)
        • +
        • Added experimental "catch" element to handle exceptions generated from "run"'s
        • +
        • Added experimental annotation (@HttpUrl, @HttpParam) processor
        • +
        • Minor Bug fixes
        • +
        +
      • +
      • 3.0 Beta +
          +
        • Support for wildcard matching.
        • +
        • Added "match-type" attribute to rule and outbound-rule.
        • +
        • Added ability to specify charset decoding ("decodeusing" attribute to "urlrewrite" element)
        • +
        • Swapped "to" variable replacement and run processing, run processing now comes before "to" + variable replacement is done. dtd it has been swapped make sure you change the reference in your conf file. + Make sure element order is from, set, run, to.
        • +
        • Context addition to the url is now optional
        • +
        • Query string matching on rule is now optional (defaults to false) +
          before 3.0 you would specify +
          <from>/blah.jsp?a=b</from> +
          3.0 and up (unless use-query-string on urlrewrite element is set to true) +
          <condition name="a">b</condition> +
          <from>/blah.jsp</from>
        • +
        +
      • +
      • 2.6 +
          +
        • fixed bug with encode on to element defaulting to incorrect boolean (change to dtd)
        • +
        +
      • +
      • 2.5.3 +
          +
        • cleaner exception handling when invoking "run" items, original exception thrown as if it were the + original if it extends RuntimeException (eg, NullPointer), other exceptions wrapped in a ServletException and thrown
        • +
        +
      • +
      • 2.5.2 +
          +
        • fixed bug with encodefirst attr not being set
        • +
        • ability to specify wildcards on statusEnabledOnHosts
        • +
        • added backreferences and variables for to element value
        • +
        • logLevel init param can now include sysout:{level} ie, sysout:DEBUG for people who have trouble with context.log
        • +
        +
      • +
      • 2.5.1 +
          +
        • bug fixes, Log initialisation and null auth type condition values
        • +
        +
      • +
      • 2.5 +
          +
        • matcher changed to accept first match (not the whole string) please make sure you retest your rules + (ie, previously /res/js/l.js?aaa would not match /res/js/l.js, with this release it will)
        • +
        • support for logging to log4j or commons-logging (see filter params in manual)
        • +
        • fixed bug for when request.getCookies() returns null on some containers
        • +
        • added encodefirst outbound-rule, outbound-rule now respects encode on "to".
        • +
        + +
      • +
      • 2.4 +
          +
        • removed all external library dependencies to make much more deploy friendly
        • +
        • no longer uses Jakarta ORO, this should't mean any change in regular expression handling but you should test + your existing rules just in case.
        • +
        • fixed problem with rediredting to "null" this will now not proceed with the request if the rule is matched + (ie, chain.doFilter will not be called)
        • +
        • fixed problem with ant dependency on status page
        • +
        +
      • +
      • 2.3 (4/2005) +
          +
        • Added new outbound-rule for rewriting hyperlinks in JSP's, improved status page, added ability + to run methods when a rule is matched
        • +
        +
      • +
      • 2.0.1 (2/2005) +
          +
        • Fixed bug with rule processing when to element doesn't exist.
        • +
        +
      • +
      • 2.0 (1/2005) +
          +
        • Minor bug fixes, last attribute on rule now defaults to false (thanks to Vineet Kumar for his + assistance).
        • +
        +
      • +
      • 2.0-beta (12/2004) +
          +
        • Minor bug fixes, documentation improvements, ALL matches now done case insensitively by + default, case sensitivity can be set (see from and condition elements).
        • +
        +
      • +
      • 2.0-alpha (11/2004) +
          +
        • First 2.0 release, added many new condition types, many new set types.
        • +
        +
      • +
      • 1.2 (6/2004) +
          +
        • Added set element (ability to set random attributes on request, thanks for the idea + Russell), from now matches RELATIVE to context NOT root (if you + are upgrading this may mean a change for you).
        • +
        +
      • +
      • 1.1 (4/2004) +
          +
        • Ability to disable rules, Refactored to enable rewriter to be embedded, + changed logging to enable log level to be set, added name and note elements to rule for documentation, + ability to disable status page, ability to change status prefix, javadoc style ant task for an HTML + configuration report.
        • +
        +
      • +
      • 1.0 (3/2004) +
          +
        • General tidy up of logging, tidy up of all code, dist now includes manual, log4j and junit + removed from bin release.
        • +
        +
      • +
      • 0.9 (2/2004) +
          +
        • Fixed conf loading problem in Resin, resolved concurrency issue with Perl5Compiler and + Perl5Matcher (thanks Scott Askew!)
        • +
        +
      • +
      • 0.8 (2/2004) +
          +
        • Removed dependency on "Commons Lang", Changed DTD path (bug fix), added ability to put time + fields in "condition" element, added ability to put "operators" in the "condition" element, fixed multiple rules issue (bug fix)
        • +
        +
      • +
      • 0.7 (11/2003) +
          +
        • Improved test cases, documentation
        • +
        +
      • +
      • 0.6 (8/2003) +
          +
        • Improved error handling, status page and condition matching
        • +
        +
      • +
      • 0.5 (6/2003) +
          +
        • Improved configuration error handling
        • +
        +
      • +
      + + + +
      +
      + + + + + + diff --git a/src/doc/manual/5.1/urf-100.png b/src/doc/manual/5.1/urf-100.png new file mode 100644 index 0000000000000000000000000000000000000000..3d569a431525650c96e7eb0917e3799863a8347f GIT binary patch literal 3530 zcmV;*4K?zKP)Px#32;bRa{vGjVE_ORVF9Q=r)dBH00(qQO+^RX2MGi)47d3=Y5)KYTuDShRCwC$ zoO^Io)g8xwzjNRFNOm``&E}mD0wkb<3J4ZoV10n4Dvpm1ZMC+J9oyQDojUDI`NOH5 zv9>dow$o~-)tRClE0%&UR1{DV@qs*r5CVB;H;>IGcVG9O(?2f6kX^{l=596{b0))V zE}MIQ=d<76@BGg1oU_OngKTSzF+|iU+xdC-f8TGrsK#~KY)@^86AAJJ3Bi$Xv+%i? zb+8Ns!J*ie58D3uMl(UsDbsXT;F1K?)euj1Dkf7 z+I7G$@?@9=rA*UlD6Dxs%Gc%>ES{Txd7WDnI13HnvyRmEk30YM_Nf-XI+7FsAc7+C z-&j_80!xi* z&%Aarq-sCCZSLj`%i|hNqzM2Wz2TAnWo>}Z8fDoe{(;rAhJT%1n$y@8;<$5I5QMJ2 z$Y5A=JH>R^kTuF0)#jAv=#(XjtE(?E7}3)7(5!`3=1hb|5L*3eNR7|HI;Sm~?TIA| zTWVBq3xv~@4`n4R#+Y5^N(*d>;^GK4cMfU#46G3fLd0T^Oq0PnIRh&(Jk2gm7PbhU z=m=?)ro$7n6&6RZp)yy~Y2x*kZnb|fW^IO*-LMd`I8TuTE>S_EK#rUW&A8z?%`WrB z9wosMfgrZ})frglG)3fm`ATAp=Q;fJMBfaobDBfpYkUsMk_?EAZ8L6oZWDM??2!>* zRMHzwplK zFIopeVJ)sv#@KX#wV>La)YT$!y)6(~ zX89aRuSa9Fy+=(sY`y$mTTG)4h3^@NKKEvGNR3YiSYD4TCsY9ukunw-h$SupnMvPv ze%}4}*P7I*Mi2#_vuw0Wp;&JyR#s>;f47$Ip=Vxg>K}{|f{ZauXE!b` z{@#r>fnanxxFG<{Eze1;0wO>xPGg#GUZMVA?*aa_qvxx6P?2vJX#~h_&G(5R6PRHAIYQ^mi{FF*-S_ zNdl2X&Wx=7yyf`TJ?*kU5Row!)9A16sb5g-8acJJIKXe(aeDo#s-&gfakaQcH@$sY z97_~BWo-d<@6jGLswWDIG03$GxprYpQZMald1Y^h@tQHFQ})<*7c^Anrnl-4*XVQG zn;*QTc7pebX>{Y3V`iWu0!NI^4>*bfV^HmLRD10gz=VkVj`cqO&S_1j1}Vzm&TA?z ztMiN;ZPPM06nL`j!}jie3!G8liJ2dsBj-!dC6Uapa&a6JsNpDNi5pkb>r3tLw&zaf;d(|RuQcDbcoxS0|Y;A1ut2{>lfB`J5b>Dq$C4U~i z*25x*pB(Q!)*8yx_-H(rSQs=W{9&foBj5MBL_|fWsx(&pUL!x4=ik`awXN&*_5hr|A~HMWT1@kJU)K!0+&O)uq#+R8V-LX zoqge52fF8#=Ma*jxOB>N(;N60Fj?es?ZV>brd^D~+yZz+m-K~aUlroOs zqj%1$EzKFTTF;;AvTRR)EOH@LV`sK8!g~h;D;IfZ`J5@-iX(W%ynIFC%xMZ-cA=`+ zv9Q)%UF=94@<(3T@mbgZK4@bA2tXMVc=GM*tCq~mHxo4Y-)uT;VQ3EwM9;p4_MY(W z1OCb)yP@`R-AWS3hV}DJ{t;s^@^ng4ffyHeeAcyb%khDsxG~;wh&L|wtyx+^5X~$C z@y(q>mb;;m?1?;i`MtKAmz3n^N-0cYlAg{PGZ#-3$Z+!c^s6Vf?P*t|x{)YQ2KAM> zKe)LD&5;5CKINEV23$yuzqGsc{+ntnKPP#?w3tS_`y+dg_U<_n=zjPTD`R7o6Ac@o}{4kw8Jt^em}dt`ImRsn>S9UZ2yUVr!5up2qNH@ zQKS0WWu>c^`ev0lQ_$2T!7|J})Eqq29IUU*HE$)yp)qWwp3nnmIs;(ytK9eAP(8cE zA)cuhrx-maX?3S>F!uVsj{3@6^H!$N9RvUz{+ATGq?L<`ufNRec8DYAIw_AclK~46 zDP^txa3B~pnRD?Ru3l0ii{m&u&wwc+Uz)FYa-?F9;$uVq+Vs+%06S1t19+C`WG<G5kNkyT(yvSykd8fiV6yD_! zIdk826p86??CZGt;v!$3l1W&Mv1nZX?$@gk#+@+-hvKb%RT^uNwbc*oWIqF-l<5>C zf%x*2Vvkbcwbhn5%L;6jUdQ=vVwiNIeQ@`|z}FTOno1oKPtH!T{)c!*M4HYTDqWY( z_M{Nk2_nZKH&zDECG@|uFVfK){^(ebL*_j>QlU$lSCPAFk+=A)a7N}6agFXh+S4;& zcE--1Z}(~{qzHERM?$J**hCpyyS&7q@RL@YK|~G#0C^5#8tv>2cl3r2pBmWqVS7oQ zvhJ$#%j-PG2Vj^KQsX-h_&L+X4SwT8ms)7)FQRl6H1U75-i&d3Kq zr))5+9c>xd@a(}{yYQ`*Ro7fnsE8b6>|k^7MEjs9kVwpwd+}DssWUGGjx3*_U*wjj zNQz+0c7kgBiGLq??#+|eE%e^B*!SYjR#_x!RM#oX0IcCwQDncep#akG#d{MBsWzDp z4#xlW)~PM;w?$&Qz!L=BqTV{H5mY2DuG8Vv#N4dm=D#uPSE zBt&}X>WeVO#&kz3VKK&xEwdAs)%@z*+vDX)Pl_8Mrn4^+2u3J{7Qbp7N8$)_9FmkC zO(uW&-YVB)j4i7#SXN(P^8M{SYD;(cqc3{*9qZ}pix_4MZ*&;*S>_}BR6OW3F6fLg zU!KjEXInfs51_WyufFwZ*Y1P<{=xWQI8G@Wu7aG8R6}L%UDs5YS)-gLr^1HkRiy>C z^{cAZud3Q}q-W3Jz@g^gX}?N!%5zCJ$^*dF7Z=@kL$xPI%2s7rLT$<1yd`tdYznIikMrVcWXQ{4G^H#t+kr3EhevG2?;FS1Xq{aI7TH#fa~isz6q zHm5A-(Yx!tZrS8;`4xg?2ihPp zD&ySKl-_cbL0P?jD9{&*J+f}jl6m + + +UrlRewriteFilter configuration overview for urlrewrite.xml + + +

      UrlRewriteFilter 5.1.3 build 0d262f7db8cf16b93623a16961666e3ac904a7de configuration overview (generated 1/10/23 12:18 PM)

      +
      +

      Summary + of urlrewrite.xml +

      +

      In total there are 13 rules, 3 outbound rules and 12 conditions in the configuration file.

      +

      Test Rule1 (rule 0)

      +

      A test rule to show a simple redirect.

      +

      URL's matching /test/status/ will be redirected to /rewrite-status.

      +

      This rule and it's conditions will use the regex matching engine.

      Note, other rules will be processed after this rule.

      + + +

      Bild redirect test (rule 1)

      +

      URL's matching logo.gif will permanent-redirect to http://127.0.0.1:8080/urlrewrite/artifact_type.gif.

      +

      This rule and it's conditions will use the regex matching engine.

      Note, other rules will be processed after this rule.

      + + +

      Products (rule 2)

      +

      Allows users to type product id's into urls.
      ID's published in magazine.

      +

      URL's matching /products/*/*/ will be forwarded to /products.jsp.

      +

      This rule and it's conditions will use the regex matching engine.

      This rule will set:

        +
      1. +An attribute on the request object called categoryId to the value null +
      2. +
      3. +An attribute on the request object called usingFilter to the value yes +
      4. +
      +

      Note, other rules will be processed after this rule.

      + + +

      Rule 3

      +

      URL's matching /chairs/*/ will be forwarded to /products/chairs.jsp.

      +

      This rule and it's conditions will use the regex matching engine.

      This rule will set:

        +
      1. +An attribute on the session object called chairShopper to the value true +
      2. +
      +

      Note, other rules will be processed after this rule.

      + + +

      Test Rule disabled (rule 4) **DISABLED**

      +

      URL's matching /test/disabled/ will be redirected to /rewrite-status.

      +

      This rule and it's conditions will use the regex matching engine.

      Given that the following conditions are met.

        +
      1. +The user-agent HTTP header does NOT match the value mac +and +
      2. +
      3. +dayofmonth is equal to the value 14 +and +
      4. +
      5. +The charset HTTP header matches the value utf +and +
      6. +
      7. +user-in-role admin is equal to the value admin +
      8. +
      +

      Note, other rules will be processed after this rule.

      + + +

      Test Rule with sets (rule 5)

      +

      URL's matching /test/disabled/.

      +

      This rule and it's conditions will use the regex matching engine.

      Given that the following condition is met.

        +
      1. +The user-agent HTTP header does NOT match the value mac +
      2. +
      +

      This rule will set:

        +
      1. +An attribute on the request object called blah to the value ass +
      2. +
      3. +The cache-control HTTP response header to ass +
      4. +
      +

      Note, other rules will be processed after this rule.

      + + +

      Rule 6

      +

      URL's matching /test-set/([0-9]+) will be forwarded to /test-set.jsp.

      +

      This rule and it's conditions will use the regex matching engine.

      Given that the following condition is met.

        +
      1. +The user-agent HTTP header does NOT match the value mac +
      2. +
      +

      This rule will set:

        +
      1. +An attribute on the request object called num to the value num +
      2. +
      +

      This rule will run:

        +
      1. + run on an instance of org.tuckey.web.filters.urlrewrite.test.TestRunObj +
      2. +
      3. + run on an instance of org.tuckey.web.filters.urlrewrite.test.TestRunObj +
      4. +
      5. + nonDefaultRun on an instance of org.tuckey.web.filters.urlrewrite.test.TestRunObj +
      6. +
      7. + nonDefaultRun on an instance of org.tuckey.web.filters.urlrewrite.test.TestRunObj + (a new instance will be created for each rule match) +
      8. +
      9. + nonDefaultRun on an instance of org.tuckey.web.filters.urlrewrite.test.TestRunObj + (a new instance will be created for each rule match) +
      10. +
      +Note, if init(ServletConfig) or destroy() is found on the above objects they will be run at when creating or destroying an instance. +

      Note, other rules will be processed after this rule.

      + + +

      Rule 7

      +

      URL's matching /content/([a-zA-Z]+).

      +

      This rule and it's conditions will use the regex matching engine.

      This rule will set:

        +
      1. +An attribute on the request object called contentItem to the value $1 +
      2. +
      +

      This rule will run:

        +
      1. + doGet on an instance of org.tuckey.web.filters.urlrewrite.TestServlet +
      2. +
      +Note, if init(ServletConfig) or destroy() is found on the above object they will be run at when creating or destroying an instance. +

      Note, other rules will be processed after this rule.

      + + +

      Rule 8

      +

      URL's matching /pref/([a-zA-Z]+).

      +

      This rule and it's conditions will use the regex matching engine.

      Given that the following condition is met.

        +
      1. +method is equal to the value POST +
      2. +
      +

      This rule will run:

        +
      1. + doPost on an instance of org.tuckey.web.filters.urlrewrite.TestServlet +
      2. +
      +Note, if init(ServletConfig) or destroy() is found on the above object they will be run at when creating or destroying an instance. +

      Note, other rules will be processed after this rule.

      + + +

      Rule 9

      +

      URL's matching /test-redirect-301 will permanent-redirect to /is-this-301.

      +

      This rule and it's conditions will use the regex matching engine.

      Note, other rules will be processed after this rule.

      + + +

      Rule 10

      +

      URL's matching /test-redirect-302 will temporary-redirect to is-this-302.

      +

      This rule and it's conditions will use the regex matching engine.

      Note, other rules will be processed after this rule.

      + + +

      Rule 11

      +

      URL's matching /test-redirect-302 will temporary-redirect to is-this-302.

      +

      This rule and it's conditions will use the regex matching engine.

      Given that the following condition is met.

        +
      1. +user-in-role devil is equal to the value devil +
      2. +
      +

      Note, other rules will be processed after this rule.

      + + +

      filenamecheck (rule 12)

      +

      URL's matching /check-uw-config-exists.txt will be forwarded to /test-set.jsp.

      +

      This rule and it's conditions will use the regex matching engine.

      Given that the following condition is met.

        +
      1. +request-filename is the value null +
      2. +
      +

      This rule will set:

        +
      1. +An attribute on the request object called test1 to the value file exists!!! +
      2. +
      +

      Note, other rules will be processed after this rule.

      + + +

      Out test 1 (outbound rule 0)

      +

      Outbound URL's matching /page-not-for-devils(0-9)? will be rewritten to /devils-page, after response.encodeURL() has been called.

      +

      Given that the following condition is met.

        +
      1. +user-in-role devil is equal to the value devil +
      2. +
      +

      Note, other outbound rules will be processed after this rule.

      + + +

      Outbound Rule 1

      +

      Outbound URL's matching ^(.*);jsessionid=.*$ will be rewritten to $1.

      +

      Given that the following condition is met.

        +
      1. +The user-agent HTTP header matches the value googlebot.* +
      2. +
      +

      Note, other outbound rules will be processed after this rule.

      + + +

      Outbound Rule 2

      +

      Outbound URL's matching *;jsessionid=* will be rewritten to $1, after response.encodeURL() has been called.

      +

      Given that the following condition is met.

        +
      1. +The user-agent HTTP header matches the value googlebot* +
      2. +
      +

      Note, other outbound rules will be processed after this rule.

      + + +
      +


      + + diff --git a/src/doc/manual/5.1/urlrewrite.xml b/src/doc/manual/5.1/urlrewrite.xml new file mode 100644 index 00000000..ddf91d51 --- /dev/null +++ b/src/doc/manual/5.1/urlrewrite.xml @@ -0,0 +1,97 @@ + + + + + + + + + The rule means that requests to /test/status/ will be redirected to /rewrite-status + the url will be rewritten. + + /test/status/ + %{context-path}/rewrite-status + + + + + + The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url) + the url /rewrite-status will be rewritten to /test/status/. + + The above rule and this outbound-rule means that end users should never see the + url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks + in your pages. + + /rewrite-status + /test/status/ + + + + + + + diff --git a/src/doc/manual/guide.html b/src/doc/manual/guide.html index 8815796f..6b965508 100644 --- a/src/doc/manual/guide.html +++ b/src/doc/manual/guide.html @@ -7,7 +7,7 @@ -

      Latest Guide

      +

      Latest Guide

      Version 4.0 Guide

      diff --git a/src/doc/manual/index.html b/src/doc/manual/index.html index 78304b97..dbe4c8ef 100644 --- a/src/doc/manual/index.html +++ b/src/doc/manual/index.html @@ -7,7 +7,7 @@ -

      Latest Documentation

      +

      Latest Documentation

      Version 4.0 Documentation

      diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java b/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java index ef32729b..62b44c9d 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/ConfHandler.java @@ -51,14 +51,14 @@ */ public class ConfHandler extends DefaultHandler { - private static Log log = Log.getLog(ConfHandler.class); + private static final Log log = Log.getLog(ConfHandler.class); // pattern to match file://, http://, jndi:// private static final Pattern HAS_PROTOCOL = Pattern.compile("^\\w+:"); - private String confSystemId; + private final String confSystemId; - private static Hashtable dtdPaths = new Hashtable(); + private static final Hashtable dtdPaths = new Hashtable<>(); static { dtdPaths.put("-//tuckey.org//DTD UrlRewrite 1.0//EN", "/org/tuckey/web/filters/urlrewrite/dtds/urlrewrite1.0.dtd"); @@ -73,6 +73,7 @@ public class ConfHandler extends DefaultHandler { dtdPaths.put("-//tuckey.org//DTD UrlRewrite 3.3//EN", "/org/tuckey/web/filters/urlrewrite/dtds/urlrewrite3.3.dtd"); dtdPaths.put("-//tuckey.org//DTD UrlRewrite 4.0//EN", "/org/tuckey/web/filters/urlrewrite/dtds/urlrewrite4.0.dtd"); dtdPaths.put("-//tuckey.org//DTD UrlRewrite 5.0//EN", "/org/tuckey/web/filters/urlrewrite/dtds/urlrewrite5.0.dtd"); + dtdPaths.put("-//tuckey.org//DTD UrlRewrite 5.1//EN", "/org/tuckey/web/filters/urlrewrite/dtds/urlrewrite5.1.dtd"); } public ConfHandler(String confSystemId) { @@ -97,7 +98,7 @@ public InputSource resolveEntity(String publicId, String systemId) } return new InputSource(systemId); } - String entity = (String) dtdPaths.get(publicId); + String entity = dtdPaths.get(publicId); if (entity == null) { if (log.isDebugEnabled()) { diff --git a/src/test/webapp/WEB-INF/urlrewrite.xml b/src/test/webapp/WEB-INF/urlrewrite.xml index 3a132963..3072f45e 100644 --- a/src/test/webapp/WEB-INF/urlrewrite.xml +++ b/src/test/webapp/WEB-INF/urlrewrite.xml @@ -1,6 +1,6 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2eed91f2602c072ab48e73fd75addb91088bd031 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 20 Oct 2023 09:35:22 +1300 Subject: [PATCH 3/5] remove unused annotation processor --- annotation/build.xml | 54 -- annotation/pom.xml | 118 ----- .../annotation/HttpExceptionHandler.java | 48 -- .../urlrewrite/annotation/HttpJson.java | 59 --- .../urlrewrite/annotation/HttpParam.java | 65 --- .../urlrewrite/annotation/HttpUrl.java | 59 --- .../annotation/HttpUrlAPTFactory.java | 98 ---- .../HttpUrlAnnotationProcessor.java | 392 --------------- .../ProcessorServiceLoaderCheck.java | 19 - .../UrlRewriteAnnotationProcessor.java | 469 ------------------ .../filters/urlrewrite/json/JSONRPCBean.java | 65 --- .../urlrewrite/json/JSONRPCErrorBean.java | 73 --- ....sun.mirror.apt.AnnotationProcessorFactory | 1 - .../javax.annotation.processing.Processor | 1 - .../annotation/SampleMatchAction.java | 121 ----- 15 files changed, 1642 deletions(-) delete mode 100644 annotation/build.xml delete mode 100644 annotation/pom.xml delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpExceptionHandler.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpJson.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpParam.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrl.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAPTFactory.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAnnotationProcessor.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/ProcessorServiceLoaderCheck.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/UrlRewriteAnnotationProcessor.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCBean.java delete mode 100644 annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCErrorBean.java delete mode 100644 annotation/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory delete mode 100644 annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor delete mode 100644 annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java diff --git a/annotation/build.xml b/annotation/build.xml deleted file mode 100644 index 6c820c16..00000000 --- a/annotation/build.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/annotation/pom.xml b/annotation/pom.xml deleted file mode 100644 index 330e31e8..00000000 --- a/annotation/pom.xml +++ /dev/null @@ -1,118 +0,0 @@ - - - 4.0.0 - org.tuckey - urlrewritefilter-annotation - jar - 5.0.0 - UrlRewriteFilter Annotation - http://www.tuckey.org/urlrewrite/ - 2006 - - Add-on to urlrewritefilter to support annotations - - - - UTF-8 - - - - - BSD - http://www.opensource.org/licenses/bsd-license.php - repo - - - - - scm:git:https://github.com/paultuckey/urlrewritefilter.git - scm:git:https://github.com/paultuckey/urlrewritefilter.git - https://github.com/paultuckey/urlrewritefilter - - - - https://github.com/paultuckey/urlrewritefilter/issues - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.5 - 1.5 - -proc:none - - - - - - - - com.sun - tools - 1.6.0 - system - ${java.home}/../lib/tools.jar - - - junit - junit - 4.13.1 - compile - - - javax.servlet - servlet-api - 2.4 - test - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.5 - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.2 - - - jakarta - package - - shade - - - jakarta - true - false - - - ${project.groupId}:${project.artifactId} - - - - - javax.servlet - jakarta.servlet - - - javax.annotation - jakarta.annotation - - - - - - - - - - \ No newline at end of file diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpExceptionHandler.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpExceptionHandler.java deleted file mode 100644 index 81522f84..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpExceptionHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.METHOD) -public @interface HttpExceptionHandler { - - String value() default "[ unassigned ]"; - -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpJson.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpJson.java deleted file mode 100644 index ed6e3c96..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpJson.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A marker annotation for allowing a method to be called via HTTP and the results to be returned as JSON. - */ -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.METHOD) -public @interface HttpJson { - - String value() default "[ unassigned ]"; - - /** - * A weighting to be applied to the url, if higher it will move this url to the "top" if lower more towards the - * "bottom". - * - * @return weight - */ - int weight() default 0; - -} \ No newline at end of file diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpParam.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpParam.java deleted file mode 100644 index 90b6f092..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpParam.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for matching parameters in HTTP requests. - *

      - * Usage: - *

      - * \@HttpUrl("^/search/(people|objects)/$") - * public void someMethod(@HttpParam("fName") String firstName, @HttpParam String lastName) - * for the request /search/people/?fName=bob&lastName=smith - * will invoke the method with someMethod("bob", "smith", "people") - * to be used in conjunction with @HttpUrl - */ -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.PARAMETER) -public @interface HttpParam { - - /** - * If not set will use the name of the parameter (case insensitive). - * can be a expression ie, $1 (the first group of @HttpUrl regexp), %{header:user-agent} (the user agent header). - * - * @return value - */ - String value() default "[ unassigned ]"; - -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrl.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrl.java deleted file mode 100644 index 8abb049b..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrl.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for matching URL's in HTTP requests. - */ -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.METHOD) -public @interface HttpUrl { - - String value(); - - /** - * A weighting to be applied to the url, if higher it will move this url to the "top" if lower more towards the - * "bottom". - * - * @return weight - */ - int weight() default 0; - -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAPTFactory.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAPTFactory.java deleted file mode 100644 index 299dfa19..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAPTFactory.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import com.sun.mirror.apt.AnnotationProcessor; -import com.sun.mirror.apt.AnnotationProcessorEnvironment; -import com.sun.mirror.apt.AnnotationProcessorFactory; -import com.sun.mirror.apt.AnnotationProcessors; -import com.sun.mirror.declaration.AnnotationTypeDeclaration; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -/** - * Annotation Processor Factory for UrlRewriteFilter annotations. - * - * @deprecated Use UrlRewriteAnnotationProcessor - */ -public class HttpUrlAPTFactory implements AnnotationProcessorFactory { - - /** - * Returns a note annotation processor. - * - * @return An annotation processor for note annotations if requested, - * otherwise, returns the NO_OP annotation processor. - */ - public AnnotationProcessor getProcessorFor(Set declarations, - AnnotationProcessorEnvironment env) { - AnnotationProcessor result; - if (declarations.isEmpty()) { - result = AnnotationProcessors.NO_OP; - } else { - result = new HttpUrlAnnotationProcessor(env); - } - return result; - - } - - /** - * This factory only builds processors for all UrlRewrite annotations. - * - * @return a collection containing only the note annotation name. - */ - public Collection supportedAnnotationTypes() { - Set set = new HashSet(); - set.add(HttpUrl.class.getName()); - set.add(HttpExceptionHandler.class.getName()); - set.add(HttpParam.class.getName()); - return set; - } - - /** - * Options supported by this annotation processor. - * - * @return collection of options. - */ - public Collection supportedOptions() { - Set set = new HashSet(); - set.add("-AsaveRulesTo"); - set.add("-AshowPositions"); - set.add("-Adebug"); - return set; - } -} - diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAnnotationProcessor.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAnnotationProcessor.java deleted file mode 100644 index d38a0316..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/HttpUrlAnnotationProcessor.java +++ /dev/null @@ -1,392 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import com.sun.mirror.apt.AnnotationProcessor; -import com.sun.mirror.apt.AnnotationProcessorEnvironment; -import com.sun.mirror.apt.Filer; -import com.sun.mirror.apt.Messager; -import com.sun.mirror.declaration.AnnotationTypeDeclaration; -import com.sun.mirror.declaration.Declaration; -import com.sun.mirror.declaration.MethodDeclaration; -import com.sun.mirror.declaration.ParameterDeclaration; -import com.sun.mirror.util.SourcePosition; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - - -/** - * Annotation processor for UrlRewrite. Will search compiled classes for annotations and generate XML. - *

      - * Processor for JDK 1.5. - * - * @deprecated use UrlRewriteAnnotationProcessor. - */ -public class HttpUrlAnnotationProcessor implements AnnotationProcessor { - - private AnnotationProcessorEnvironment environment; - private AnnotationTypeDeclaration httpUrlDeclaration; - private AnnotationTypeDeclaration httpExceptionHandlerDeclaration; - private List processedAnnotations = new ArrayList(); - private List httpExceptionHandlers = new ArrayList(); - private Messager messager; - private boolean showPositionsOfAnnotations = false; - private boolean debug = false; - - public HttpUrlAnnotationProcessor(AnnotationProcessorEnvironment env) { - environment = env; - messager = env.getMessager(); - // get the type declaration for the annotations we are processing for - httpUrlDeclaration = (AnnotationTypeDeclaration) environment.getTypeDeclaration(HttpUrl.class.getName()); - httpExceptionHandlerDeclaration = (AnnotationTypeDeclaration) environment.getTypeDeclaration(HttpExceptionHandler.class.getName()); - } - - public void process() { - Map options = environment.getOptions(); - Set keys = options.keySet(); - String saveRulesTo = null; - for (String key : keys) { - if (key.startsWith("-AsaveRulesTo=")) { - saveRulesTo = key.substring("-AsaveRulesTo=".length()); - } - if (key.startsWith("-AshowPositions=")) { - showPositionsOfAnnotations = "true".equalsIgnoreCase(key.substring("-AshowPositions=".length())); - } - if (key.startsWith("-Adebug=")) { - debug = "true".equalsIgnoreCase(key.substring("-Adebug=".length())); - } - } - debugMsg("Processing"); - if (saveRulesTo == null) { - messager.printError("ERROR: conf option must be specified"); - return; - } - - File confFile = new File(saveRulesTo); - PrintWriter pw; - boolean delFile = false; - try { - if (!confFile.exists()) { - if ( ! confFile.createNewFile() ) { - checkDirsExistMkdir(confFile.getParentFile()); - confFile.createNewFile(); - } - } - if (!confFile.canWrite()) throw new IOException("cannot write to " + confFile.getName()); - pw = environment.getFiler().createTextFile(Filer.Location.CLASS_TREE, "", confFile, null); - } catch (IOException e) { - e.printStackTrace(); - return; - } - try { - - // Get all declarations that use the HttpUrl annotation. - debugMsg("Looking for @HttpUrl"); - Collection urlDeclarations = environment.getDeclarationsAnnotatedWith(httpUrlDeclaration); - for (Declaration declaration : urlDeclarations) { - ProcessedHttpUrlAnnotation pa = processHttpUrlAnnotation(declaration); - if (pa == null) delFile = true; - else processedAnnotations.add(pa); - } - - // Get all declarations that use the HttpExceptionHandler annotation. - debugMsg("Looking for @HttpExceptionHandler"); - Collection exceptionDeclarations = environment.getDeclarationsAnnotatedWith(httpExceptionHandlerDeclaration); - for (Declaration declaration : exceptionDeclarations) { - ProcessedHttpExceptionAnnotation phea = processHttpExceptionHandlerAnnotation(declaration); - if (phea == null) delFile = true; - else httpExceptionHandlers.add(phea); - } - - if (processedAnnotations.size() > 0) { - messager.printNotice("Got " + processedAnnotations.size() + " @HttpUrl annotations"); - Collections.sort(processedAnnotations); - } - if (httpExceptionHandlers.size() > 0) { - messager.printNotice("Got " + httpExceptionHandlers.size() + " @HttpExceptionHandler annotations"); - Collections.sort(httpExceptionHandlers); - } - - if (!delFile) { - environment.getMessager().printNotice("Writing to " + confFile); - outputRules(pw); - outputExceptionHandlers(pw); - - } else { - confFile.delete(); - } - - } catch (Throwable t) { - delFile = true; - t.printStackTrace(); - } - if (delFile) { - messager.printError("Error occured during processing deleting generated file."); - confFile.delete(); - } - - pw.close(); - } - - private void outputRules(PrintWriter pw) { - for (ProcessedHttpUrlAnnotation pa : processedAnnotations) { - pw.println(""); - pw.println(" " + pa.sourceRef + ""); - if (!isBlank(pa.docComment)) { - pw.println(" "); - pw.println(padEachLine(" ", escapeXML(pa.docComment))); - pw.println(" "); - } - pw.println(" " + pa.value + ""); - pw.println(" "); - if (!pa.chainUsed) { - pw.println(" null"); - } - pw.println(""); - pw.flush(); - } - } - - private void outputExceptionHandlers(PrintWriter pw) { - for (ProcessedHttpExceptionAnnotation pa : httpExceptionHandlers) { - pw.println(""); - if (!isBlank(pa.docComment)) { - pw.println(" "); - pw.println(padEachLine(" ", escapeXML(pa.docComment))); - pw.println(" "); - } - pw.println(" "); - pw.println(""); - pw.flush(); - } - } - - private ProcessedHttpUrlAnnotation processHttpUrlAnnotation(Declaration declaration) { - HttpUrl httpUrl = declaration.getAnnotation(HttpUrl.class); - return new ProcessedHttpUrlAnnotation(HttpUrl.class.getName(), declaration, httpUrl.value(), httpUrl.weight()); - } - - private ProcessedHttpExceptionAnnotation processHttpExceptionHandlerAnnotation(Declaration declaration) { - SourcePosition position = declaration.getPosition(); - if (!(declaration instanceof MethodDeclaration)) { - messager.printWarning(declaration.getPosition(), "@HttpExceptionHandler declared on a non-method " + position); - return null; - } - MethodDeclaration methodDeclaration = (MethodDeclaration) declaration; - HttpExceptionHandler httpExceptionHandler = declaration.getAnnotation(HttpExceptionHandler.class); - String className = methodDeclaration.getDeclaringType().getQualifiedName(); - - ProcessedHttpExceptionAnnotation ea = new ProcessedHttpExceptionAnnotation(); - ea.exceptionName = httpExceptionHandler.value(); //.getName(); - ea.methodName = declaration.getSimpleName(); - ea.docComment = declaration.getDocComment(); - ea.className = className; - - ea.setParams(methodDeclaration.getParameters()); - - // out exceptionName might not be set - if ("[ unassigned ]".equals(ea.exceptionName) && methodDeclaration.getParameters().size() > 0) { - // use first param - ea.exceptionName = methodDeclaration.getParameters().iterator().next().getType().toString(); - } - - if (showPositionsOfAnnotations) { - messager.printNotice(position, "@HttpExceptionHandlerUrl value " + ea.value + " weight " + ea.weight); - } - return ea; - } - - class ProcessedHttpUrlAnnotation implements Comparable { - public int weight = 0; - public String value; - public boolean chainUsed; - public String paramsFormatted; - public String methodName; - public String className; - public String docComment; - public String sourceRef; - private static final String FILTER_CHAIN_CLASS_NAME = "javax.servlet.FilterChain"; - - public ProcessedHttpUrlAnnotation() { - // empty - } - - public ProcessedHttpUrlAnnotation(String typeName, Declaration declaration, String value, int weight) { - MethodDeclaration methodDeclaration = (MethodDeclaration) declaration; - String className = methodDeclaration.getDeclaringType().getQualifiedName(); - this.methodName = declaration.getSimpleName(); - this.docComment = declaration.getDocComment(); - this.className = className; - this.value = value; - this.weight = weight; - this.setParams(methodDeclaration.getParameters()); - String typeNameShort = typeName.substring(typeName.lastIndexOf(".")); - SourcePosition positionInCode = declaration.getPosition(); - sourceRef = positionInCode.file().getName() + ":" + positionInCode.line(); - if (!(declaration instanceof MethodDeclaration)) { - messager.printWarning(positionInCode, "@" + typeNameShort + " declared on a non-method " + positionInCode); - } - if (showPositionsOfAnnotations) { - messager.printNotice(positionInCode, "@" + typeNameShort + " value " + value + " weight " + weight); - } - } - - public int compareTo(ProcessedHttpUrlAnnotation other) { - if (this.weight < other.weight) return 1; - if (this.weight > other.weight) return -1; - if (this.className != null && other.className != null) { - int comp = this.className.compareTo(other.className); - if (comp != 0) return comp; - } - if (this.methodName != null && other.methodName != null) { - return this.methodName.compareTo(other.methodName); - } - return 0; - } - - void setParams(Collection params) { - paramsFormatted = "("; - chainUsed = false; - if (params.size() > 0) { - int i = 1; - for (ParameterDeclaration paramDeclaration : params) { - String paramType = paramDeclaration.getType().toString(); - if (FILTER_CHAIN_CLASS_NAME.equals(paramType)) { - chainUsed = true; - } - paramsFormatted += (i == 1 ? "" : ", ") + paramType; - - HttpParam httpParam = paramDeclaration.getAnnotation(HttpParam.class); - if (httpParam != null) { - paramsFormatted += " "; - if (!"[ unassigned ]".equals(httpParam.value())) { - paramsFormatted += httpParam.value(); - } else { - paramsFormatted += paramDeclaration.getSimpleName(); - } - } - i++; - } - } - paramsFormatted += ")"; - } - } - - class ProcessedHttpExceptionAnnotation extends ProcessedHttpUrlAnnotation { - public String exceptionName; - - public int compareTo(ProcessedHttpExceptionAnnotation other) { - int comp = super.compareTo(other); - if (comp == 0) comp = exceptionName.compareTo(other.exceptionName); - return comp; - } - - } - - - /** - * a very very basic xml escaper. - * - * @param s string to escape - * @return the escaped string - */ - private static String escapeXML(String s) { - if (s == null) { - return null; - } - final int length = s.length(); - StringBuffer b = new StringBuffer(); - for (int i = 0; i < length; i++) { - char c = s.charAt(i); - switch (c) { - case '&': - b.append("&"); - break; - case '<': - b.append("<"); - break; - case '>': - b.append(">"); - break; - default: - b.append(c); - break; - } - } - return b.toString(); - } - - private static String padEachLine(String padWith, String str) { - StringBuffer out = new StringBuffer(); - String[] lines = str.split("\n"); - int i = 0; - while (i < lines.length) { - String line = lines[i]; - out.append(padWith); - out.append(line); - i++; - if (i < lines.length) out.append('\n'); - } - return out.toString(); - } - - private static boolean isBlank(final String str) { - return str == null || "".equals(str) || "".equals(str.trim()); - } - - private static void checkDirsExistMkdir(File dir) { - if (!dir.getParentFile().exists()) { - checkDirsExistMkdir(dir.getParentFile()); - } - if (!dir.exists()) { - dir.mkdir(); - } - } - - private void debugMsg(String msg) { - if (!debug) return; - messager.printNotice("Debug: " + msg); - } - -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/ProcessorServiceLoaderCheck.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/ProcessorServiceLoaderCheck.java deleted file mode 100644 index 90c594e2..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/ProcessorServiceLoaderCheck.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tuckey.web.filters.urlrewrite.annotation; - -import javax.annotation.processing.Processor; -import java.util.ServiceLoader; - -/** - * Quick and dirty class to check that "service" file is loaded in the current classpath. - */ -public class ProcessorServiceLoaderCheck { - - public static void main(String[] args) { - System.out.println("Checking for services..."); - ServiceLoader processorServices = ServiceLoader.load(Processor.class); - for (Object o : processorServices) { - System.out.println(o); - } - System.out.println("Done."); - } -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/UrlRewriteAnnotationProcessor.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/UrlRewriteAnnotationProcessor.java deleted file mode 100644 index 25f7ffd7..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/annotation/UrlRewriteAnnotationProcessor.java +++ /dev/null @@ -1,469 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Messager; -import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.lang.model.element.*; -import javax.lang.model.util.Elements; -import javax.tools.Diagnostic; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Annotation processor for UrlRewrite. Will search classes for annotations and generate XML fragment. - * JDK 1.6+ - *

      - * - * @since 3.2 - */ -@SupportedAnnotationTypes("org.tuckey.web.filters.urlrewrite.*") -public class UrlRewriteAnnotationProcessor extends AbstractProcessor { - - private List processedAnnotations = new ArrayList(); - private List processedJsonAnnotations = new ArrayList(); - private List httpExceptionHandlers = new ArrayList(); - private Messager messager; - private Elements elementUtils; - private boolean showPositions = false; - private boolean debug = false; - private boolean errorDuringProcessing = false; - private String dest = null; - private String rpcBase = "/rpc/"; - - public UrlRewriteAnnotationProcessor() { - // needed - } - - public Set getSupportedOptions() { - HashSet options = new HashSet(); - options.add("urlrewriteDest"); - options.add("urlrewriteShowPositions"); - options.add("urlrewriteDebug"); - options.add("urlrewriteRpcBase"); - return options; - } - - public synchronized void init(ProcessingEnvironment processingEnv) { - this.messager = processingEnv.getMessager(); - this.elementUtils = processingEnv.getElementUtils(); - - Map options = processingEnv.getOptions(); - Set keys = options.keySet(); - for (String key : keys) { - if (key.equalsIgnoreCase("urlrewriteDest")) { - dest = options.get(key); - - } else if (key.equalsIgnoreCase("urlrewriteShowPositions")) { - showPositions = "true".equalsIgnoreCase(options.get(key)); - - } else if (key.equalsIgnoreCase("urlrewriteDebug")) { - debug = "true".equalsIgnoreCase(options.get(key)); - - } else if (key.equalsIgnoreCase("urlrewriteRpcBase")) { - rpcBase = options.get(key); - } - } - debugMsg("init"); - } - - public boolean process(Set annotations, RoundEnvironment roundEnv) { - if (isBlank(dest)) { - if (roundEnv.processingOver()) - infoMsg(getClass().getSimpleName() + ": -AurlrewriteDest not specified, annotations ignored"); - return true; - } - debugMsg("process"); - - Set urlDeclarations = roundEnv.getElementsAnnotatedWith(HttpUrl.class); - for (Element element : urlDeclarations) { - processedAnnotations.add(new ProcessedHttpUrlAnnotation(element)); - } - - Set jsonDeclarations = roundEnv.getElementsAnnotatedWith(HttpJson.class); - for (Element element : jsonDeclarations) { - processedJsonAnnotations.add(new ProcessedHttpJsonAnnotation(element)); - } - - Set exceptionDeclarations = roundEnv.getElementsAnnotatedWith(HttpExceptionHandler.class); - for (Element element : exceptionDeclarations) { - httpExceptionHandlers.add(new ProcessedHttpExceptionAnnotation(element)); - } - - if (roundEnv.processingOver()) { - if (processedAnnotations.size() > 0) { - infoMsg("Got " + processedAnnotations.size() + " @HttpUrl annotations"); - } - if (processedJsonAnnotations.size() > 0) { - infoMsg("Got " + processedJsonAnnotations.size() + " @HttpJson annotations"); - processedAnnotations.addAll(processedJsonAnnotations); - } - Collections.sort(processedAnnotations); - - if (httpExceptionHandlers.size() > 0) { - infoMsg("Got " + httpExceptionHandlers.size() + " @HttpExceptionHandler annotations"); - Collections.sort(httpExceptionHandlers); - } - try { - File destFile = new File(dest); - if (!destFile.exists()){ - if ( destFile.getParentFile() == null ) { - infoMsg("Parent file null for " + destFile); - } - if ( ! destFile.createNewFile() ) { - infoMsg("could not make new file for " + destFile + " trying to mkdirs"); - checkDirsExistMkdir(destFile.getParentFile()); - if ( ! destFile.createNewFile() ) { - errorMsg("could not make new file for " + destFile); - } - } - } - if (!destFile.canWrite()) { - throw new IOException("cannot write to " + destFile.getName()); - } - if (errorDuringProcessing) { - errorMsg("Error occured during processing deleting generated file."); - destFile.delete(); - - } else { - PrintWriter pw = new PrintWriter(destFile); - infoMsg("Writing to " + destFile); - outputRules(pw); - outputExceptionHandlers(pw); - pw.close(); - - } - } catch (FileNotFoundException e) { - errorMsg(e); - e.printStackTrace(); - - } catch (IOException e) { - errorMsg(e); - e.printStackTrace(); - } - } - return true; - } - - private void outputRules(PrintWriter pw) { - for (ProcessedHttpUrlAnnotation pa : processedAnnotations) { - boolean jsonHandler = pa instanceof ProcessedHttpJsonAnnotation; - pw.println(""); - pw.println(" " + pa.className + "." + pa.methodName + ""); - if (!isBlank(pa.docComment)) { - pw.println(" "); - pw.println(padEachLine(" ", escapeXML(pa.docComment))); - pw.println(" "); - } - pw.println(" " + pa.value + ""); - pw.println(" "); - if (!pa.chainUsed) { - pw.println(" null"); - } - pw.println(""); - pw.flush(); - } - } - - private void outputExceptionHandlers(PrintWriter pw) { - for (ProcessedHttpExceptionAnnotation pa : httpExceptionHandlers) { - pw.println(""); - if (!isBlank(pa.docComment)) { - pw.println(" "); - pw.println(padEachLine(" ", escapeXML(pa.docComment))); - pw.println(" "); - } - pw.println(" "); - pw.println(""); - pw.flush(); - } - } - - class ProcessedUrlRewriteFilterAnnotation implements Comparable { - - public String methodName; - public String className; - public String docComment; - public String paramsFormatted; - - public ExecutableElement init(Element declaration) { - if (!ElementKind.METHOD.equals(declaration.getKind())) { - errorMsg("declared on a non-method (type is " + declaration.getKind() + ")", declaration); - return null; - } - ExecutableElement methodDeclaration = (ExecutableElement) declaration; - TypeElement classDeclaration = (TypeElement) methodDeclaration.getEnclosingElement(); - className = classDeclaration.getQualifiedName().toString(); - methodName = declaration.getSimpleName().toString(); - docComment = elementUtils.getDocComment(declaration); - return methodDeclaration; - } - - public int compareTo(ProcessedUrlRewriteFilterAnnotation other) { - if (this.className != null && other.className != null) { - int comp = this.className.compareTo(other.className); - if (comp != 0) return comp; - } - if (this.methodName != null && other.methodName != null) { - return this.methodName.compareTo(other.methodName); - } - return 0; - } - - void setParams(Collection params) { - paramsFormatted = "("; - if (params.size() > 0) { - int i = 1; - for (VariableElement paramDeclaration : params) { - String paramType = paramDeclaration.asType().toString(); - paramsFormatted += (i == 1 ? "" : ", ") + paramType; - HttpParam httpParam = paramDeclaration.getAnnotation(HttpParam.class); - if (httpParam != null) { - paramsFormatted += " "; - if (!"[ unassigned ]".equals(httpParam.value())) { - paramsFormatted += httpParam.value(); - } else { - paramsFormatted += paramDeclaration.getSimpleName(); - } - } - i++; - } - } - paramsFormatted += ")"; - } - - } - - class ProcessedHttpJsonAnnotation extends ProcessedHttpUrlAnnotation { - public ProcessedHttpJsonAnnotation(Element declaration) { - ExecutableElement methodDeclaration = init(declaration); - if (methodDeclaration == null) return; - - HttpJson httpJson = declaration.getAnnotation(HttpJson.class); - if ("[ unassigned ]".equals(httpJson.value()) ) { - this.value = rpcBase + this.className + "/" + this.methodName; - } else { - this.value = httpJson.value(); - } - this.weight = httpJson.weight(); - setParams(methodDeclaration.getParameters()); - - if (showPositions) { - messager.printMessage(Diagnostic.Kind.NOTE, "@HttpJson value " + value + " weight " + weight, methodDeclaration); - } - } - - } - - class ProcessedHttpUrlAnnotation extends ProcessedUrlRewriteFilterAnnotation { - public int weight = 0; - public String value; - public boolean chainUsed; - public String sourceRef; - private static final String FILTER_CHAIN_CLASS_NAME = "javax.servlet.FilterChain"; - - public ProcessedHttpUrlAnnotation() { - // empty - } - - public ProcessedHttpUrlAnnotation(Element declaration) { - ExecutableElement methodDeclaration = init(declaration); - if (methodDeclaration == null) return; - - HttpUrl httpUrl = declaration.getAnnotation(HttpUrl.class); - this.value = httpUrl.value(); - this.weight = httpUrl.weight(); - setParams(methodDeclaration.getParameters()); - - if (showPositions) { - messager.printMessage(Diagnostic.Kind.NOTE, "@HttpUrl value " + value + " weight " + weight, methodDeclaration); - } - } - - public int compareTo(ProcessedHttpUrlAnnotation other) { - if (this.weight < other.weight) return 1; - if (this.weight > other.weight) return -1; - return super.compareTo(other); - } - - protected void setParams(Collection params) { - chainUsed = false; - if (params.size() > 0) { - for (VariableElement paramDeclaration : params) { - String paramType = paramDeclaration.asType().toString(); - if (FILTER_CHAIN_CLASS_NAME.equals(paramType)) { - chainUsed = true; - } - } - } - super.setParams(params); - } - - } - - class ProcessedHttpExceptionAnnotation extends ProcessedUrlRewriteFilterAnnotation { - public String exceptionName; - - public ProcessedHttpExceptionAnnotation(Element declaration) { - ExecutableElement methodDeclaration = init(declaration); - if (methodDeclaration == null) return; - - HttpExceptionHandler httpExceptionHandler = declaration.getAnnotation(HttpExceptionHandler.class); - exceptionName = httpExceptionHandler.value(); - - // out exceptionName might not be set - if ("[ unassigned ]".equals(exceptionName) ) { - // use first param - exceptionName = methodDeclaration.getParameters().get(0).asType().toString(); - } - setParams(methodDeclaration.getParameters()); - - if (showPositions) { - messager.printMessage(Diagnostic.Kind.NOTE, "@HttpExceptionHandlerUrl exceptionName " + exceptionName, methodDeclaration); - } - } - - public int compareTo(ProcessedHttpExceptionAnnotation other) { - int comp = super.compareTo(other); - if (comp == 0) comp = exceptionName.compareTo(other.exceptionName); - return comp; - } - - } - - - /** - * a very very basic xml escaper. - * - * @param s string to escape - * @return the escaped string - */ - private static String escapeXML(String s) { - if (s == null) { - return null; - } - final int length = s.length(); - StringBuffer b = new StringBuffer(); - for (int i = 0; i < length; i++) { - char c = s.charAt(i); - switch (c) { - case '&': - b.append("&"); - break; - case '<': - b.append("<"); - break; - case '>': - b.append(">"); - break; - default: - b.append(c); - break; - } - } - return b.toString(); - } - - private static String padEachLine(String padWith, String str) { - StringBuffer out = new StringBuffer(); - String[] lines = str.split("\n"); - int i = 0; - while (i < lines.length) { - String line = lines[i]; - out.append(padWith); - out.append(line); - i++; - if (i < lines.length) out.append('\n'); - } - return out.toString(); - } - - private static boolean isBlank(final String str) { - return str == null || "".equals(str) || "".equals(str.trim()); - } - - private static void checkDirsExistMkdir(File dir) { - if ( dir == null ) throw new RuntimeException("checkDirsExistMkdir called with null"); - if (dir.getParentFile() == null ) { - checkDirsExistMkdir(dir); - } - if (!dir.getParentFile().exists()) { - checkDirsExistMkdir(dir.getParentFile()); - } - if (!dir.exists()) { - dir.mkdir(); - } - } - - - private void debugMsg(String msg) { - if (!debug) return; - messager.printMessage(Diagnostic.Kind.OTHER, getClass().getSimpleName() + " " + msg); - } - - private void infoMsg(String msg) { - messager.printMessage(Diagnostic.Kind.NOTE, msg); - } - - private void errorMsg(String msg) { - errorDuringProcessing = true; - messager.printMessage(Diagnostic.Kind.ERROR, msg); - } - - private void errorMsg(Exception e) { - errorDuringProcessing = true; - messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage()); - } - - private void errorMsg(String msg, Element element) { - errorDuringProcessing = true; - messager.printMessage(Diagnostic.Kind.ERROR, msg, element); - } - -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCBean.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCBean.java deleted file mode 100644 index d9044a0b..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCBean.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.json; - -/** - * Bean to encapsulate an RPC result. - */ -public class JSONRPCBean { - - private Object result; - private JSONRPCErrorBean error; - - public String getVersion() { - return "1.1"; - } - - public Object getResult() { - return result; - } - - public void setResult(Object result) { - this.result = result; - } - - public JSONRPCErrorBean getError() { - return error; - } - - public void setError(JSONRPCErrorBean error) { - this.error = error; - } - -} diff --git a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCErrorBean.java b/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCErrorBean.java deleted file mode 100644 index 836c9c62..00000000 --- a/annotation/src/main/java/org/tuckey/web/filters/urlrewrite/json/JSONRPCErrorBean.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.json; - -/** - * Bean to encapsulate RPC errors. - */ -public class JSONRPCErrorBean { - - private int code; - private String message; - private Object error; - - public String getName() { - return "JSONRPCError"; - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public Object getError() { - return error; - } - - public void setError(Object error) { - this.error = error; - } -} diff --git a/annotation/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory b/annotation/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory deleted file mode 100644 index 01e21e54..00000000 --- a/annotation/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory +++ /dev/null @@ -1 +0,0 @@ -org.tuckey.web.filters.urlrewrite.annotation.HttpUrlAPTFactory \ No newline at end of file diff --git a/annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index 590d16aa..00000000 --- a/annotation/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -org.tuckey.web.filters.urlrewrite.annotation.UrlRewriteAnnotationProcessor \ No newline at end of file diff --git a/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java b/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java deleted file mode 100644 index fe101d27..00000000 --- a/annotation/src/test/java/org/tuckey/web/filters/urlrewrite/annotation/SampleMatchAction.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Copyright (c) 2005-2023, Paul Tuckey - * All rights reserved. - * ==================================================================== - * Licensed under the BSD License. Text as follows. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - Neither the name tuckey.org nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - */ -package org.tuckey.web.filters.urlrewrite.annotation; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.sql.SQLException; - - -public class SampleMatchAction { - - @HttpUrl(value = "^/1clientinfo/$") - public void listActive(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException, SQLException { - - } - - /** - * In file 2nd. - */ - @HttpUrl("^/clientinfo/(*)/$") - public void clientDetails(int clientId) - throws SQLException { - - } - - @HttpUrl("^/search/(clients|staff)/$") - public void addClientFilterSecond(String searchType, @HttpParam String firstName, - @HttpParam("lName")String lastName) - throws SQLException { - - } - - /** - * In the file 3rd. Should be 1st. - *

      - * Multiline doc. - */ - @HttpUrl(value = "^/clientinfo/(*)/$", weight = 2) - public void addClientFilterFirst(int clientId, FilterChain chain) - throws SQLException { - - } - - /** - * Should be the last item in the processed file. - * In file 4th. Should be last. - */ - @HttpUrl(value = "^/clientinfo/(*)/$", weight = -1) - public void addClientFilterLast(int clientId, FilterChain chain) - throws SQLException { - - } - - /** - * In file 5th. Should be 2nd. - */ - @HttpUrl(value = "^/clientinfo/(*)/$", weight = 1) - public void addClientFilterSecond(int clientId, FilterChain chain) - throws SQLException { - - } - - class ClientBean { - private String name = "Bob"; - } - - @HttpExceptionHandler("java.lang.Exception") - public void addExceptionHandler(Exception e) - throws SQLException { - - } - - @HttpExceptionHandler - public void addExceptionHandlerAuto(Exception e) - throws SQLException { - - } - - @HttpJson - public String clientDetailsRpc(@HttpParam int clientId) - throws SQLException { - return "Hello World"; - } - -} From 11a1467cc3863646efd36f84be963baf00cf00ce Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 20 Oct 2023 09:37:19 +1300 Subject: [PATCH 4/5] remove ref to 5.1 --- src/doc/manual/5.0/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/manual/5.0/index.html b/src/doc/manual/5.0/index.html index 5468bd49..4e5001d7 100644 --- a/src/doc/manual/5.0/index.html +++ b/src/doc/manual/5.0/index.html @@ -86,12 +86,12 @@

      Install

      1. Add Maven dependency below or add - urlrewritefilter-5.1.2.jar + urlrewritefilter-5.0.0.jar directly into your WEB-INF/lib directory.
        <dependency>
             <groupId>org.tuckey</groupId>
             <artifactId>urlrewritefilter</artifactId>
        -    <version>5.1.2</version>
        +    <version>5.0.0</version>
         </dependency>
      2. Add the following to your WEB-INF/web.xml (add it near the top above your servlet mappings (if you have any)): (see filter From ec67926e91ee215ab89920e3f829e66172c56c5c Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 20 Oct 2023 09:39:25 +1300 Subject: [PATCH 5/5] chore: tidy up --- .../org/tuckey/web/filters/urlrewrite/doc/doc.css | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/doc/doc.css b/src/main/java/org/tuckey/web/filters/urlrewrite/doc/doc.css index fe1a09f7..1152530e 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/doc/doc.css +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/doc/doc.css @@ -10,8 +10,8 @@ body { h1 { color: #000000; font-size: 2.5em; - padding: 0px 0px 0px 5px; - margin: 0px; + padding: 0 0 0 5px; + margin: 0; font-family: georgia, times, serif; } @@ -42,11 +42,11 @@ h3 { font-family: georgia, times, serif; border-bottom: 1px solid #c0c0c0; margin-top: 2em; - padding: 0.25em 0.25em 0em 0.5em; + padding: 0.25em 0.25em 0 0.5em; } p { - padding: 0.25em 0.25em 0em 1.0em; + padding: 0.25em 0.25em 0 1.0em; } code, pre { @@ -78,7 +78,7 @@ th { } hr { - border: 0px; + border: 0; background-color: #c0c0c0; } @@ -90,7 +90,6 @@ hr { float:left; width:160px; background: #efefef; - Zmargin-top: 2px; padding-bottom: 10px; padding-left: 10px; -moz-border-radius-bottomleft: 20px;