Even the cq5 FormHandlingServlet uses the ServletRequestWrapper with the
getMethod returning GET. Trouble is, the classes it uses are hidden away
from user space. If you want one which is reusable by all your scripts or
classes, you need to create one and export the package in osgi. Only a few
lines and needed once.

I personally don't think the mechanism us hacky because if you think about
it, when you are done with your action or processing, you are supposed to
be done with the POST method. The redirect or forward is GETing another
resource to present to the user. Hence a change of method makes sense to
me. I'll leave the floor to the REST gurus to provide a more thorough
analysis of this.

I dumped some thoughts on cq5 forms and gotchas here:
http://chanchal.wordpress.com/2013/01/25/cq5-and-sling-forms-options-and-gotchas/

You might have discovered the same things already.

Sarwar


On Wednesday, February 27, 2013, Sean Steimer wrote:

> Is there a recommended approach to handle a POST request in sling where the
> eventual html response rendered to the user depends heavily on the original
> context of the request?
>
> I've run across this problem in a few different scenarios, but the general
> flow looks something like this:
> - user is presented with an html form
> - form is submitted via HTTP post, which is handled by a servlet
> - servlet process the data, which involves perhaps complex logic such as
> calling some external service
> - user then should see a thank you page confirming successful submission,
> and the thanks you page needs to also include info about what was submitted
> (ie. order details in an eCommerce scenario)
>
> That last step becomes a problem because of the way post requests are
> handled by the sling post Servlet.  If I simply do
> slingRequest.getRequestDispatcher().forward() the request method remains
> post, and the thank you page doesn't render as expected.  I've gotten
> around this before by using sendRedirect() and setting cookies, or passing
> along url parameters, but when there is a large amount of data involved,
> this becomes less than ideal, plus you are adding an extra server
> round-trip.
>
> I've also thought about using a custom ServletRequestWrapper that overrides
> getMethod() to always return "GET", but that seems Hacky at best.
>
> Are there common approaches/patterns/helper classes to make this work that
> I'm just not aware of?
>
> FWIW, my work in this areas has been with CQ, but my understanding is that
> the limitations I'm running into are based on sling POST servlet handling,
> hence why I'm asking the questions here.
>

Reply via email to