You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Unmesh Joshi <un...@gmail.com> on 2011/03/05 14:17:51 UTC

Chanding HTTP verb from POST to GET while handling request

Hi,

As I have discussed in earlier threads, our current project is
migration from Spring-MVC based application backed by Teamsite to Day
CQ. Its planned to migrated thin slices of the application from
Spring-MVC to CQ/Sling.
One of the proposed approaches is to migrate just the View JSPs in CQ.
This means migrate just the JSPs and create CQ components (which will
be based on same JSPs).
No changes will be done in existing Spring controllers. CQ will be
used just for rendering pages. An interceptor is written which
forwards request to CQ/Sling instead of JSPs.

So the flow looks as following.

Existing spring MVC

HTTP POST ----> Spring MVC Controller ---> Request forward (Using
request dispatcher forward) ---> JSP page.

With CQ co existing with Spring MVC

HTTP POST ---> Spring MVC Controller ---> Spring Interceptor --->
Request forward (Using ServletContext.dispatcher.forward) --->
CQ/Sling Page URL

The problem with the interceptor is that while it can forward requests
to CQ/Sling (Just as you forward request to other web app in same
container), the HTTP request still remains as POST. CQ/Sling (because
its based on Restful model) have very different meaning for POST and
GET.

So, an proof of concept was done, where before forwarding a request to
CQ, its wrapped in custom RequestWrapper which overrides getMethod
method and returns 'GET'.
e.g.
CustomerRequestWrapper extends HttpServletRequestWrapper {

   public String getMethod() {
         return "GET";
  }

}

This seems to be working.

But I want to know if this kind of verb changing in the same request
can run into any issues?

Thanks,
Unmesh

Re: [day-communique] Re: Chanding HTTP verb from POST to GET while handling request

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 07.03.11 08:08, "Unmesh Joshi" <un...@gmail.com> wrote:
>I was looking at code of
>com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.
>It is actually changing http verb from POST to GET by wrapping http
>request. Is this an exception or is this an idiom followed in CQ/Sling
>development?

Depends on the use case. In case of the forms handling servlet, it does a
lot of internal includes on the form action JSPs, which should not be
POSTs but simply run the desired "<selector>.jsp" (e.g. init.jsp,
forward.jsp, servervalidation.jsp), but still keep the request with all
the parameters available.

>I see POST-REDIRECT-GET as a cleaner and Restful way of handling such
>kind of situation.

HTTP-level redirect is no option in the above case, where multiple
includes are done per request, and these should directly address
fixed-named JSPs.

>Changing HTTP verb does not seem very Restful.

REST is about the general architecture and the (general constraints for
the) protocol between client and server. It does not mandate any
implementation. As long as the REST/HTTP semantics are kept up, it is
irrelevant in which JSP or method the logic is implemented. Sling's
script/servlet resolution is just there to make it easy for most cases,
but sometimes it is necessary to tweak it.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: Chanding HTTP verb from POST to GET while handling request

Posted by Unmesh Joshi <un...@gmail.com>.
Hi,

I was looking at code of
com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.
It is actually changing http verb from POST to GET by wrapping http
request. Is this an exception or is this an idiom followed in CQ/Sling
development?

I see POST-REDIRECT-GET as a cleaner and Restful way of handling such
kind of situation.

Changing HTTP verb does not seem very Restful.

Thanks,
Unmesh


On Sat, Mar 5, 2011 at 9:29 PM, Justin Edelson <ju...@gmail.com> wrote:
> Why not just register your scripts to handle POST requests?
>
> On 3/5/11 8:17 AM, Unmesh Joshi wrote:
>> Hi,
>>
>> As I have discussed in earlier threads, our current project is
>> migration from Spring-MVC based application backed by Teamsite to Day
>> CQ. Its planned to migrated thin slices of the application from
>> Spring-MVC to CQ/Sling.
>> One of the proposed approaches is to migrate just the View JSPs in CQ.
>> This means migrate just the JSPs and create CQ components (which will
>> be based on same JSPs).
>> No changes will be done in existing Spring controllers. CQ will be
>> used just for rendering pages. An interceptor is written which
>> forwards request to CQ/Sling instead of JSPs.
>>
>> So the flow looks as following.
>>
>> Existing spring MVC
>>
>> HTTP POST ----> Spring MVC Controller ---> Request forward (Using
>> request dispatcher forward) ---> JSP page.
>>
>> With CQ co existing with Spring MVC
>>
>> HTTP POST ---> Spring MVC Controller ---> Spring Interceptor --->
>> Request forward (Using ServletContext.dispatcher.forward) --->
>> CQ/Sling Page URL
>>
>> The problem with the interceptor is that while it can forward requests
>> to CQ/Sling (Just as you forward request to other web app in same
>> container), the HTTP request still remains as POST. CQ/Sling (because
>> its based on Restful model) have very different meaning for POST and
>> GET.
>>
>> So, an proof of concept was done, where before forwarding a request to
>> CQ, its wrapped in custom RequestWrapper which overrides getMethod
>> method and returns 'GET'.
>> e.g.
>> CustomerRequestWrapper extends HttpServletRequestWrapper {
>>
>>    public String getMethod() {
>>          return "GET";
>>   }
>>
>> }
>>
>> This seems to be working.
>>
>> But I want to know if this kind of verb changing in the same request
>> can run into any issues?
>>
>> Thanks,
>> Unmesh
>
>

Re: Chanding HTTP verb from POST to GET while handling request

Posted by Justin Edelson <ju...@gmail.com>.
Why not just register your scripts to handle POST requests?

On 3/5/11 8:17 AM, Unmesh Joshi wrote:
> Hi,
> 
> As I have discussed in earlier threads, our current project is
> migration from Spring-MVC based application backed by Teamsite to Day
> CQ. Its planned to migrated thin slices of the application from
> Spring-MVC to CQ/Sling.
> One of the proposed approaches is to migrate just the View JSPs in CQ.
> This means migrate just the JSPs and create CQ components (which will
> be based on same JSPs).
> No changes will be done in existing Spring controllers. CQ will be
> used just for rendering pages. An interceptor is written which
> forwards request to CQ/Sling instead of JSPs.
> 
> So the flow looks as following.
> 
> Existing spring MVC
> 
> HTTP POST ----> Spring MVC Controller ---> Request forward (Using
> request dispatcher forward) ---> JSP page.
> 
> With CQ co existing with Spring MVC
> 
> HTTP POST ---> Spring MVC Controller ---> Spring Interceptor --->
> Request forward (Using ServletContext.dispatcher.forward) --->
> CQ/Sling Page URL
> 
> The problem with the interceptor is that while it can forward requests
> to CQ/Sling (Just as you forward request to other web app in same
> container), the HTTP request still remains as POST. CQ/Sling (because
> its based on Restful model) have very different meaning for POST and
> GET.
> 
> So, an proof of concept was done, where before forwarding a request to
> CQ, its wrapped in custom RequestWrapper which overrides getMethod
> method and returns 'GET'.
> e.g.
> CustomerRequestWrapper extends HttpServletRequestWrapper {
> 
>    public String getMethod() {
>          return "GET";
>   }
> 
> }
> 
> This seems to be working.
> 
> But I want to know if this kind of verb changing in the same request
> can run into any issues?
> 
> Thanks,
> Unmesh