Getting IllegalArgumentException when using colon to specify port number with server vairable in rewrite rule in JBoss EAP 6.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6.x
Issue
To force redirect to https, I configured the following global rewrite rule in web subsystem in standalone.xml
<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
...
<virtual-server name="default-host" enable-welcome-root="true">
...
<rewrite pattern="^/(.*)$" substitution="https://%{HTTP_HOST}:8443%{REQUEST_URI}" flags="RL">
<condition test="%{HTTPS}" pattern="off" />
</rewrite>
</virtual-server>
</subsystem>
then got the following IllegalArgumentException:
ERROR [org.jboss.msc.service.fail] (MSC service thread 1-37) MSC000001: Failed to start service jboss.web.host.default-host: org.jboss.msc.service.StartException in service jboss.web.host.default-host: java.lang.IllegalArgumentException: https://%{HTTP_HOST}:8443%{REQUEST_URI}
at org.jboss.as.web.WebVirtualHostService.createRewriteValve(WebVirtualHostService.java:225)
at org.jboss.as.web.WebVirtualHostService.start(WebVirtualHostService.java:88)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1980) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1913) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_77]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_77]
Caused by: java.lang.IllegalArgumentException: https://%{HTTP_HOST}:8443%{REQUEST_URI}
at org.jboss.web.rewrite.Substitution.parse(Substitution.java:195)
at org.jboss.web.rewrite.RewriteRule.parse(RewriteRule.java:45)
at org.jboss.web.rewrite.RewriteValve.parse(RewriteValve.java:251)
at org.jboss.web.rewrite.RewriteValve.setConfiguration(RewriteValve.java:184)
at org.jboss.as.web.WebVirtualHostService.createRewriteValve(WebVirtualHostService.java:223)
... 6 more
Same issue occurred when using the followingrewrite.properties with setting rewrite valve in WEB-INF/jboss-web.xml:
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}:8443%{REQUEST_URI} [R,L]
Resolution
-
This is a bug reported in This content is not included.BZ#1341410
-
If a fixed hostname is acceptable instead of using server variable %{HTTP_HOST}, you can workaround by changing your rewrite rule.
For example, change global rewrite vale in web subsystem from:<rewrite pattern="^/(.*)$" substitution="https://%{HTTP_HOST}:8443%{REQUEST_URI}" flags="RL"> <condition test="%{HTTPS}" pattern="off" /> </rewrite>to:
<rewrite pattern="^/(.*)$" substitution="https://www.example.com:8443%{REQUEST_URI}" flags="RL"> <condition test="%{HTTPS}" pattern="off" /> </rewrite>Or, change rewrite.properties from:
RewriteCond %{HTTPS} !=on RewriteRule .* https://%{HTTP_HOST}:8443%{REQUEST_URI} [R,L]to:
RewriteCond %{HTTPS} !=on RewriteRule .* https://www.example.com:8443%{REQUEST_URI} [R,L]
Root Cause
- Similar issue has already been fixed in tomcat trunk by <Content from svn.apache.org is not included.https://svn.apache.org/viewvc?view=revision&revision=1730612>
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.