Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuckey UrlRewrite: ClassNotFoundException after changing urlrewrite.xml

I'd like to be able to change the rules in urlrewrite.xml without restarting the server.

I am running Tomcat 7. In web.xml I have...

  <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
      <param-name>confReloadCheckInterval</param-name>
      <param-value>120</param-value>
    </init-param>
    <init-param>
      <param-name>logLevel</param-name>
      <param-value>INFO</param-value>
    </init-param>
  </filter>

When I change the value of a <to> element in urlrewrite.xml, trying to execute that rule causes an exception.

java.lang.ClassNotFoundException: org.apache.jsp.s1.content.about_002dus_jsp at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132) at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:145) at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338) at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at au.com.pawsforlife.vizsla.controller.UserFilter.doFilter(UserFilter.java:81) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

Does anyone know why this happens, or at least how to fix it?

Thanks!

like image 912
WoodenKitty Avatar asked Feb 24 '15 23:02

WoodenKitty


2 Answers

I think that is not the proper way to modify the rules dynamically. Check the Extending UrlRewriteFilter section in the manual.

Instead of rule tag, you should use class-rule. You specify a class, that will dynamically load the rules from a resource.

They have an example of a simple rule.

So basically you can't simply modify the XML file, you have to load the rules runtime, this way you can load any rules before the rewriting.

like image 121
gaRos Avatar answered Nov 10 '22 21:11

gaRos


I had a similar exception in the past but I don't remember the details. That's why I am sharing my urlrewrite.xml and web.xml examples from a simple project. I hope it helps. urlrewrite.xml:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
  3         "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
  4
  5 <!--
  6
  7     Configuration file for UrlRewriteFilter
  8     http://www.tuckey.org/urlrewrite/
  9
 10 -->
 11 <urlrewrite>
 12
 13     <rule>
 14         <from>^/OA_HTML/(.*)$</from>
 15         <to type="redirect">/tuckeyUrl/$1</to>
 16     </rule>
 17
78 </urlrewrite>

web.xml:

 <?xml version="1.0" encoding="ISO-8859-1"?>
  2
  3 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  4      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  6      version="2.4">
  7
  8 <filter>
  9     <filter-name>UrlRewriteFilter</filter-name>
 10     <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
 11 </filter>
 12 <filter-mapping>
 13     <filter-name>UrlRewriteFilter</filter-name>
 14     <url-pattern>/*</url-pattern>
 15     <dispatcher>REQUEST</dispatcher>
 16     <dispatcher>FORWARD</dispatcher>
 17 </filter-mapping>
 39 </web-app>

I also remember I had another exception. I fixed with removing the extra line before the first line

<?xml version="1.0" encoding="ISO-8859-1"?> 

from my web.xml.

like image 33
melis Avatar answered Nov 10 '22 19:11

melis