Jetty9 for url-rewrite

854 views Asked by At

Hi I am using the jetty7 for url-rewriting so i have modified my jetty.xml file according to the url http://wiki.eclipse.org/Jetty/Feature/Rewrite_Handler And i am using intelij idea for development.

<New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
  <Set name="rewriteRequestURI">true</Set>
  <Set name="rewritePathInfo">false</Set>
  <Set name="originalPathAttribute">requestedPath</Set>

  <!-- redirect the response. This is a redirect which is visible to the browser.
       After the redirect, the browser address bar will show /redirected -->
  <Call name="addRule">
    <Arg>
      <New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
        <Set name="pattern">/redirect</Set>
        <Set name="location">/redirected</Set>
      </New>
    </Arg>
  </Call>

  <!-- This rewrites the base URL; supports Regex. This is visible to the browser. -->
  <Call name="addRule">
    <Arg>
      <New class="org.eclipse.jetty.rewrite.handler.RedirectRegexRule">
        <Set name="regex">(^(?!/base/path/).*)</Set>
        <Set name="replacement">/base/path/</Set>
      </New>
    </Arg>
  </Call>
</New>

  <!-- rewrite the request URI. This is an internal rewrite, visible to server,
       but the browser will still show /some/old/context -->
  <Call name="addRule">
    <Arg>
      <New class="org.eclipse.jetty.rewrite.handler.RewritePatternRule">
        <Set name="pattern">/some/old/context</Set>
        <Set name="replacement">/some/new/context</Set>
      </New>
    </Arg>
  </Call>

  <!-- reverse the order of the path sections. Internal rewrite -->
  <Call name="addRule">
    <Arg>
      <New class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
        <Set name="regex">/reverse/([^/]*)/(.*)</Set>
        <Set name="replacement">/reverse/$2/$1</Set>
      </New>
    </Arg>
  </Call>
</New>

 <!-- add the rewrite handler to the server -->
<Set name="handler"><Ref id="Rewrite" /></Set>

When i was running the server i am getting following error. stack trace is as follows.

WARN:oejx.XmlConfiguration:Config error at <New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler"><Set name="rewriteRequestURI">true</Set><Set name="rewritePathInfo">false</Set><Set name="originalPathAttribute">requestedPath</Set><Call name="addRule"><Arg>|                    <New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule"><Set name="pattern">/redirect/\*</Set><Set name="location">/redirected</Set></New>|                </Arg></Call><Call name="addRule"><Arg>|                    <New class="org.eclipse.jetty.rewrite.handler.RedirectRegexRule"><Set name="regex">(^(?!/base/path/).*)</Set><Set name="replacement">/base/path/</Set></New>|                </Arg></Call><Call name="addRule"><Arg>|                    <New class="org.eclipse.jetty.rewrite.handler.RewritePatternRule"><Set name="pattern">/some/old/context</Set><Set name="replacement">/some/new/context</Set></New>|                </Arg></Call><Call name="addRule"><Arg>|                    <New class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule"><Set name="regex">/reverse/([^/]*)/(.*)</Set><Set name="replacement">/reverse/$2/$1</Set></New>|                </Arg></Call></New> java.lang.ClassNotFoundException: 
   java.lang.reflect.InvocationTargetException
    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.eclipse.jetty.start.Main.invokeMain(Main.java:473)
    at org.eclipse.jetty.start.Main.start(Main.java:615)
    at org.eclipse.jetty.start.Main.main(Main.java:96)
    Caused by:java.lang.ClassNotFoundException:org.eclipse.jetty.rewrite.handler.RewriteHandler
    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 java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.eclipse.jetty.util.Loader.loadClass(Loader.java:100)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.nodeClass(XmlConfiguration.java:366)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:767)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:404)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:355)
    at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:296)
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1262)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1197)
    ...7more

    Usage:java-jar start.jar[options][properties][configs]
    java-jar start.jar--help  # for more information
0

There are 0 answers