4.5.2. 迁移 JBoss Web 重写条件
管理 CLI 迁移 操作无法自动迁移重写条件。它们报告为"迁移警告",您必须手动迁移。您可以使用 Undertow Predicates Attributes 和 Handlers 在 JBoss EAP 7 中创建等效的配置。
以下是包含 重写 配置的 JBoss EAP 6 中的 Web 子系统配置示例:
<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default" native="false">
<virtual-server name="default" enable-welcome-root="true">
<alias name="localhost"/>
<rewrite name="test" pattern="(.*)/toberewritten/(.*)" substitution="$1/rewritten/$2" flags="NC"/>
<rewrite name="test2" pattern="(.*)" substitution="-" flags="F">
<condition name="get" test="%{REQUEST_METHOD}" pattern="GET"/>
<condition name="andCond" test="%{REQUEST_URI}" pattern=".*index.html" flags="NC"/>
</rewrite>
</virtual-server>
</subsystem>
按照 管理 CLI 迁移操作 说明启动您的服务器和管理 CLI,然后使用以下命令迁移 Web 子系统配置文件:
/subsystem=web:migrate
当您在上述配置上运行 迁移 操作时,将报告以下"migration-warnings"。
/subsystem=web:migrate
{
"outcome" => "success",
"result" => {"migration-warnings" => [
"WFLYWEB0002: Could not migrate resource {
\"pattern\" => \"(.*)\",
\"substitution\" => \"-\",
\"flags\" => \"F\",
\"operation\" => \"add\",
\"address\" => [
(\"subsystem\" => \"web\"),
(\"virtual-server\" => \"default-host\"),
(\"rewrite\" => \"test2\")
]
}",
"WFLYWEB0002: Could not migrate resource {
\"test\" => \"%{REQUEST_METHOD}\",
\"pattern\" => \"GET\",
\"flags\" => undefined,
\"operation\" => \"add\",
\"address\" => [
(\"subsystem\" => \"web\"),
(\"virtual-server\" => \"default-host\"),
(\"rewrite\" => \"test2\"),
(\"condition\" => \"get\")
]
}",
"WFLYWEB0002: Could not migrate resource {
\"test\" => \"%{REQUEST_URI}\",
\"pattern\" => \".*index.html\",
\"flags\" => \"NC\",
\"operation\" => \"add\",
\"address\" => [
(\"subsystem\" => \"web\"),
(\"virtual-server\" => \"default-host\"),
(\"rewrite\" => \"test2\"),
(\"condition\" => \"andCond\")
]
}"
]}
}
检查服务器配置文件,并且您看到 undertow 子系统的以下配置:
注意
重写配置已被丢弃。
<subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="http" socket-binding="http"/>
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost, example.com">
<location name="/" handler="welcome-content"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
</subsystem>
使用管理 CLI 创建过滤器,以取代 undertow 子系统中的重写配置。您应该为每个命令看到 "{"outcome" SAS "success"}"。
# Create the filters
/subsystem=undertow/configuration=filter/expression-filter="test1":add(expression="path('(.*)/toberewritten/(.*)') -> rewrite('$1/rewritten/$2')")
/subsystem=undertow/configuration=filter/expression-filter="test2":add(expression="method('GET') and path('.*index.html') -> response-code(403)")
# Add the filters to the default server
/subsystem=undertow/server=default-server/host=default-host/filter-ref="test1":add
/subsystem=undertow/server=default-server/host=default-host/filter-ref="test2":add
检查更新的服务器配置文件。JBoss Web 子系统现已完全在 undertow 子系统中进行迁移和配置。
<subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="http" socket-binding="http"/>
<https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost, example.com">
<location name="/" handler="welcome-content"/>
<filter-ref name="test1"/>
<filter-ref name="test2"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<expression-filter name="test1" expression="path('(.*)/toberewritten/(.*)') -> rewrite('$1/rewritten/$2')"/>
<expression-filter name="test2" expression="method('GET') and path('.*index.html') -> response-code(403)"/>
</filters>
</subsystem>
有关如何使用管理 CLI 配置过滤器和处理程序的更多信息,请参阅 JBoss EAP 7 配置指南中的配置 Web 服务器。