java.lang.IllegalArgumentException: Invalid token character ':' in token "http://www.wapforum.org/xhtml"

Spring JIRA | David Pacheco | 5 years 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

    A HTTP request with the following Accept header Accept: application/xhtml+xml; profile="http://www.wapforum.org/xhtml", application/vnd.wap.xhtml+xml to a String Controller, causes the following exception to be thrown: {code:java} SEVERE: Servlet.service() for servlet dispatcher threw exception java.lang.IllegalArgumentException: Invalid token character ':' in token "http://www.wapforum.org/xhtml" at org.springframework.http.MediaType.checkToken(MediaType.java:282) at org.springframework.http.MediaType.checkParameters(MediaType.java:302) at org.springframework.http.MediaType.<init>(MediaType.java:263) at org.springframework.http.MediaType.parseMediaType(MediaType.java:584) at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:286) at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:97) at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:1) at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:973) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:931) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:880) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:429) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717) 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) {code} In brief: This is due to the AbstractHttpMessageConverter write method calling the headers.setContentType() method of the outputMessage parameter with a MediaType with the following value "application/xhtml+xml;profile=http://www.wapforum.org/xhtml". Note the lack of quotes around the profile value part. The program flow is: The MediaType is parsed from the HTTP Accept header with the value application/xhtml+xml;profile="http://www.wapforum.org/xhtml" Note - The inclusion of the quotes means that this value does not trigger the checkToken(String) method of MediaType. In the StringHttpMessageConverter write method, a call is made to set the content type for the outputMessage. This uses the toString() method of MediaType to set the Content-Type header, this results in the value being set to "application/xhtml+xml;profile=http://www.wapforum.org/xhtml". Next the writeInternal method of StringHttpMessageConverter is called, this tries to get the MediaType for the outputMessage by calling outputMessage.getHeaders().getContentType(), which in turn calls MediaType.parseMediaType(value) with the value of "application/xhtml+xml;profile=http://www.wapforum.org/xhtml", due to the missing quotes in the profile parameter value, this will now trigger the checkToken(String) method of MediaType which ultimately results in the IllegalArgumentException being thrown. ----- Example request headers GET /index.html HTTP/1.1 Accept: application/xhtml+xml; profile="http://www.wapforum.org/xhtml", application/vnd.wap.xhtml+xml Accept-Language: en-us Host: app.example.com Connection: Keep-Alive Pragma: no-cache

    Spring JIRA | 5 years ago | David Pacheco
    java.lang.IllegalArgumentException: Invalid token character ':' in token "http://www.wapforum.org/xhtml"
  2. 0

    A HTTP request with the following Accept header Accept: application/xhtml+xml; profile="http://www.wapforum.org/xhtml", application/vnd.wap.xhtml+xml to a String Controller, causes the following exception to be thrown: {code:java} SEVERE: Servlet.service() for servlet dispatcher threw exception java.lang.IllegalArgumentException: Invalid token character ':' in token "http://www.wapforum.org/xhtml" at org.springframework.http.MediaType.checkToken(MediaType.java:282) at org.springframework.http.MediaType.checkParameters(MediaType.java:302) at org.springframework.http.MediaType.<init>(MediaType.java:263) at org.springframework.http.MediaType.parseMediaType(MediaType.java:584) at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:286) at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:97) at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:1) at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:973) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:931) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:880) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:429) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717) 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) {code} In brief: This is due to the AbstractHttpMessageConverter write method calling the headers.setContentType() method of the outputMessage parameter with a MediaType with the following value "application/xhtml+xml;profile=http://www.wapforum.org/xhtml". Note the lack of quotes around the profile value part. The program flow is: The MediaType is parsed from the HTTP Accept header with the value application/xhtml+xml;profile="http://www.wapforum.org/xhtml" Note - The inclusion of the quotes means that this value does not trigger the checkToken(String) method of MediaType. In the StringHttpMessageConverter write method, a call is made to set the content type for the outputMessage. This uses the toString() method of MediaType to set the Content-Type header, this results in the value being set to "application/xhtml+xml;profile=http://www.wapforum.org/xhtml". Next the writeInternal method of StringHttpMessageConverter is called, this tries to get the MediaType for the outputMessage by calling outputMessage.getHeaders().getContentType(), which in turn calls MediaType.parseMediaType(value) with the value of "application/xhtml+xml;profile=http://www.wapforum.org/xhtml", due to the missing quotes in the profile parameter value, this will now trigger the checkToken(String) method of MediaType which ultimately results in the IllegalArgumentException being thrown. ----- Example request headers GET /index.html HTTP/1.1 Accept: application/xhtml+xml; profile="http://www.wapforum.org/xhtml", application/vnd.wap.xhtml+xml Accept-Language: en-us Host: app.example.com Connection: Keep-Alive Pragma: no-cache

    Spring JIRA | 5 years ago | David Pacheco
    java.lang.IllegalArgumentException: Invalid token character ':' in token "http://www.wapforum.org/xhtml"

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Invalid token character ':' in token "http://www.wapforum.org/xhtml"

      at org.springframework.http.MediaType.checkToken()
    2. Spring
      AbstractHttpMessageConverter.write
      1. org.springframework.http.MediaType.checkToken(MediaType.java:282)
      2. org.springframework.http.MediaType.checkParameters(MediaType.java:302)
      3. org.springframework.http.MediaType.<init>(MediaType.java:263)
      4. org.springframework.http.MediaType.parseMediaType(MediaType.java:584)
      5. org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:286)
      6. org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:97)
      7. org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:1)
      8. org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:181)
      8 frames
    3. Spring MVC
      FrameworkServlet.doGet
      1. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:973)
      2. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:931)
      3. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:880)
      4. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:429)
      5. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
      6. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
      7. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
      8. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
      9. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
      9 frames
    4. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      1 frame