如何在 prettyFaces 中使用 captureWith 方法

how can I use capturedWith method in prettyFaces

我想在请求 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")));

尝试使用参数移调:

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;
   }
}