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 2010/12/07 08:14:09 UTC
Simple web application in Apache sling
Hi,
I tried following example by writing custom resource resolvers and
servlets. Can someone on the list please verify if this fits 'good
programming practices' for sling?
Use Case: User Account Summary
1. User makes a GET request to /account-entry
a) I have a resource resolver that resolves /account-entry to a
resource (An empty resource at this point)
b) Resource resolver has resource type as /apps/myapp/account-entry.jsp
c) account-entry.jsp is presented to the user
2. User enters account number and submits the form. This makes a POST
request to /account-verify
a) I have a Servlet resource registered for path /account-verify
for handling POST.
b) Servlet makes a backend web service call to verify the account
c) If account is valid, it redirects (by calling
httpResponse.sendRedirect()) to /account-summary
3. A GET request is made to /account-summary
a) I have a resource resolver which resolves /account-summary to resource
b) This resource resolver makes a back end web service call to get
account details
c) This resource resolver has resource type as
/apps/myapp/account-summary.jsp
d) account-summary.jsp is presented to the user.
Following above pattern of Resource resolvers - Servlets, I should be
able to write any web application that is not dealing with data from
JCR repository.
Thanks,
Unmesh
Re: Simple web application in Apache sling
Posted by Unmesh Joshi <un...@gmail.com>.
>>> You can specify a redirect URL in your POST, by using a :redirect field.
Yeah. But I want to conditionally redirect to different urls. So have
to redirect programatically. I think servlets is the only option then.
Re: Simple web application in Apache sling
Posted by Vidar Ramdal <vi...@idium.no>.
On Sun, Dec 12, 2010 at 10:09 AM, Unmesh Joshi <un...@gmail.com> wrote:
> Hi Vidar,
>> A more REST-like approach would be to post to /account-entry/*. You
>> would then use a SlingPostOperation or SlingPostProcessor to do the
>> validation and/or persisting.
>
> If I post to /account-entry/*. It still find the resource resolver I
> have which has resource type as "myapp/account-entry.jsp.".
> Plus, In PostProcessor or PostOperation, I do not get handle to
> HttpServletResponse so I can not redirect to Url I want.
> So it ends up showing up same JSP again.
>
> I think using servlet for handling POST request gave a lot more
> control. (But doesnt fit well in the REST style)
>
> Am I missing anything here.?
You can specify a redirect URL in your POST, by using a :redirect field.
--
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 22 00 84 76
Quando omni flunkus moritatus!
Re: Simple web application in Apache sling
Posted by Unmesh Joshi <un...@gmail.com>.
Hi Vidar,
> A more REST-like approach would be to post to /account-entry/*. You
> would then use a SlingPostOperation or SlingPostProcessor to do the
> validation and/or persisting.
If I post to /account-entry/*. It still find the resource resolver I
have which has resource type as "myapp/account-entry.jsp.".
Plus, In PostProcessor or PostOperation, I do not get handle to
HttpServletResponse so I can not redirect to Url I want.
So it ends up showing up same JSP again.
I think using servlet for handling POST request gave a lot more
control. (But doesnt fit well in the REST style)
Am I missing anything here.?
Thanks,
Unmesh
> ... or to /account-entry/some-newly-created-identifier.html, which
> displays the state of the created account.
>
>> 3. A GET request is made to /account-summary
>
> ... account-entry/some-newly-created-identifier
>
>> a) I have a resource resolver which resolves /account-summary to resource
>> b) This resource resolver makes a back end web service call to get
>> account details
>> c) This resource resolver has resource type as
>> /apps/myapp/account-summary.jsp
>> d) account-summary.jsp is presented to the user.
>
> So to wrap it up, instead of mapping your servlets to absolute paths,
> and have the end-user request them, let the end-user request the
> account resource itself.
>
> --
> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
> Sommerrogata 13-15, N-0255 Oslo, Norway
> + 47 22 00 84 00 / +47 22 00 84 76
> Quando omni flunkus moritatus!
>
Re: Simple web application in Apache sling
Posted by Unmesh Joshi <un...@gmail.com>.
Thanks.. I think now that I have basic thing working.. I can make it
more Restful..
On Tue, Dec 7, 2010 at 4:17 PM, Vidar Ramdal (Kolibri)
<ko...@idium.no> wrote:
> Looks basically reasonable, but could be made more REST-compliant::
>
> On Tue, Dec 7, 2010 at 8:14 AM, Unmesh Joshi <un...@gmail.com> wrote:
>> Hi,
>>
>> I tried following example by writing custom resource resolvers and
>> servlets. Can someone on the list please verify if this fits 'good
>> programming practices' for sling?
>>
>> Use Case: User Account Summary
>>
>> 1. User makes a GET request to /account-entry
>> a) I have a resource resolver that resolves /account-entry to a
>> resource (An empty resource at this point)
>> b) Resource resolver has resource type as /apps/myapp/account-entry.jsp
>
> You might want to specify the resource type relatively - just use
> myapp/account-entry. This gives more flexibility when handling
> different request methods or response formats, for example. See
> http://sling.apache.org/site/servlets.html
>
>> c) account-entry.jsp is presented to the user
>>
>> 2. User enters account number and submits the form. This makes a POST
>> request to /account-verify
>> a) I have a Servlet resource registered for path /account-verify
>> for handling POST.
>
> A more REST-like approach would be to post to /account-entry/*. You
> would then use a SlingPostOperation or SlingPostProcessor to do the
> validation and/or persisting.
>
>> b) Servlet makes a backend web service call to verify the account
>> c) If account is valid, it redirects (by calling
>> httpResponse.sendRedirect()) to /account-summary
>
> ... or to /account-entry/some-newly-created-identifier.html, which
> displays the state of the created account.
>
>> 3. A GET request is made to /account-summary
>
> ... account-entry/some-newly-created-identifier
>
>> a) I have a resource resolver which resolves /account-summary to resource
>> b) This resource resolver makes a back end web service call to get
>> account details
>> c) This resource resolver has resource type as
>> /apps/myapp/account-summary.jsp
>> d) account-summary.jsp is presented to the user.
>
> So to wrap it up, instead of mapping your servlets to absolute paths,
> and have the end-user request them, let the end-user request the
> account resource itself.
>
> --
> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
> Sommerrogata 13-15, N-0255 Oslo, Norway
> + 47 22 00 84 00 / +47 22 00 84 76
> Quando omni flunkus moritatus!
>
Re: Simple web application in Apache sling
Posted by "Vidar Ramdal (Kolibri)" <ko...@idium.no>.
Looks basically reasonable, but could be made more REST-compliant::
On Tue, Dec 7, 2010 at 8:14 AM, Unmesh Joshi <un...@gmail.com> wrote:
> Hi,
>
> I tried following example by writing custom resource resolvers and
> servlets. Can someone on the list please verify if this fits 'good
> programming practices' for sling?
>
> Use Case: User Account Summary
>
> 1. User makes a GET request to /account-entry
> a) I have a resource resolver that resolves /account-entry to a
> resource (An empty resource at this point)
> b) Resource resolver has resource type as /apps/myapp/account-entry.jsp
You might want to specify the resource type relatively - just use
myapp/account-entry. This gives more flexibility when handling
different request methods or response formats, for example. See
http://sling.apache.org/site/servlets.html
> c) account-entry.jsp is presented to the user
>
> 2. User enters account number and submits the form. This makes a POST
> request to /account-verify
> a) I have a Servlet resource registered for path /account-verify
> for handling POST.
A more REST-like approach would be to post to /account-entry/*. You
would then use a SlingPostOperation or SlingPostProcessor to do the
validation and/or persisting.
> b) Servlet makes a backend web service call to verify the account
> c) If account is valid, it redirects (by calling
> httpResponse.sendRedirect()) to /account-summary
... or to /account-entry/some-newly-created-identifier.html, which
displays the state of the created account.
> 3. A GET request is made to /account-summary
... account-entry/some-newly-created-identifier
> a) I have a resource resolver which resolves /account-summary to resource
> b) This resource resolver makes a back end web service call to get
> account details
> c) This resource resolver has resource type as
> /apps/myapp/account-summary.jsp
> d) account-summary.jsp is presented to the user.
So to wrap it up, instead of mapping your servlets to absolute paths,
and have the end-user request them, let the end-user request the
account resource itself.
--
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 22 00 84 76
Quando omni flunkus moritatus!