1
votes

We are migrating a clickonce application(this is not an usual war/ear deployment) which hosted on JBOSS to Tomcat, however having an issue in URL Redirection.

Actual URL which user hits from browser looks as below,

https://abc.domainname:port/app/app.application

this should get redirected as below,

https://abc.domainname:port/abc/app/app.application

application is deployed under tomcatbasedir/webapp/abc/app

I have tried using the rewrite valve which didnt helped me to achieve this.

context.xml or server.xml

Valve className="org.apache.catalina.valves.rewrite.RewriteValve" and

created a rewrite.config under catalinahome/conf and placed the below entry.

RewriteRule  ^/app/app.application$  abc/app/app.application [RL]

For information, below the rule used in JBOSS to do the redirection.

rewrite name="rule-1" pattern="^/app/app.application" substitution="/abc/app/app.application" flags="RL"

Error Trace:

        SEVERE: A child container failed during start
    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [org
    .apache.catalina.valves.rewrite.RewriteValve[localhost]]
            at java.util.concurrent.FutureTask.report(FutureTask.java:122)
            at java.util.concurrent.FutureTask.get(FutureTask.java:188)
            at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:931)
            at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:261)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:766)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            at org.apache.catalina.startup.Catalina.start(Catalina.java:688)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:342)
            at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.valves.rewrite.RewriteValve[localhost]]
            at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
            at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:176)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:948)
            at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
            at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
            at java.util.concurrent.FutureTask.run(FutureTask.java:262)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalArgumentException: rewriteValve.invalidLine
            at org.apache.catalina.valves.rewrite.RewriteValve.parse(RewriteValve.java:709)
            at org.apache.catalina.valves.rewrite.RewriteValve.parse(RewriteValve.java:237)
    :

Content on rewrite.config

RewriteEngine On

RewriteRule "^/app/app.application" "/abc/app/app.application" [RL]

any pointers or help is much appreciated on this.

1
The rewrite.config file should be: in $CATALINA_BASE/conf/[enginename] (usually conf/Catalina) if you added it to the engine; $CATALINA_BASE/conf/[enginename]/[hostname] (usually conf/Catalina/localhost) if you added it to your host. - Piotr P. Karwasz
I have tried this already keeping rewrite.config under the host directory, still it didn't redirecting the URL. - user2417975
Rewriting rules are usually hard to debug, hence you can enable debugging on the RewriteValve (org.apache.catalina.core.ContainerBase.[Catalina].level=FINE in conf/logging.properties) can help. It is hard to be more specific, since you didn't provide neither your server.xml nor context.xml. Remark that you use the regexp ^/app/app.application$ in Tomcat, whereas you used ^/app/app.application before. - Piotr P. Karwasz
Please don't post additional data as comments, click the edit label under the question instead: questions should be self-contained without reading the comments. Please add the complete stack trace of the exception. - Piotr P. Karwasz
Thanks for the suggestion, updated the stack trace in question section. - user2417975

1 Answers

0
votes

There is no RewriteEngine directive in the RewriteValve (cf. documentation), hence the parsing error you obtain.

The RewriteRule directive works almost as Apache's mod_rewrite directive with a twist: the pattern must match the entire URI path. Therefore you need to use:

RewriteRule /app/app.application(/.*)? /abc/app/app.application$1 [RL]