【问题标题】:how can I use capturedWith method in prettyFaces如何在 prettyFaces 中使用 captureWith 方法
【发布时间】:2019-01-25 20:42:47
【问题描述】:

我想在请求 http url 时强制使用 https url。我在 Prettyfaces 论坛中找到了this。但是这段代码给出了cannot find symbol 错误。我该如何解决这个问题?

return ConfigurationBuilder.begin()
    .addRule()
    .when(URL.captureIn("url").and(Path.matches("/login")).and(Scheme.matches("http")))
    .perform(Redirect.permanent(URL.capturedWith("url").toScheme("https")));

【问题讨论】:

    标签: jsf prettyfaces


    【解决方案1】:

    尝试使用参数转置:

    return ConfigurationBuilder.begin()
        .addRule()
        .when(URL.captureIn("url").and(Path.matches("/login")).and(Scheme.matches("http")))
        .perform(Redirect.permanent("{url}"))
        .where("url").transposedBy(new Transposition() { ... convert to HTTPS HERE ... });
    

    https://github.com/ocpsoft/rewrite/blob/master/api/src/main/java/org/ocpsoft/rewrite/param/Transposition.java

    您也可以通过使用自定义操作执行类似的操作来实现相同的目的:

    https://github.com/ocpsoft/rewrite/blob/master/config-servlet/src/test/java/org/ocpsoft/rewrite/servlet/config/SchemeChangeConfigurationProvider.java

    public class SchemeChangeConfigurationProvider extends HttpConfigurationProvider
    {
       @Override
       public int priority()
       {
          return 0;
       }
    
       @Override
       public Configuration getConfiguration(final ServletContext context)
       {
          Configuration config = ConfigurationBuilder.begin()
    
                   .addRule().when(Scheme.matches("http")).perform(new HttpOperation() {
    
                      @Override
                      public void performHttp(HttpServletRewrite event, EvaluationContext context)
                      {
                         String url = event.getRequest().getRequestURL().toString().replaceFirst("http", "https");
                         Redirect.temporary(url).perform(event, context);
                      }
                   });
          return config;
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-12
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 2012-06-13
      • 2015-07-01
      • 2012-03-03
      • 2012-04-23
      相关资源
      最近更新 更多