Search code examples
javajerseytuckey-urlrewrite-filter

tuckey urlrewrite returns 404 not found


I am using Jersey framework and the endpoint I have is /v1/users/{user_id: \p{XDigit}{8}}/orders/{order_id: \p{XDigit}{8}}.

What I need is to rewrite the url /v2/users/{user_id: \p{XDigit}{8}}/orders/{order_id: \p{XDigit}{8}} to the above url.

I am using tuckey for url rewrite. And following is my urlrewrite.xml.

<rule>
    <from>^/v2/users/([A-Fa-f0-9]{8})$/orders/([A-Fa-f0-9]{8})$</from>
    <to>/v1/users/$1/orders/$2</to>
</rule>

By sending request curl 'localhost:8080/v1/users/11111111/orders/11111111', I am hitting the right endpoint, but when I try to curl 'localhost:8080/v2/users/11111111/orders/11111111', I an getting 404 NOT FOUND response.

And when I change my urlrewrite.xml to following

<rule>
    <from>^/v2/users/([A-Fa-f0-9]{8})/orders/([A-Fa-f0-9]{8})</from>
    <to>/v1/users/([A-Fa-f0-9]{8})/orders/([A-Fa-f0-9]{8})</to>
</rule>

I am getting error saying that You did not supply enough values to fill path parameters.

Any idea why I am wrong?


Solution

  • Please try the following:

    <rule>
        <from>^/v2/users/([A-Fa-f0-9]{8})/orders/([A-Fa-f0-9]{8})$</from>
        <to>/v1/users/$1/orders/$2</to>
    </rule>
    

    Note that you have used one extra '$'. In RegEx, '$' means 'end of the sentence'.

    Good luck.