You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Matthias Wermund <ma...@namics.com> on 2009/08/17 13:22:01 UTC
Dispatching in POST requests like in GET
Hello to everyone,
after just reading for some week it's now time for my first own question.
I want to integrate a legacy application in a website based on Sling (in
Day CQ5).
This legacy application renders itself using Portlets, so it enforces the
use of POST forms if the user submits any data. The application is
embedded using RequestDispatcher.include(req,res).
Now we all know about the magic SlingPostServlet, but in this case I
obviously don't want to use it. In case of a POST, I want just to display
the page as usual and pass the request to the embedded application.
The page is based on components, which are included using
RequestDispatcher.include(req,res). The page and all components inherit
from SlingSafeMethodsServlet. They are not registered using @scr
annotations, but evaluated directly inside the content tree.
To catch the POST before the SlingPostServlet, I can use a subclass of the
page, so the structure would look like this:
/apps/all/pages/mypage.java
/apps/all/pages/POST.java
I tried this already and it works.
But:
As I said above, the page includes components using
RequestDispatcher.include(req,res). These components don't have the
POST.java. Because the SlingHttpServletRequest is still of method POST,
the SlingPostServlet catches these includes and none of them actually
resolve to the component's servlet.
To differ between wanted SlingPostServlet requests and the legacy-POSTs I
use a selector in the legacy-POSTs. But the main problem remains: As soon
as I dispatch the request beyond the page, I will be caught by
SlingPostServlet. It would be ideally to have something like
SlingRequestDispatcher.includeIgnoreMethod(req,res) or so ;-)
Some things I quickly tried but didn't lead to solutions were:
- Extending SlingAllMethodsServlet instead of SlingSafeMethodsServlet in
the page
- Using SlingHttpServletRequestWrapper with overrided getMethod() to
return always GET
How can I solve this? Subclassing all of my components with a POST.java
too is not really an option...
Thanks in advance.
Regards,
Matthias Wermund
Software Engineer
---------------------------------------------------------------------
namics ag - ein Unternehmen der PubliGroupe
Teufenerstrasse 19
CH-9000 St. Gallen
http://www.namics.com
http://blog.namics.com
mailto: matthias.wermund@namics.com
Re: Dispatching in POST requests like in GET
Posted by Alexander Klimetschek <ak...@day.com>.
Hi,
a quick answer:
1) to handle POSTs, you must extend SlingAllMethodsServlet, since POST
is not a safe method ;-)
2) you say you don't want to subclass / write a POST.java for each
component, but they should have a specific behaviour, ie. at least
"override" the default sling post servlet behaviour and do nothing;
well, in this case you have to provide a specific POST handler for
each of your components
3) if they all behave the same way, ie. an empty POST handler that
should only be overridden by certain components, introduce a super
resource type "component", eg. /apps/generic/component and put the
(empty) POST.java in their and set sling:superResourceType on the
components.
Regards,
Alex
On Mon, Aug 17, 2009 at 1:22 PM, Matthias
Wermund<ma...@namics.com> wrote:
> Hello to everyone,
>
> after just reading for some week it's now time for my first own question.
>
> I want to integrate a legacy application in a website based on Sling (in
> Day CQ5).
> This legacy application renders itself using Portlets, so it enforces the
> use of POST forms if the user submits any data. The application is
> embedded using RequestDispatcher.include(req,res).
>
> Now we all know about the magic SlingPostServlet, but in this case I
> obviously don't want to use it. In case of a POST, I want just to display
> the page as usual and pass the request to the embedded application.
> The page is based on components, which are included using
> RequestDispatcher.include(req,res). The page and all components inherit
> from SlingSafeMethodsServlet. They are not registered using @scr
> annotations, but evaluated directly inside the content tree.
>
> To catch the POST before the SlingPostServlet, I can use a subclass of the
> page, so the structure would look like this:
>
> /apps/all/pages/mypage.java
> /apps/all/pages/POST.java
>
> I tried this already and it works.
>
> But:
> As I said above, the page includes components using
> RequestDispatcher.include(req,res). These components don't have the
> POST.java. Because the SlingHttpServletRequest is still of method POST,
> the SlingPostServlet catches these includes and none of them actually
> resolve to the component's servlet.
>
> To differ between wanted SlingPostServlet requests and the legacy-POSTs I
> use a selector in the legacy-POSTs. But the main problem remains: As soon
> as I dispatch the request beyond the page, I will be caught by
> SlingPostServlet. It would be ideally to have something like
> SlingRequestDispatcher.includeIgnoreMethod(req,res) or so ;-)
>
> Some things I quickly tried but didn't lead to solutions were:
> - Extending SlingAllMethodsServlet instead of SlingSafeMethodsServlet in
> the page
> - Using SlingHttpServletRequestWrapper with overrided getMethod() to
> return always GET
>
> How can I solve this? Subclassing all of my components with a POST.java
> too is not really an option...
>
>
> Thanks in advance.
>
> Regards,
>
> Matthias Wermund
> Software Engineer
> ---------------------------------------------------------------------
> namics ag - ein Unternehmen der PubliGroupe
> Teufenerstrasse 19
> CH-9000 St. Gallen
> http://www.namics.com
> http://blog.namics.com
> mailto: matthias.wermund@namics.com
>
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Dispatching in POST requests like in GET
Posted by Matthias Wermund <ma...@namics.com>.
I made a mistake in the example-paths.
The page has resourceType all/pages/mypage, so the paths are like:
/apps/all/pages/mypage/mypage.java
/apps/all/pages/mypage/POST.java
Matthias Wermund
Software Engineer
---------------------------------------------------------------------
namics ag - ein Unternehmen der PubliGroupe
Teufenerstrasse 19
CH-9000 St. Gallen
http://www.namics.com
http://blog.namics.com
mailto: matthias.wermund@namics.com
---------------------------------------------------------------------
From: Matthias Wermund <ma...@namics.com>
To: dev@sling.apache.org
Date: 17.08.2009 13:22
Subject: Dispatching in POST requests like in GET
Hello to everyone,
after just reading for some week it's now time for my first own question.
I want to integrate a legacy application in a website based on Sling (in
Day CQ5).
This legacy application renders itself using Portlets, so it enforces the
use of POST forms if the user submits any data. The application is
embedded using RequestDispatcher.include(req,res).
Now we all know about the magic SlingPostServlet, but in this case I
obviously don't want to use it. In case of a POST, I want just to display
the page as usual and pass the request to the embedded application.
The page is based on components, which are included using
RequestDispatcher.include(req,res). The page and all components inherit
from SlingSafeMethodsServlet. They are not registered using @scr
annotations, but evaluated directly inside the content tree.
To catch the POST before the SlingPostServlet, I can use a subclass of the
page, so the structure would look like this:
/apps/all/pages/mypage.java
/apps/all/pages/POST.java
I tried this already and it works.
But:
As I said above, the page includes components using
RequestDispatcher.include(req,res). These components don't have the
POST.java. Because the SlingHttpServletRequest is still of method POST,
the SlingPostServlet catches these includes and none of them actually
resolve to the component's servlet.
To differ between wanted SlingPostServlet requests and the legacy-POSTs I
use a selector in the legacy-POSTs. But the main problem remains: As soon
as I dispatch the request beyond the page, I will be caught by
SlingPostServlet. It would be ideally to have something like
SlingRequestDispatcher.includeIgnoreMethod(req,res) or so ;-)
Some things I quickly tried but didn't lead to solutions were:
- Extending SlingAllMethodsServlet instead of SlingSafeMethodsServlet in
the page
- Using SlingHttpServletRequestWrapper with overrided getMethod() to
return always GET
How can I solve this? Subclassing all of my components with a POST.java
too is not really an option...
Thanks in advance.
Regards,
Matthias Wermund
Software Engineer
---------------------------------------------------------------------
namics ag - ein Unternehmen der PubliGroupe
Teufenerstrasse 19
CH-9000 St. Gallen
http://www.namics.com
http://blog.namics.com
mailto: matthias.wermund@namics.com
Re: Dispatching in POST requests like in GET
Posted by Felix Meschberger <fm...@gmail.com>.
Hi Matthias,
Matthias Wermund schrieb:
> after just reading for some week it's now time for my first own question.
So, welcome then ;-)
To recapitulate: Your requests are generally POST requests due to the
legacy nature of the application. But once entering the system, the
requests should not be handled by the SlingPostServlet but by the
regular "GET" servlets and scripts used for reguaölr GET requests. Right ?
In this case, my solution would be to have a very simple top-level page
handling servlet. This servlet would do the following in its doPost method:
SlingHttpServletRequest req =
new SlingHttpServletRequestWrapper(originalRequest) {
public String getMethod() {
return "GET";
}
};
RequestDispatcher rd = req.getRequestDispatcher(req.getResource());
rd.forward(req, originalResponse);
This should probably do the trick.
HTH
Regards
Felix
>
> I want to integrate a legacy application in a website based on Sling (in
> Day CQ5).
> This legacy application renders itself using Portlets, so it enforces the
> use of POST forms if the user submits any data. The application is
> embedded using RequestDispatcher.include(req,res).
>
> Now we all know about the magic SlingPostServlet, but in this case I
> obviously don't want to use it. In case of a POST, I want just to display
> the page as usual and pass the request to the embedded application.
> The page is based on components, which are included using
> RequestDispatcher.include(req,res). The page and all components inherit
> from SlingSafeMethodsServlet. They are not registered using @scr
> annotations, but evaluated directly inside the content tree.
>
> To catch the POST before the SlingPostServlet, I can use a subclass of the
> page, so the structure would look like this:
>
> /apps/all/pages/mypage.java
> /apps/all/pages/POST.java
>
> I tried this already and it works.
>
> But:
> As I said above, the page includes components using
> RequestDispatcher.include(req,res). These components don't have the
> POST.java. Because the SlingHttpServletRequest is still of method POST,
> the SlingPostServlet catches these includes and none of them actually
> resolve to the component's servlet.
>
> To differ between wanted SlingPostServlet requests and the legacy-POSTs I
> use a selector in the legacy-POSTs. But the main problem remains: As soon
> as I dispatch the request beyond the page, I will be caught by
> SlingPostServlet. It would be ideally to have something like
> SlingRequestDispatcher.includeIgnoreMethod(req,res) or so ;-)
>
> Some things I quickly tried but didn't lead to solutions were:
> - Extending SlingAllMethodsServlet instead of SlingSafeMethodsServlet in
> the page
> - Using SlingHttpServletRequestWrapper with overrided getMethod() to
> return always GET
>
> How can I solve this? Subclassing all of my components with a POST.java
> too is not really an option...
>
>
> Thanks in advance.
>
> Regards,
>
> Matthias Wermund
> Software Engineer
> ---------------------------------------------------------------------
> namics ag - ein Unternehmen der PubliGroupe
> Teufenerstrasse 19
> CH-9000 St. Gallen
> http://www.namics.com
> http://blog.namics.com
> mailto: matthias.wermund@namics.com
>