【问题标题】:OCPsoft Rewrite Rule no longer works after Update from 1.0.5 to 1.1.0从 1.0.5 更新到 1.1.0 后,OCPsoft 重写规则不再有效
【发布时间】:2012-12-11 13:19:23
【问题描述】:

当将 OCPsoft Rewrite 从版本 1.0.5.Final 更新到 1.1.0.Final 时,以下规则不再有效,我不知道如何解决:

.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}")
)

在 Rewrite changelog 中有一点可以帮助你帮助我:

配置字符串现在是文字。正则表达式必须通过一个>参数进行配置,例如:.defineRule().when(Path.matches("/{*}").where("*").matches(".*"))

我得到的例外是以下一个:

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)
        ...

【问题讨论】:

  • 附言。抱歉回复晚了 :) 假期!

标签: java tomcat jakarta-ee url-rewriting ocpsoft-rewrite


【解决方案1】:

下面的方法成功了,我只需要重新排序连接子句:

.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();
)

感谢 Lincoln,他发现了这一点并在 Rewrite 支持论坛上回答了我的问题。

【讨论】:

    【解决方案2】:

    嗯.. 看起来确实像一个错误,我会尝试重现它,但您不需要在目标 URL 中重新定义 {i}{d}。如果您使用请求绑定,Join 会自动为您处理,如下所示:

    .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();
    )
    

    我猜如果你这样做,你的问题就会消失。如果您想将对旧的 .html URL 的请求重定向到新的 URL,您也可以使用 .withInboundCorrection()

    如果您对此仍有疑问,请在支持论坛上发帖,我们会解决的 :)

    抱歉,您遇到了麻烦,希望不会再有麻烦了:)

    【讨论】:

      猜你喜欢
      • 2014-06-28
      • 1970-01-01
      • 2013-10-12
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2018-08-29
      相关资源
      最近更新 更多