javax.servlet.ServletException: java.lang.IllegalArgumentException: Failure parsing MediaType string: application/xhtml+xml application/pdf

JBoss Issue Tracker | Evgeny Denisov | 6 years ago
  1. 0

    RestEasy throws java.lang.IllegalArgumentException when processing GET request with ACCEPT mediatype string: "application/xhtml+xml application/pdf": javax.servlet.ServletException: java.lang.IllegalArgumentException: Failure parsing MediaType string: application/xhtml+xml application/pdf at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:74) at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:121) at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:560) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:490) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:549) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:438) at org.apache.catalina.core.StandardHostValve.postInvoke(StandardHostValve.java:249) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:649) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579) at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263) at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214) at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106) Caused by: java.lang.IllegalArgumentException: Failure parsing MediaType string: application/xhtml+xml application/pdf at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:42) at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:18) at javax.ws.rs.core.MediaType.valueOf(MediaType.java:226) at org.jboss.resteasy.util.MediaTypeHelper.parseHeader(MediaTypeHelper.java:204) at org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractAccepts(ServletUtil.java:119) at org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractHttpHeaders(ServletUtil.java:82) at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:127) at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53) ... 31 more This error occures regularly when processing requests from some WEB-crawlers. It should be "HTTP Error 400 Bad request" instead.

    JBoss Issue Tracker | 6 years ago | Evgeny Denisov
    javax.servlet.ServletException: java.lang.IllegalArgumentException: Failure parsing MediaType string: application/xhtml+xml application/pdf
  2. 0

    Printing a PDF from JSF

    Oracle Community | 1 decade ago | 843842
    javax.portlet.PortletException
  3. 0

    PDF downloading from server in struts2

    Stack Overflow | 3 years ago | user2594235
    java.lang.IllegalArgumentException: application/pdf is not a supported mime type
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Because MediaType has an special constructor with only one String parameter, the ObjectToObjectConverter thought, that he can convert the String value "application/xml" to an MediaType. So ObjectToObjectConverter will call the constructor and conversion fails, because this constructor only need the primary content type: Exception: {noformat} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:40) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:138) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:201) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:155) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:461) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1363) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1322) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 31 more Caused by: org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:82) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ... 39 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:501) at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:70) ... 40 more Caused by: java.lang.IllegalArgumentException: Invalid token character '/' in token "application/xml" at org.springframework.http.MediaType.checkToken(MediaType.java:286) at org.springframework.http.MediaType.<init>(MediaType.java:257) at org.springframework.http.MediaType.<init>(MediaType.java:207) at org.springframework.http.MediaType.<init>(MediaType.java:196) ... 45 more {noformat} With disabled ConversionService, the value will be converted by MediaTypeEditor, which uses the MediaType.parseMediaType method. I think the behauvior should be the same like mediaTypes-parameter map (ContentNegotiatingViewResolver), where Strings must be used. Example spring config: {code:xml} <bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="defaultContentType" value="application/xml"/> <property name="mediaTypes"> <map> <entry key="xml" value="application/xml" /> <entry key="json" value="application/json" /> </map> </property> </bean> {code}

    Spring JIRA | 6 years ago | Gerrit Brehmer
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException
  6. 0

    Can custom content type contain @ ? Restful call with jersy client

    Stack Overflow | 2 years ago | user3697919
    java.lang.IllegalArgumentException: Error parsing media type 'application/x-xxx-data@1.0'

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Failure parsing MediaType string: application/xhtml+xml application/pdf

      at org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse()
    2. RESTEasy JAX-RS Implementation
      MediaTypeHeaderDelegate.fromString
      1. org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:42)
      2. org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:18)
      2 frames
    3. JavaEE 7
      MediaType.valueOf
      1. javax.ws.rs.core.MediaType.valueOf(MediaType.java:226)
      1 frame
    4. RESTEasy JAX-RS Implementation
      ServletUtil.extractHttpHeaders
      1. org.jboss.resteasy.util.MediaTypeHelper.parseHeader(MediaTypeHelper.java:204)
      2. org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractAccepts(ServletUtil.java:119)
      3. org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractHttpHeaders(ServletUtil.java:82)
      3 frames
    5. org.jboss.seam
      SeamResourceServlet.service
      1. org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:127)
      2. org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
      3. org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:121)
      4. org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
      4 frames
    6. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      1 frame
    7. Glassfish Core
      ContainerBase.invoke
      1. org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
      2. org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
      3. org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723)
      4. org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:560)
      5. org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:490)
      6. org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382)
      7. org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:549)
      8. org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:438)
      9. org.apache.catalina.core.StandardHostValve.postInvoke(StandardHostValve.java:249)
      10. org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:649)
      11. org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
      12. org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
      13. org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
      14. org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
      15. org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
      16. org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
      17. org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
      18. org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
      18 frames
    8. org.apache.coyote
      CoyoteAdapter.service
      1. org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
      1 frame
    9. Glassfish Core
      DefaultReadTask.doTask
      1. com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
      2. com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
      3. com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
      4. com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
      5. com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
      6. com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
      6 frames
    10. Grizzly HTTP
      PortUnificationPipeline$PUTask.doTask
      1. com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
      1 frame
    11. Glassfish Core
      TaskBase.run
      1. com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
      1 frame
    12. Grizzly HTTP
      SSLWorkerThread.run
      1. com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
      1 frame