org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/'

Spring JIRA | Nazar Vishka | 9 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    If a client is sending a POST message with an empty/invalid header 'Content-Type' the request fails with [InvalidMediaTypeException|https://github.com/spring-projects/spring-framework/blob/v4.2.6.RELEASE/spring-web/src/main/java/org/springframework/http/InvalidMediaTypeException.java]. {code}org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/' at org.springframework.http.MediaType.parseMediaType(MediaType.java:385) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:722) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.http.server.ServletServerHttpRequest.getHeaders(ServletServerHttpRequest.java:116) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:810) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:71) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.handler.AbstractHandlerMapping$CorsInterceptor.preHandle(AbstractHandlerMapping.java:503) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) [spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870) [spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] {code} I think that [org.springframework.http.HttpHeaders#getContentType|https://github.com/spring-projects/spring-framework/blob/v4.2.6.RELEASE/spring-web/src/main/java/org/springframework/http/HttpHeaders.java#L720-L723] should handle InvalidMediaTypeException exception and return null in such cases or you should change behaviour of [org.springframework.http.MediaType#parseMediaType|https://github.com/spring-projects/spring-framework/blob/v4.2.6.RELEASE/spring-web/src/main/java/org/springframework/http/MediaType.java#L379-L393]

    Spring JIRA | 9 months ago | Nazar Vishka
    org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/'
  2. 0

    If a client is sending a POST message with an empty/invalid header 'Content-Type' the request fails with [InvalidMediaTypeException|https://github.com/spring-projects/spring-framework/blob/v4.2.6.RELEASE/spring-web/src/main/java/org/springframework/http/InvalidMediaTypeException.java]. {code}org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/' at org.springframework.http.MediaType.parseMediaType(MediaType.java:385) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:722) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.http.server.ServletServerHttpRequest.getHeaders(ServletServerHttpRequest.java:116) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:810) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:71) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.handler.AbstractHandlerMapping$CorsInterceptor.preHandle(AbstractHandlerMapping.java:503) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) [spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870) [spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE] {code} I think that [org.springframework.http.HttpHeaders#getContentType|https://github.com/spring-projects/spring-framework/blob/v4.2.6.RELEASE/spring-web/src/main/java/org/springframework/http/HttpHeaders.java#L720-L723] should handle InvalidMediaTypeException exception and return null in such cases or you should change behaviour of [org.springframework.http.MediaType#parseMediaType|https://github.com/spring-projects/spring-framework/blob/v4.2.6.RELEASE/spring-web/src/main/java/org/springframework/http/MediaType.java#L379-L393]

    Spring JIRA | 9 months ago | Nazar Vishka
    org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/'

    Root Cause Analysis

    1. org.springframework.http.InvalidMediaTypeException

      Invalid mime type "null": does not contain '/'

      at org.springframework.http.MediaType.parseMediaType()
    2. Spring
      WebUtils.isSameOrigin
      1. org.springframework.http.MediaType.parseMediaType(MediaType.java:385)[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      2. org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:722)[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      3. org.springframework.http.server.ServletServerHttpRequest.getHeaders(ServletServerHttpRequest.java:116)[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      4. org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:810)[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      4 frames
    3. org.springframework.web
      DefaultCorsProcessor.processRequest
      1. org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:71)[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      1 frame
    4. Spring MVC
      FrameworkServlet.doPost
      1. org.springframework.web.servlet.handler.AbstractHandlerMapping$CorsInterceptor.preHandle(AbstractHandlerMapping.java:503)[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      2. org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134)[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      3. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954)[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      4. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      5. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      6. org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870)[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
      6 frames