jersey
  1. jersey
  2. JERSEY-1223

"500 Internal Server Error" for POST request with garbage instead of "Content-Type"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.12, 2.1
    • Fix Version/s: 2.0-m07, 2.2
    • Component/s: containers
    • Labels:
      None

      Description

      When Jersey ServletContainer processes POST request with garbage as value of "Content-Type" header, it responds with "500 Internal Server Error".

      The reason is that WebComponent.filterFormParameters() throws WebApplicationException, which is never caught and unhandled. Thus, the web container under which Jersey application runs, catches it and responses with "500 Internal Server Error"

        Activity

        Hide
        Michal Gajdos added a comment -

        Also present in Jersey2 (tomcat + multipart-webapp example).

        Show
        Michal Gajdos added a comment - Also present in Jersey2 (tomcat + multipart-webapp example).
        Hide
        Michal Gajdos added a comment -

        Fixed in Jersey2.

        Show
        Michal Gajdos added a comment - Fixed in Jersey2.
        Hide
        jannikolai added a comment -

        We upgraded to Jersey 2, because we hoped to get this Problem ( https://java.net/jira/browse/JERSEY-1276 ) fixed in version 2, as this ticket states.
        But unfortunately we are still getting a 500 response:

        org.glassfish.jersey.message.internal.HeaderValueException: Unable to parse "Content-Type" header value: "application/json, app/json"
        	at org.glassfish.jersey.message.internal.InboundMessageContext.exception(InboundMessageContext.java:318)
        	at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:313)
        	at org.glassfish.jersey.message.internal.InboundMessageContext.getMediaType(InboundMessageContext.java:427)
        	at org.glassfish.jersey.servlet.WebComponent.filterFormParameters(WebComponent.java:482)
        	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:303)
        	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
        	at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:525)
        	at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:473)
        	at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:410)
        	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148)
        	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:387)
        	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
        	at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
        	at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        	at org.mortbay.jetty.Server.handle(Server.java:324)
        	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
        	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880)
        	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
        	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
        	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
        	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
        Caused by: javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Error parsing media type 'application/json, app/json'
        	at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:433)
        	at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:427)
        	at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:311)
        	... 24 more
        Caused by: java.lang.IllegalArgumentException: Error parsing media type 'application/json, app/json'
        	at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:89)
        	at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:59)
        	at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
        	at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:431)
        	... 26 more
        Caused by: java.text.ParseException: Expected separator ';' instead of ','
        	at org.glassfish.jersey.message.internal.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:115)
        	at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:249)
        	at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:242)
        	at org.glassfish.jersey.message.internal.MediaTypeProvider.valueOf(MediaTypeProvider.java:107)
        	at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:87)
        	... 29 more
        

        The request we made is the following one:

        curl -X POST http://your-host.com/resource -d '[{}]' -H"Content-Type: application/json, app/json" -v
        
        Show
        jannikolai added a comment - We upgraded to Jersey 2, because we hoped to get this Problem ( https://java.net/jira/browse/JERSEY-1276 ) fixed in version 2, as this ticket states. But unfortunately we are still getting a 500 response: org.glassfish.jersey.message.internal.HeaderValueException: Unable to parse "Content-Type" header value: "application/json, app/json" at org.glassfish.jersey.message.internal.InboundMessageContext.exception(InboundMessageContext.java:318) at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:313) at org.glassfish.jersey.message.internal.InboundMessageContext.getMediaType(InboundMessageContext.java:427) at org.glassfish.jersey.servlet.WebComponent.filterFormParameters(WebComponent.java:482) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:303) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372) at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:525) at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:473) at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:410) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:387) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520) Caused by: javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Error parsing media type 'application/json, app/json' at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:433) at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:427) at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:311) ... 24 more Caused by: java.lang.IllegalArgumentException: Error parsing media type 'application/json, app/json' at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:89) at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:59) at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179) at org.glassfish.jersey.message.internal.InboundMessageContext$5.apply(InboundMessageContext.java:431) ... 26 more Caused by: java.text.ParseException: Expected separator ';' instead of ',' at org.glassfish.jersey.message.internal.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:115) at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:249) at org.glassfish.jersey.message.internal.HttpHeaderReader.readParameters(HttpHeaderReader.java:242) at org.glassfish.jersey.message.internal.MediaTypeProvider.valueOf(MediaTypeProvider.java:107) at org.glassfish.jersey.message.internal.MediaTypeProvider.fromString(MediaTypeProvider.java:87) ... 29 more The request we made is the following one: curl -X POST http: //your-host.com/resource -d '[{}]' -H "Content-Type: application/json, app/json" -v
        Hide
        Michal Gajdos added a comment -

        Reopening - servlet container is not covered. Create an integration test.

        Show
        Michal Gajdos added a comment - Reopening - servlet container is not covered. Create an integration test.
        Hide
        Xorlev added a comment -

        Would be nice to see a fix backported to Jersey 1.x for those unable to upgrade to Jersey 2.

        Show
        Xorlev added a comment - Would be nice to see a fix backported to Jersey 1.x for those unable to upgrade to Jersey 2.

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            Dassburger
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 3 hours, 1 minute
              3h 1m