Question

When updating OCPsoft Rewrite from Version 1.0.5.Final to 1.1.0.Final the following Rule no longer works and I don't know how to fix it:

.addRule(
    Join.path("/{i}/{d}")
        .where("i").matches("[-_a-zA-Z0-9~*]{8}")
        .where("d").matches("[-_a-zA-Z0-9~*]{32}")
        .to("/resources/html/user/doSomething.html?i={i}&d={d}")
)

In the Rewrite changelog there is one point that could help you help me:

Configuration strings are now literal. Regular expressions must be configured through a >parameter such as: .defineRule().when(Path.matches("/{*}").where("*").matches(".*"))

The exception I get is the following one:

Exception starting filter OCPsoft Rewrite Filter
    java.lang.NullPointerException
        at org.ocpsoft.rewrite.servlet.config.rule.Join.where(Join.java:199)
        at org.ocpsoft.rewrite.servlet.config.rule.Join.where(Join.java:47)
        at com.myapp.util.RewriteConfigurationProvider.getConfiguration(RewriteConfigurationProvider.java:39)
        ...
Was it helpful?

Solution

The following did the trick, I just had to reorder the join clauses:

.addRule(
    Join.path("/{i}/{d}")
        .to("/resources/html/user/doSomething.html")
        .where("i").matches("[-_a-zA-Z0-9~*]{8}")
        .where("d").matches("[-_a-zA-Z0-9~*]{32}")
        .withRequestBinding();
)

Thanks to Lincoln, who figured this out and answered my question on the Rewrite support forums.

OTHER TIPS

Hmm.. that does look like a bug, I'll try to reproduce this, but you shouldn't need to re-define {i} and {d} in the target URL. Join will handle that for you automatically if you use request binding, like so:

.addRule(
   Join.path("/{i}/{d}")
    .where("i").matches("[-_a-zA-Z0-9~*]{8}")
    .where("d").matches("[-_a-zA-Z0-9~*]{32}")
    .to("/resources/html/user/doSomething.html").withRequestBinding();
)

I'm guessing if you do that, your problem will go away. You can also use .withInboundCorrection() if you'd like to redirect requests for the old .html URL to the new URL.

If you still have a problem with this, please post on the support forums and we'll get it figured out :)

Sorry you had trouble, hopefully it won't be trouble any more :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top