You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tay Kai Yang <ka...@gmail.com> on 2014/11/21 03:08:40 UTC

How to setup rewrite valve for angularjs

Hi
I have been reading up tomcat 8's user doc. But I have some problems
understanding the setup of rewrite valve. I think I should add the rewrite
valve class name and XML settings to /conf/server.xml, but I am not sure
what to do next. Where should I place my rewrite.config, how do I activate
rewrite my war context only?

Have anyone written a tutorial or can point me to a source for how-to?

I am trying to set a single page angularjs app to point
/context/path/path/... To /context/index.jsp

Any idea on how to do that?

Thanks.
Kai yang

Re: How to setup rewrite valve for angularjs

Posted by Ameer Mawia <am...@gmail.com>.
correction:

On Nov 24, 2014 11:54 AM, "Ameer Mawia" <am...@gmail.com> wrote:
>
>
> On Nov 24, 2014 8:30 AM, "Tay Kai Yang" <ka...@gmail.com> wrote:
> >
> > Hi Daniel
> >
> > Thanks for the reply.
> >
> > I have not used a webapp META-INF/context.xml before. So I had tried to
> > refer to online examples.
> >
> > This is what I did.
> >
> >    - Create context.xml in webapp/META-INF
> >    - This is what I have added in context.xml
> >
> >
> > >    -
> > >    - <?xml version="1.0" encoding="UTF-8"?>
> > >    - <Context copyXML="true" unpackWAR="true">
> > >    - <Valve
className="org.apache.catalina.valves.rewrite.RewriteValve"/>
> > >    - </Context>
> > >
> > > My rewrite.config in webapp/WEB-INF
> >
> > RewriteCond %{REQUEST_FILENAME} !-f
> > >
> > > RewriteCond %{REQUEST_FILENAME} !-d
> > >
> > > RewriteCond %{REQUEST_URI} !index
> > >
> > > RewriteRule (.*) index.jsp [L]
> > >
> > >
> >
> >  And in my localhost.log
> >
> > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read
> > >> configuration from: /WEB-INF/rewrite.config
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with
pattern
> > >> (.*) and substitution index.jsp
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
!-f
> > >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> > >> index.jsp
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
!-d
> > >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> > >> index.jsp
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
!index
> > >> test %{REQUEST_URI} to rule with pattern (.*) and substitution
index.jsp
> > >
> > >
> > Seems that all the required components starts up fine. But I received
this
> > error when i try to access http://localhost:8080/{webapp}/, it shows the
> > following on the response.
> >
> > *type* Exception report
> > >
> > > *message* *The resource path [null] is not valid*
> > >
> > > *description* *The server encountered an internal error that
prevented it
> > > from fulfilling this request.*
> > >
> > > *exception*
> > >
> > > java.lang.IllegalArgumentException: The resource path [null] is not
valid
> > >
 org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:237)
> > >
 org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:199)
> > >
 org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:193)
> > >
 org.apache.catalina.valves.rewrite.ResolverImpl.resolveResource(ResolverImpl.java:151)
> > >
 org.apache.catalina.valves.rewrite.RewriteCond$ResourceCondition.evaluate(RewriteCond.java:82)
> > >
 org.apache.catalina.valves.rewrite.RewriteCond.evaluate(RewriteCond.java:235)
> > >
 org.apache.catalina.valves.rewrite.RewriteRule.evaluate(RewriteRule.java:105)
> > >
 org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:311)
> > >
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
> > >
 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
> > >
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
> > >
 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
> > >
 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
> > >
 org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
> > >
 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
> > >
 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
> > >
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> > >
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> > >
 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> > >       java.lang.Thread.run(Thread.java:745)
> > >
>
> Taking hints from doc page,
http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html and your log, you
seems to be missing path prex in your substitution string. Can you prefix
/to index.jsp to your substituion string. That is:
>
> RewriteRule (.*) index.jsp [L]
RewriteRule (.*) /index.jsp [L]
>
>
> > > Checking localhost_access.log gives me
> >
> > 127.0.0.1 - - [24/Nov/2014:10:42:18 +0800] "GET /web/ HTTP/1.1" 500 2990
> >
> >
> >
> > I cannot figure out what is the problem, because I can't find anymore
> > errors, or stacktrace in any of my logfiles, catalina.stderr etc...
> >
> > I can't find any information with regard to resource path [null]. What
have
> > I missed out?
> >
> > On Fri, Nov 21, 2014 at 8:28 PM, Daniel Mikusa <dm...@pivotal.io>
wrote:
> >
> > > On Thu, Nov 20, 2014 at 9:08 PM, Tay Kai Yang <ka...@gmail.com>
> > > wrote:
> > >
> > > > Hi
> > > > I have been reading up tomcat 8's user doc. But I have some problems
> > > > understanding the setup of rewrite valve. I think I should add the
> > > rewrite
> > > > valve class name and XML settings to /conf/server.xml, but I am not
sure
> > > > what to do next. Where should I place my rewrite.config, how do I
> > > activate
> > > > rewrite my war context only?
> > > >
> > >
> > > See the second option here...
> > >
> > > http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html#Configuration
> > >
> > > "It can also be in the context.xml of a webapp. The valve will then
use a
> > > rewrite.config file containing the rewrite directives, it must be
placed in
> > > the WEB-INF folder of the web application"
> > >
> > >
> > > >
> > > > Have anyone written a tutorial or can point me to a source for
how-to?
> > > >
> > >
> > > The docs seem pretty thorough but if you need a tutorial you could
look for
> > > a mod_rewrite tutorial.  This valve is designed to be similar to
> > > mod_rewrite, so a tutorial for that should be mostly applicable here.
> > >
> > > Dan
> > >
> > >
> > > > I am trying to set a single page angularjs app to point
> > > > /context/path/path/... To /context/index.jsp
> > > >
> > > > Any idea on how to do that?
> > >
> > >
> > > > Thanks.
> > > > Kai yang
> > > >
> > >
> >
> >
> >
> > --
> > Tay Kai Yang
> > Mobile: (+65) 94879678
> > Email:  Kaiyang.Tay@Gmail.com
> > Skype: Kaiyang.Tay
>
> Regards,
> Ameer Mawia

Re: How to setup rewrite valve for angularjs

Posted by Ameer Mawia <am...@gmail.com>.
Tay,

Quickly glossing over the code, what I understand is, it is breaking while
evaluating one of the conditions mentioned in your re-write rules:


RewriteCond %{REQUEST_FILENAME} !-f
>
> RewriteCond %{REQUEST_FILENAME} !-d
>
> RewriteCond %{REQUEST_URI} !index

Basically it is trying to locate %{REQUEST_FILENAME}%, to evaluate these
conditions. But that file path is being evaluated to NULL, and this confirm
with your request:
"GET /web/ HTTP/1.1" 500 2990

assuming your "web" is your application resource root, the path relative to
this root is NULL.

Can you please try, something like:

GET /web/someXYZ.jsp

and it should NOT complained about path being NULL.

Once this is confirmed you can then find a way to handle this NULL path in
re-write rule.

Regards,
Ameer Mawia





On Mon, Nov 24, 2014 at 12:48 PM, Tay Kai Yang <ka...@gmail.com>
wrote:

> Hi
>
> I have tried to add a / to index.jsp. The problem still persist.
> It consistently complained about resource path null. What is this resource
> that it is looking for?
>  On Nov 24, 2014 2:25 PM, "Ameer Mawia" <am...@gmail.com> wrote:
>
> > On Nov 24, 2014 8:30 AM, "Tay Kai Yang" <ka...@gmail.com> wrote:
> > >
> > > Hi Daniel
> > >
> > > Thanks for the reply.
> > >
> > > I have not used a webapp META-INF/context.xml before. So I had tried to
> > > refer to online examples.
> > >
> > > This is what I did.
> > >
> > >    - Create context.xml in webapp/META-INF
> > >    - This is what I have added in context.xml
> > >
> > >
> > > >    -
> > > >    - <?xml version="1.0" encoding="UTF-8"?>
> > > >    - <Context copyXML="true" unpackWAR="true">
> > > >    - <Valve
> > className="org.apache.catalina.valves.rewrite.RewriteValve"/>
> > > >    - </Context>
> > > >
> > > > My rewrite.config in webapp/WEB-INF
> > >
> > > RewriteCond %{REQUEST_FILENAME} !-f
> > > >
> > > > RewriteCond %{REQUEST_FILENAME} !-d
> > > >
> > > > RewriteCond %{REQUEST_URI} !index
> > > >
> > > > RewriteRule (.*) index.jsp [L]
> > > >
> > > >
> > >
> > >  And in my localhost.log
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > > >> org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read
> > > >> configuration from: /WEB-INF/rewrite.config
> > > >
> > > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with
> > pattern
> > > >> (.*) and substitution index.jsp
> > > >
> > > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
> > !-f
> > > >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> > > >> index.jsp
> > > >
> > > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
> > !-d
> > > >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> > > >> index.jsp
> > > >
> > > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
> > !index
> > > >> test %{REQUEST_URI} to rule with pattern (.*) and substitution
> > index.jsp
> > > >
> > > >
> > > Seems that all the required components starts up fine. But I received
> > this
> > > error when i try to access http://localhost:8080/{webapp}/, it shows
> the
> > > following on the response.
> > >
> > > *type* Exception report
> > > >
> > > > *message* *The resource path [null] is not valid*
> > > >
> > > > *description* *The server encountered an internal error that
> prevented
> > it
> > > > from fulfilling this request.*
> > > >
> > > > *exception*
> > > >
> > > > java.lang.IllegalArgumentException: The resource path [null] is not
> > valid
> > > >
> >
> >
> org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:237)
> > > >
> >
> >
> org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:199)
> > > >
> >
> >
> org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:193)
> > > >
> >
> >
> org.apache.catalina.valves.rewrite.ResolverImpl.resolveResource(ResolverImpl.java:151)
> > > >
> >
> >
> org.apache.catalina.valves.rewrite.RewriteCond$ResourceCondition.evaluate(RewriteCond.java:82)
> > > >
> >
> >
> org.apache.catalina.valves.rewrite.RewriteCond.evaluate(RewriteCond.java:235)
> > > >
> >
> >
> org.apache.catalina.valves.rewrite.RewriteRule.evaluate(RewriteRule.java:105)
> > > >
> >
> >
> org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:311)
> > > >
> >
> >
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
> > > >
> >
> >
> org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
> > > >
> >
> >
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
> > > >
> >
> >
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
> > > >
> >
> >
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
> > > >
> >
> >
> org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
> > > >
> >
> >
> org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
> > > >
> >
> >
> org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
> > > >
> >
> >
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> > > >
> >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> > > >
> >
> >
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> > > >       java.lang.Thread.run(Thread.java:745)
> > > >
> >
> > Taking hints from doc page,
> > http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html and your log, you
> > seems to be missing path prex in your substitution string. Can you prefix
> > /to index.jsp to your substituion string. That is:
> >
> > RewriteRule (.*) index.jsp [L]
> >
> > > > Checking localhost_access.log gives me
> > >
> > > 127.0.0.1 - - [24/Nov/2014:10:42:18 +0800] "GET /web/ HTTP/1.1" 500
> 2990
> > >
> > >
> > >
> > > I cannot figure out what is the problem, because I can't find anymore
> > > errors, or stacktrace in any of my logfiles, catalina.stderr etc...
> > >
> > > I can't find any information with regard to resource path [null]. What
> > have
> > > I missed out?
> > >
> > > On Fri, Nov 21, 2014 at 8:28 PM, Daniel Mikusa <dm...@pivotal.io>
> > wrote:
> > >
> > > > On Thu, Nov 20, 2014 at 9:08 PM, Tay Kai Yang <kaiyang.tay@gmail.com
> >
> > > > wrote:
> > > >
> > > > > Hi
> > > > > I have been reading up tomcat 8's user doc. But I have some
> problems
> > > > > understanding the setup of rewrite valve. I think I should add the
> > > > rewrite
> > > > > valve class name and XML settings to /conf/server.xml, but I am not
> > sure
> > > > > what to do next. Where should I place my rewrite.config, how do I
> > > > activate
> > > > > rewrite my war context only?
> > > > >
> > > >
> > > > See the second option here...
> > > >
> > > > http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html#Configuration
> > > >
> > > > "It can also be in the context.xml of a webapp. The valve will then
> use
> > a
> > > > rewrite.config file containing the rewrite directives, it must be
> > placed in
> > > > the WEB-INF folder of the web application"
> > > >
> > > >
> > > > >
> > > > > Have anyone written a tutorial or can point me to a source for
> > how-to?
> > > > >
> > > >
> > > > The docs seem pretty thorough but if you need a tutorial you could
> look
> > for
> > > > a mod_rewrite tutorial.  This valve is designed to be similar to
> > > > mod_rewrite, so a tutorial for that should be mostly applicable here.
> > > >
> > > > Dan
> > > >
> > > >
> > > > > I am trying to set a single page angularjs app to point
> > > > > /context/path/path/... To /context/index.jsp
> > > > >
> > > > > Any idea on how to do that?
> > > >
> > > >
> > > > > Thanks.
> > > > > Kai yang
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Tay Kai Yang
> > > Mobile: (+65) 94879678
> > > Email:  Kaiyang.Tay@Gmail.com
> > > Skype: Kaiyang.Tay
> >
> > Regards,
> > Ameer Mawia
> >
>

Re: How to setup rewrite valve for angularjs

Posted by Tay Kai Yang <ka...@gmail.com>.
Hi

I have tried to add a / to index.jsp. The problem still persist.
It consistently complained about resource path null. What is this resource
that it is looking for?
 On Nov 24, 2014 2:25 PM, "Ameer Mawia" <am...@gmail.com> wrote:

> On Nov 24, 2014 8:30 AM, "Tay Kai Yang" <ka...@gmail.com> wrote:
> >
> > Hi Daniel
> >
> > Thanks for the reply.
> >
> > I have not used a webapp META-INF/context.xml before. So I had tried to
> > refer to online examples.
> >
> > This is what I did.
> >
> >    - Create context.xml in webapp/META-INF
> >    - This is what I have added in context.xml
> >
> >
> > >    -
> > >    - <?xml version="1.0" encoding="UTF-8"?>
> > >    - <Context copyXML="true" unpackWAR="true">
> > >    - <Valve
> className="org.apache.catalina.valves.rewrite.RewriteValve"/>
> > >    - </Context>
> > >
> > > My rewrite.config in webapp/WEB-INF
> >
> > RewriteCond %{REQUEST_FILENAME} !-f
> > >
> > > RewriteCond %{REQUEST_FILENAME} !-d
> > >
> > > RewriteCond %{REQUEST_URI} !index
> > >
> > > RewriteRule (.*) index.jsp [L]
> > >
> > >
> >
> >  And in my localhost.log
> >
> > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read
> > >> configuration from: /WEB-INF/rewrite.config
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with
> pattern
> > >> (.*) and substitution index.jsp
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
> !-f
> > >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> > >> index.jsp
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
> !-d
> > >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> > >> index.jsp
> > >
> > > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> > >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
> !index
> > >> test %{REQUEST_URI} to rule with pattern (.*) and substitution
> index.jsp
> > >
> > >
> > Seems that all the required components starts up fine. But I received
> this
> > error when i try to access http://localhost:8080/{webapp}/, it shows the
> > following on the response.
> >
> > *type* Exception report
> > >
> > > *message* *The resource path [null] is not valid*
> > >
> > > *description* *The server encountered an internal error that prevented
> it
> > > from fulfilling this request.*
> > >
> > > *exception*
> > >
> > > java.lang.IllegalArgumentException: The resource path [null] is not
> valid
> > >
>
>  org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:237)
> > >
>
>  org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:199)
> > >
>
>  org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:193)
> > >
>
>  org.apache.catalina.valves.rewrite.ResolverImpl.resolveResource(ResolverImpl.java:151)
> > >
>
>  org.apache.catalina.valves.rewrite.RewriteCond$ResourceCondition.evaluate(RewriteCond.java:82)
> > >
>
>  org.apache.catalina.valves.rewrite.RewriteCond.evaluate(RewriteCond.java:235)
> > >
>
>  org.apache.catalina.valves.rewrite.RewriteRule.evaluate(RewriteRule.java:105)
> > >
>
>  org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:311)
> > >
>
>  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
> > >
>
>  org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
> > >
>
>  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
> > >
>
>  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
> > >
>
>  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
> > >
>
>  org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
> > >
>
>  org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
> > >
>
>  org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
> > >
>
>  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> > >
>
>  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> > >
>
>  org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> > >       java.lang.Thread.run(Thread.java:745)
> > >
>
> Taking hints from doc page,
> http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html and your log, you
> seems to be missing path prex in your substitution string. Can you prefix
> /to index.jsp to your substituion string. That is:
>
> RewriteRule (.*) index.jsp [L]
>
> > > Checking localhost_access.log gives me
> >
> > 127.0.0.1 - - [24/Nov/2014:10:42:18 +0800] "GET /web/ HTTP/1.1" 500 2990
> >
> >
> >
> > I cannot figure out what is the problem, because I can't find anymore
> > errors, or stacktrace in any of my logfiles, catalina.stderr etc...
> >
> > I can't find any information with regard to resource path [null]. What
> have
> > I missed out?
> >
> > On Fri, Nov 21, 2014 at 8:28 PM, Daniel Mikusa <dm...@pivotal.io>
> wrote:
> >
> > > On Thu, Nov 20, 2014 at 9:08 PM, Tay Kai Yang <ka...@gmail.com>
> > > wrote:
> > >
> > > > Hi
> > > > I have been reading up tomcat 8's user doc. But I have some problems
> > > > understanding the setup of rewrite valve. I think I should add the
> > > rewrite
> > > > valve class name and XML settings to /conf/server.xml, but I am not
> sure
> > > > what to do next. Where should I place my rewrite.config, how do I
> > > activate
> > > > rewrite my war context only?
> > > >
> > >
> > > See the second option here...
> > >
> > > http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html#Configuration
> > >
> > > "It can also be in the context.xml of a webapp. The valve will then use
> a
> > > rewrite.config file containing the rewrite directives, it must be
> placed in
> > > the WEB-INF folder of the web application"
> > >
> > >
> > > >
> > > > Have anyone written a tutorial or can point me to a source for
> how-to?
> > > >
> > >
> > > The docs seem pretty thorough but if you need a tutorial you could look
> for
> > > a mod_rewrite tutorial.  This valve is designed to be similar to
> > > mod_rewrite, so a tutorial for that should be mostly applicable here.
> > >
> > > Dan
> > >
> > >
> > > > I am trying to set a single page angularjs app to point
> > > > /context/path/path/... To /context/index.jsp
> > > >
> > > > Any idea on how to do that?
> > >
> > >
> > > > Thanks.
> > > > Kai yang
> > > >
> > >
> >
> >
> >
> > --
> > Tay Kai Yang
> > Mobile: (+65) 94879678
> > Email:  Kaiyang.Tay@Gmail.com
> > Skype: Kaiyang.Tay
>
> Regards,
> Ameer Mawia
>

Re: How to setup rewrite valve for angularjs

Posted by Ameer Mawia <am...@gmail.com>.
On Nov 24, 2014 8:30 AM, "Tay Kai Yang" <ka...@gmail.com> wrote:
>
> Hi Daniel
>
> Thanks for the reply.
>
> I have not used a webapp META-INF/context.xml before. So I had tried to
> refer to online examples.
>
> This is what I did.
>
>    - Create context.xml in webapp/META-INF
>    - This is what I have added in context.xml
>
>
> >    -
> >    - <?xml version="1.0" encoding="UTF-8"?>
> >    - <Context copyXML="true" unpackWAR="true">
> >    - <Valve
className="org.apache.catalina.valves.rewrite.RewriteValve"/>
> >    - </Context>
> >
> > My rewrite.config in webapp/WEB-INF
>
> RewriteCond %{REQUEST_FILENAME} !-f
> >
> > RewriteCond %{REQUEST_FILENAME} !-d
> >
> > RewriteCond %{REQUEST_URI} !index
> >
> > RewriteRule (.*) index.jsp [L]
> >
> >
>
>  And in my localhost.log
>
> 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> >> org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read
> >> configuration from: /WEB-INF/rewrite.config
> >
> > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with
pattern
> >> (.*) and substitution index.jsp
> >
> > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition !-f
> >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> >> index.jsp
> >
> > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition !-d
> >> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
> >> index.jsp
> >
> > 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
> >> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition
!index
> >> test %{REQUEST_URI} to rule with pattern (.*) and substitution
index.jsp
> >
> >
> Seems that all the required components starts up fine. But I received this
> error when i try to access http://localhost:8080/{webapp}/, it shows the
> following on the response.
>
> *type* Exception report
> >
> > *message* *The resource path [null] is not valid*
> >
> > *description* *The server encountered an internal error that prevented
it
> > from fulfilling this request.*
> >
> > *exception*
> >
> > java.lang.IllegalArgumentException: The resource path [null] is not
valid
> >
 org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:237)
> >
 org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:199)
> >
 org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:193)
> >
 org.apache.catalina.valves.rewrite.ResolverImpl.resolveResource(ResolverImpl.java:151)
> >
 org.apache.catalina.valves.rewrite.RewriteCond$ResourceCondition.evaluate(RewriteCond.java:82)
> >
 org.apache.catalina.valves.rewrite.RewriteCond.evaluate(RewriteCond.java:235)
> >
 org.apache.catalina.valves.rewrite.RewriteRule.evaluate(RewriteRule.java:105)
> >
 org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:311)
> >
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
> >
 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
> >
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
> >
 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
> >
 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
> >
 org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
> >
 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
> >
 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
> >
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> >
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> >
 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> >       java.lang.Thread.run(Thread.java:745)
> >

Taking hints from doc page,
http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html and your log, you
seems to be missing path prex in your substitution string. Can you prefix
/to index.jsp to your substituion string. That is:

RewriteRule (.*) index.jsp [L]

> > Checking localhost_access.log gives me
>
> 127.0.0.1 - - [24/Nov/2014:10:42:18 +0800] "GET /web/ HTTP/1.1" 500 2990
>
>
>
> I cannot figure out what is the problem, because I can't find anymore
> errors, or stacktrace in any of my logfiles, catalina.stderr etc...
>
> I can't find any information with regard to resource path [null]. What
have
> I missed out?
>
> On Fri, Nov 21, 2014 at 8:28 PM, Daniel Mikusa <dm...@pivotal.io> wrote:
>
> > On Thu, Nov 20, 2014 at 9:08 PM, Tay Kai Yang <ka...@gmail.com>
> > wrote:
> >
> > > Hi
> > > I have been reading up tomcat 8's user doc. But I have some problems
> > > understanding the setup of rewrite valve. I think I should add the
> > rewrite
> > > valve class name and XML settings to /conf/server.xml, but I am not
sure
> > > what to do next. Where should I place my rewrite.config, how do I
> > activate
> > > rewrite my war context only?
> > >
> >
> > See the second option here...
> >
> > http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html#Configuration
> >
> > "It can also be in the context.xml of a webapp. The valve will then use
a
> > rewrite.config file containing the rewrite directives, it must be
placed in
> > the WEB-INF folder of the web application"
> >
> >
> > >
> > > Have anyone written a tutorial or can point me to a source for how-to?
> > >
> >
> > The docs seem pretty thorough but if you need a tutorial you could look
for
> > a mod_rewrite tutorial.  This valve is designed to be similar to
> > mod_rewrite, so a tutorial for that should be mostly applicable here.
> >
> > Dan
> >
> >
> > > I am trying to set a single page angularjs app to point
> > > /context/path/path/... To /context/index.jsp
> > >
> > > Any idea on how to do that?
> >
> >
> > > Thanks.
> > > Kai yang
> > >
> >
>
>
>
> --
> Tay Kai Yang
> Mobile: (+65) 94879678
> Email:  Kaiyang.Tay@Gmail.com
> Skype: Kaiyang.Tay

Regards,
Ameer Mawia

Re: How to setup rewrite valve for angularjs

Posted by Tay Kai Yang <ka...@gmail.com>.
Hi Daniel

Thanks for the reply.

I have not used a webapp META-INF/context.xml before. So I had tried to
refer to online examples.

This is what I did.

   - Create context.xml in webapp/META-INF
   - This is what I have added in context.xml


>    -
>    - <?xml version="1.0" encoding="UTF-8"?>
>    - <Context copyXML="true" unpackWAR="true">
>    - <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
>    - </Context>
>
> My rewrite.config in webapp/WEB-INF

RewriteCond %{REQUEST_FILENAME} !-f
>
> RewriteCond %{REQUEST_FILENAME} !-d
>
> RewriteCond %{REQUEST_URI} !index
>
> RewriteRule (.*) index.jsp [L]
>
>

 And in my localhost.log

24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
>> org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read
>> configuration from: /WEB-INF/rewrite.config
>
> 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
>> org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with pattern
>> (.*) and substitution index.jsp
>
> 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
>> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition !-f
>> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
>> index.jsp
>
> 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
>> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition !-d
>> test %{REQUEST_FILENAME} to rule with pattern (.*) and substitution
>> index.jsp
>
> 24-Nov-2014 10:39:56.163 FINE [localhost-startStop-1]
>> org.apache.catalina.valves.rewrite.RewriteValve.parse Add condition !index
>> test %{REQUEST_URI} to rule with pattern (.*) and substitution index.jsp
>
>
Seems that all the required components starts up fine. But I received this
error when i try to access http://localhost:8080/{webapp}/, it shows the
following on the response.

*type* Exception report
>
> *message* *The resource path [null] is not valid*
>
> *description* *The server encountered an internal error that prevented it
> from fulfilling this request.*
>
> *exception*
>
> java.lang.IllegalArgumentException: The resource path [null] is not valid
> 	org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:237)
> 	org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:199)
> 	org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:193)
> 	org.apache.catalina.valves.rewrite.ResolverImpl.resolveResource(ResolverImpl.java:151)
> 	org.apache.catalina.valves.rewrite.RewriteCond$ResourceCondition.evaluate(RewriteCond.java:82)
> 	org.apache.catalina.valves.rewrite.RewriteCond.evaluate(RewriteCond.java:235)
> 	org.apache.catalina.valves.rewrite.RewriteRule.evaluate(RewriteRule.java:105)
> 	org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:311)
> 	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
> 	org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
> 	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
> 	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
> 	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
> 	org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
> 	org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
> 	org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
> 	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> 	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> 	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> 	java.lang.Thread.run(Thread.java:745)
>
> Checking localhost_access.log gives me

127.0.0.1 - - [24/Nov/2014:10:42:18 +0800] "GET /web/ HTTP/1.1" 500 2990



I cannot figure out what is the problem, because I can't find anymore
errors, or stacktrace in any of my logfiles, catalina.stderr etc...

I can't find any information with regard to resource path [null]. What have
I missed out?

On Fri, Nov 21, 2014 at 8:28 PM, Daniel Mikusa <dm...@pivotal.io> wrote:

> On Thu, Nov 20, 2014 at 9:08 PM, Tay Kai Yang <ka...@gmail.com>
> wrote:
>
> > Hi
> > I have been reading up tomcat 8's user doc. But I have some problems
> > understanding the setup of rewrite valve. I think I should add the
> rewrite
> > valve class name and XML settings to /conf/server.xml, but I am not sure
> > what to do next. Where should I place my rewrite.config, how do I
> activate
> > rewrite my war context only?
> >
>
> See the second option here...
>
> http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html#Configuration
>
> "It can also be in the context.xml of a webapp. The valve will then use a
> rewrite.config file containing the rewrite directives, it must be placed in
> the WEB-INF folder of the web application"
>
>
> >
> > Have anyone written a tutorial or can point me to a source for how-to?
> >
>
> The docs seem pretty thorough but if you need a tutorial you could look for
> a mod_rewrite tutorial.  This valve is designed to be similar to
> mod_rewrite, so a tutorial for that should be mostly applicable here.
>
> Dan
>
>
> > I am trying to set a single page angularjs app to point
> > /context/path/path/... To /context/index.jsp
> >
> > Any idea on how to do that?
>
>
> > Thanks.
> > Kai yang
> >
>



-- 
Tay Kai Yang
Mobile: (+65) 94879678
Email:  Kaiyang.Tay@Gmail.com
Skype: Kaiyang.Tay

Re: How to setup rewrite valve for angularjs

Posted by Daniel Mikusa <dm...@pivotal.io>.
On Thu, Nov 20, 2014 at 9:08 PM, Tay Kai Yang <ka...@gmail.com> wrote:

> Hi
> I have been reading up tomcat 8's user doc. But I have some problems
> understanding the setup of rewrite valve. I think I should add the rewrite
> valve class name and XML settings to /conf/server.xml, but I am not sure
> what to do next. Where should I place my rewrite.config, how do I activate
> rewrite my war context only?
>

See the second option here...

http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html#Configuration

"It can also be in the context.xml of a webapp. The valve will then use a
rewrite.config file containing the rewrite directives, it must be placed in
the WEB-INF folder of the web application"


>
> Have anyone written a tutorial or can point me to a source for how-to?
>

The docs seem pretty thorough but if you need a tutorial you could look for
a mod_rewrite tutorial.  This valve is designed to be similar to
mod_rewrite, so a tutorial for that should be mostly applicable here.

Dan


> I am trying to set a single page angularjs app to point
> /context/path/path/... To /context/index.jsp
>
> Any idea on how to do that?


> Thanks.
> Kai yang
>