Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9655

HttpHeaders.getAccept() does not return all accept headers for Iplanet WebServer 7

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.0.7
    • Fix Version/s: 3.1.3, 3.2 RC1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      The HttpHeaders.getAccept() method is supposed to return a list of "accept" header MediaTypes that were on the servlet request. I noticed that only the first accept header was being returned when invoking this method. I debugged the code and found that getAccept() method invokes the getFirst() method and then splits the comma delimited string to get the list of MediaTypes. This works fine on tomcat because tomcat returns the request accept headers as a single comma separated string. However Oracle Iplanet Webserver returns each request accept header as a separate header entry so it will only ever return the first accept header.

      I ran into this problem when I was invoking a controller that returned a json object. If I invoked the controller directly from the browser url I would get the string representation of the json object when running in a tomcat server. However when I ran the same code in a Iplanet WebServer I would get "org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation". I started digging into the code and that is where I found that the AnnotationMethodHandlerAdapter.writeWithMessageConverters() method is calling the inputMessage.getHeaders().getAccept() method which when run inside a tomcat server would return 4 accept headers, one of which was "/". When ran in Iplanet WebServer it only ever returned "text/html". This would cause the error since the MappingJacksonHttpMessageConverter only accepts "application/json".

      Basically the HttpHeaders.getAccept() method needs to take into account that not all servlet containers return all the header values as a single comma separated string. You should be able to just check the length of the returned list of strings when getting the accept headers and if the length is 1 then parse it. It if has more than one entry then just concatenate the string list together as a comma separated string.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rstoya05-aop Rossen Stoyanchev
                Reporter:
                martyjones Marty Jones
                Last updater:
                Juergen Hoeller
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  6 years, 1 week, 2 days ago