[ 
https://issues.apache.org/jira/browse/SLING-1336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12842577#action_12842577
 ] 

Vidar S. Ramdal commented on SLING-1336:
----------------------------------------

Thanks for the feedback:

> The IOException constructor on line 151 in JSONResponse has only been 
> introduced in Java 6

Will fix.

>The MediaRangeList seems to duplicate work done in the Engine's 
>RequestUtil.parseAcceptHeader method
     --> We might want to consolidate a number of request header parsing 
methods in some generic RequestUtil class ?

Ah, didn't realize there was such a method. Now, sling.servlets.post does not 
have a dependency to Engine. Do we want to introduce that? Or move RequestUtil 
to API?

> The JSONResponse class duplicates property storage in the JSONObject.
     --> Is there a reason for this ? 

The setProperty and getProperty methods are overridden from HtmlResponse. The 
JSONResponse methods store properties directly on the JSON object, without 
using the hashmap in HtmlResponse. Thus, there shouldn't any duplicate storage 
(but an unused HashMap in HtmlResponse).
This could probably be easily rewritten to use HtlmResponse's hashmap, and 
populating the JSONObject on send().

> Let SlingPostServlet return JSON
> --------------------------------
>
>                 Key: SLING-1336
>                 URL: https://issues.apache.org/jira/browse/SLING-1336
>             Project: Sling
>          Issue Type: New Feature
>          Components: Servlets
>    Affects Versions: Servlets Post 2.0.4
>            Reporter: Vidar S. Ramdal
>            Assignee: Vidar S. Ramdal
>             Fix For: Servlets Post 2.0.6
>
>         Attachments: SLING-1336.patch
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to