-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid MIME-type causes a 500 error [SPR-7712] #12368
Comments
Tristan Burch commented Is there a timeline for this getting fixed? I agree that a 406 should be retured in this case. |
Juergen Hoeller commented Fixed for both 3.1 RC1 and 3.0.6, handling an invalid accept header like a general non-match: returning null for ViewResolver chaining, or sending 406 if ContentNegotiatingViewResolver's "useNotAcceptableStatusCode" property has been set to "true". Juergen |
David commented We're using Spring 3.1.0RELEASE and still see this. Did the fix in 3.1RC1 make it to RELEASE? Note: I think 400 would be more appropriate than 406; I think 406 assumes a valid media type Here is the stack trace I got
type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception root cause |
Juergen Hoeller commented Rossen, can you have a look at this please? I'm pretty sure there's no regression but it might be something we never properly fixed... Juergen |
Rossen Stoyanchev commented There were a number of places exposed to invalid media types. The stack trace from David above is different from the one in the original comment. We applied a more comprehensive fix in the 3.2.x timeline and backported it to 3.1.x (see commit 83ac44 including the link to the backport commit). There are tests specifically for ProducesRequestCondition there. |
Juergen Hoeller commented Alright, Rossen, let's consider this one as fixed as of 3.1.2 then - and open a follow-up issue if needed. David, note that the 3.1.x line is retired already, so please upgrade to a recent 3.2.x release and check whether any issues remain there. Juergen |
Brett opened SPR-7712 and commented
I have a REST service setup with the ContentNegotiatingViewResolver to transform responses into either xml or json based on the Accept header. I set the useNotAcceptableStatusCode property to true and it appears to work as expected. However, if the Accept header is a completely invalid media type like 'foo' then an exception is thrown and the consumer ends up getting back a 500 Internal Server Error instead of the expected 406. The top of the resulting stack trace is included below:
SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception
java.lang.IllegalArgumentException: "foo" does not contain '/'
at org.springframework.http.MediaType.parseMediaType(MediaType.java:562)
at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:602)
at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.getMediaTypes(ContentNegotiatingViewResolver.java:306)
at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:366)
at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1078)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1027)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerner.net.oauth.j2ee.filter.OAuthValidatorFilter$1.run(OAuthValidatorFilter.java:215)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at com.cerner.net.oauth.j2ee.filter.OAuthValidatorFilter.doFilter(OAuthValidatorFilter.java:213)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
...
Considering that an invalid media type is a problem with the client making the request to the service, I think it should return a proper 406 response if the useNotAcceptableStatusCode flag is set.
Affects: 3.0.4, 3.0.5
Reference URL: http://forum.springsource.org/showthread.php?p=317618#post317618
Referenced from: commits cb0c0c5, 0a48936
Backported to: 3.0.6
4 votes, 6 watchers
The text was updated successfully, but these errors were encountered: