Closed
Description
Every now and then I find the InvalidMimeTypeException followed by a stack trace in my logfiles. These are apparently erroneous queries, but in the end they do not bother at all. Therefore, it is annoying that they take up so much space in the log file. You can find one of these error messages below.
I think I found the location where the InvalidMimeTypeException should be handled:
This is how the exception could be handled. The the logic is reasonably preserved, an invalid Accept header is treated as not provided:
try {
return MediaType.parseMediaTypes(acceptHeader);
} catch( InvalidMimeTypeException ignore ) {
return MEDIA_TYPES_ALL
}
An example error message with shortened stack trace:
11:58:09.133 [http-nio-8080-exec-108] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.http.InvalidMediaTypeException: Invalid mime type "*/*q=0.8": wildcard type is legal only in '*/*' (all mime types)] with root cause
org.springframework.util.InvalidMimeTypeException: Invalid mime type "*/*q=0.8": wildcard type is legal only in '*/*' (all mime types)
at org.springframework.util.MimeTypeUtils.parseMimeTypeInternal(MimeTypeUtils.java:237)
at org.springframework.util.ConcurrentLruCache.get(ConcurrentLruCache.java:100)
at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:213)
at org.springframework.http.MediaType.parseMediaType(MediaType.java:739)
at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:768)
at org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping.getAcceptedMediaTypes(WelcomePageHandlerMapping.java:82)
at org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping.isHtmlTextAccepted(WelcomePageHandlerMapping.java:71)
at org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping.getHandlerInternal(WelcomePageHandlerMapping.java:67)
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:505)