Bug 1341410

Summary: [GSS](6.4.z) Getting IllegalArgumentException when using colon to specify port number with server vairable in rewrite rule
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Masafumi Miura <mmiura>
Component: WebAssignee: jboss-set
Status: CLOSED CURRENTRELEASE QA Contact: Radim Hatlapatka <rhatlapa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.4.8CC: bmaxwell, ihradek, jtruhlar, msochure, psotirop, rmaucher
Target Milestone: CR1   
Target Release: EAP 6.4.11   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-17 13:11:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1316573, 1361648    

Description Masafumi Miura 2016-06-01 03:00:11 UTC
### Description of problem:

Getting IllegalArgumentException when using colon to specify port number with server vairable in rewrite rule


### How reproducible:

Anytime


### Steps to Reproduce:

1. Set 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>

   or use the following rewrite.properties with setting rewrite valve in jboss-web.xml 

       RewriteCond %{HTTPS} !=on
       RewriteRule .* https://%{HTTP_HOST}:8443%{REQUEST_URI} [R,L]

2. Start JBoss EAP 


### Actual results:

~~~
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
~~~

### Expected results:

No exception.


### Workaround

If a fixed hostname is acceptable instead of using server variable %{HTTP_HOST}, you can workaround by changing your rewrite rule 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>


### Additional info:

Similar issue has already been fixed in tomcat trunk by https://svn.apache.org/viewvc?view=revision&revision=1730612

Comment 9 Ivo Hradek 2016-10-04 06:49:44 UTC
Verified with EAP 6.4.11.CP.CR1;

Comment 10 Petr Penicka 2017-01-17 13:11:44 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.