title: Stopping Jetty from throwing stacktrace whenever it receives an invalid HTTP request
body: <p>I am running my servlet application within Jetty, and it sometimes outputs the below-shown stack trace. I think this means it is receiving an invalid URL request, but I can't actually see the request. Can I handle this exception somwehere so that my logs are not clogged up with this nasty stack trace? And if so can it handled in my code, or does this error occur before getting to my code and therefore needs to be handled with Jetty configuration?</p>
  
  <p><strong>EDIT</strong>
  So if I did move to Jeety 9 how could I configure it so the stacktrace goes and could I configure a suitable http response code</p>
  
  <p>Alternaively, I've realized that jetty is receiving the request after it has been processed by <a href="http://tuckey.org/urlrewrite/" rel="nofollow">http://tuckey.org/urlrewrite/</a>, is there something sensible I should configure in UrlRewriteFilter to do something else if the generated url is invalid.</p>
  
  <pre><code>2013-01-11 23:48:10.939:WARN:oeju.UrlEncoded:org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! byte B0 in state 0
  2013-01-11 23:48:10.939:WARN:oejs.ServletHandler:/ws/2/release/
  org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! byte B0 in state 0
  at org.eclipse.jetty.util.Utf8Appendable.appendByte(Utf8Appendable.java:174)
  at org.eclipse.jetty.util.Utf8Appendable.append(Utf8Appendable.java:99)
  at org.eclipse.jetty.util.UrlEncoded.decodeString(UrlEncoded.java:709)
  at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:251)
  at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:187)
  at org.eclipse.jetty.server.Request.mergeQueryString(Request.java:2045)
  at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:244)
  at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:103)
  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:381)
  at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:559)
  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
  at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
  at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
  at org.eclipse.jetty.server.Server.handle(Server.java:365)
  at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
  at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
  at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
  at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
  at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
  at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
  at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
  at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
  at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p><strong>EDIT</strong>
  It has been suggested that maybe this could be handled in my tuckey configuration so thsi is what it currently looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"
          "http://tuckey.org/res/dtds/urlrewrite3.1.dtd"&gt;
  
  &lt;!--
  
      Configuration file for UrlRewriteFilter
      http://tuckey.org/urlrewrite/
  
  --&gt;
  &lt;urlrewrite use-query-string="true"&gt;
      &lt;rule&gt;
         &lt;note&gt;
             Matches urls like http://localhost:8080/ws/1/artist/?query=blur&amp;amp;fmt=xml
             and converts to http://localhost:8080/?type=artist&amp;amp;query=blur&amp;amp;fmt=xml&amp;amp;version=1
         &lt;/note&gt;
         &lt;from&gt;^/ws/(\d)/(.*)/\?(.*)$&lt;/from&gt;
         &lt;to&gt;/?version=$1&amp;amp;type=$2&amp;amp;$3&lt;/to&gt;
       &lt;/rule&gt;
  
      &lt;rule&gt;
          &lt;note&gt;
              The rule means that requests to /test/status/ will be redirected to /rewrite-status
              the url will be rewritten.
          &lt;/note&gt;
          &lt;from&gt;/test/status/&lt;/from&gt;
          &lt;to type="redirect"&gt;%{context-path}/rewrite-status&lt;/to&gt;
      &lt;/rule&gt;
  
  
      &lt;outbound-rule&gt;
          &lt;note&gt;
              The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
              the url /rewrite-status will be rewritten to /test/status/.
  
              The above rule and this outbound-rule means that end users should never see the
              url /rewrite-status only /test/status/ both in their location bar and in hyperlinks
              in your pages.
          &lt;/note&gt;
          &lt;from&gt;/rewrite-status&lt;/from&gt;
          &lt;to&gt;/test/status/&lt;/to&gt;
      &lt;/outbound-rule&gt;
  &lt;/urlrewrite&gt;
  </code></pre>