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

Spring JIRA | Nazar Vishka | 6 months ago
  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 | 6 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 | 6 months ago | Nazar Vishka
    org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/'
  3. 0

    Spring RestTemplate throws InvalidMediaTypeException

    Stack Overflow | 2 months ago | Vlad Kudryavtsev
    org.springframework.http.InvalidMediaTypeException: Invalid mime type "xml": does not contain '/'
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring: How to avoid InvalidMimeTypeException in WFS request ("text/xml; subtype=gml/2.1.2")

    Stack Overflow | 1 year ago | Hannes Smit
    org.springframework.http.InvalidMediaTypeException: Invalid mime type "text/xml; subtype=gml/2.1.2": Invalid token character '/' in token "gml/2.1.2"
  6. 0

    Spring - RestTemplate throwing InvalidMediaTypeException

    Stack Overflow | 3 years ago | Raja Asthana
    org.springframework.http.InvalidMediaTypeException: Invalid media type "multipart/mixed;boundary=simple boundary;charset=UTF-8": Invalid token character ' ' in token "simple boundary"

    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