gpt4 book ai didi

java - 如何为 Undertow/JBoss 7.2 EAP 重写 RewriteValve?

转载 作者:行者123 更新时间:2023-12-05 06:14:26 25 4
gpt4 key购买 nike

我正在从 JBoss 6.4.3 迁移到 JBoss 7.2,在部署期间看到了 Valves are no longer supported 警告。这来自一个 jboss-web.xml 文件:

<valve>
<class-name>org.jboss.web.rewrite.RewriteValve</class-name>
</valve>

...和相应的rewrite.properties 文件:

RewriteCond %{HTTP:X-Forwarded-Proto} http
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

谁能建议如何为 Undertow 重写这个(没有双关语)?

最佳答案

您可以创建一个 rewrite filter在 Undertow 子系统中,然后在配置文件(standalone.xmldomain.xml - 取决于您启动应用程序的模式)中的服务器主机中引用它服务器)。

我可以想到两个可能对您有帮助的选项:

  1. 使用JBoss 应用服务器客户端(应该放在path/to/jboss-7.2/bin/)

    • 使用自定义名称 redirect-http-to-https 创建重写过滤器:
    ./jboss-cli.sh --connect --command="/subsystem=undertow/configuration=filter/rewrite=redirect-http-to-https:add(redirect=\"true\",target=\"https://%{LOCAL_SERVER_NAME}%{REQUEST_URL}\")"
    • 使用/引用过滤器redirect-http-to-https:
    ./jboss-cli.sh --connect --command="/subsystem=undertow/server=default-server/host=default-host/filter-ref=redirect-http-to-https:add(predicate=\"equals(%p,80)\")"
  2. 手动编辑相应的配置文件(例如 standalone.xml)

<subsystem xmlns="urn:jboss:domain:undertow:11.0" default-server="default-server" [...]>
<buffer-cache name="default"/>
<server name="default-server">
[...]
<host name="default-host" alias="localhost">
<filter-ref name="redirect-http-to-https" predicate="equals(%p,80)"/>
</host>
</server>
[...]
<filters>
<rewrite name="redirect-http-to-https" target="https://%{LOCAL_SERVER_NAME}%{REQUEST_URL}" redirect="true"/>
</filters>
</subsystem>

注意:对于 Undertow 交换属性(例如 LOCAL_SERVER_NAME),请参阅 Undertow documentation .此外,filter-ref 中的 predicate=\"equals(%p,80)\" 部分检查请求的端口(%p -> 只是另一个 Undertow 交换属性),如果它等于 80,那么它会触发我们的重定向过滤器 redirect-http-to-https - 你可以更改端口 80 根据您的需要。

关于java - 如何为 Undertow/JBoss 7.2 EAP 重写 RewriteValve?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62898780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com