I recently switched from Tomcat to Jetty and since then, I can see this kind of WARN in my logs.
WARN org.eclipse.jetty.http.HttpParser - URI is too large >65535
WARN org.eclipse.jetty.http.HttpParser - bad HTTP parsed: 414 for HttpChannelOverHttp@34ff28{r=0,c=false,a=IDLE,uri=null}
I am looking for a way to change the response returned when this happens (I would prefer a json response over the HTML one that is returned by default) and not log a warning. Is this something that can be done? After some reseach, it seems that this error is logged before any place were I could inject some code to handle this (like a servlet filter for exemple)
This is the category of errors known as "Bad Request" and occur very early in the processing of the incoming request.
Some examples of Bad Requests
400 Bad Request (common)
412 Precondition Failed (rather esoteric, rare)
413 Request Entity Too Large (very common)
414 URI Too Long (very common)
431 Requested Header Fields Too Large (not produced by Jetty, yet)
A Bad Request has no request URI, and consequently cannot be sent down to the context for that context to handle it.
These kinds of bad requests also have no headers, so you couldn't even check the Accept
header to make a determination if you should even send a response back as application/json
The most common reasons people see these response codes: