Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-1336

Let SlingPostServlet return JSON

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Servlets Post 2.0.4
    • Servlets Post 2.1.0
    • Servlets
    • None

    Description

      From http://markmail.org/thread/ic2752rha4iy2s2c

      In many scenarios it would be nice to get JSON in response to a POST. You could write your own post servlet to do that, but then you will not benefit from the registered SlingPostOperations and SlingPostProcessors that are executed by the default SlingPostServlet.

      In the case of SlingPostOperation, an implementing class is passed a HtmlResponse object when run(). The HtmlResponse object is pretty agnostic to response format though, the only HTML related work is in the send() method. Thus, it should be possible ot replace/extend/abstract HtmlResponse with a more generic response object. The send() functionality is then moved to SlingPostServlet, which determines which format to return based on these criteria (in order):
      1. The Accept HTTP header - if set to "application/json" return JSON, otherwise return HTML
      2. Possibly also an :accept form field, with the same meaning as the HTTP header, in case it is proven that setting the HTTP header does not work in all browsers
      3. The format of the posted data - if JSON is posted (see SLING-1172), return JSON, otherwise return HTML

      Attachments

        1. SLING-1336-2.patch
          39 kB
          Vidar Skauge Ramdal
        2. SLING-1336.patch
          39 kB
          Vidar Skauge Ramdal

        Issue Links

          Activity

            People

              bdelacretaz Bertrand Delacretaz
              vramdal Vidar Skauge Ramdal
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: