You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Michael Marth <mm...@day.com> on 2008/09/18 11:21:35 UTC

Re: SlingPostServlet: How to handle resource paths when creating content (Re: [jira] Commented: (SLING-588) Sling ignores specified node path when creating content)

Hi Felix,

I have a question about that:

URL for the selection of the concrete representation (script). For other
> requests (POST, DELETE, ...) you want to modify the resource (and don't
> care for the representation) and hence _should_ address the resource
> directly without any representational detail such as selectors and
> extensions."
>

I would like to implement two different POST features on one node. As
always, a blog example :) The nodes are blog posts, one feature is posting
reader comments, the second feature is trackbacks (which come along as POST
requests from other blogs).

For the comments I am OK with the default behavior (I do not want to
overwrite POST.esp). For the trackback feature I need to implement a custom
behavior (as specified or rather agreed upon by the different blog systems).
How could I construct a URL that would make it possible to distinguish the
two POSTs if there are no selectors?

Related to this: trackback POSTs are supposed to return an xml document
containing success or error messages. So in my understanding of Sling's
handling of extensions for GET requests the URL for trackback POSTs should
end in .xml. You might say that there is no problem, because Sling ignores
the extension anyway, so it might as well be .xml, but it seems a bit
inconsistent to me. I think a POST to /foo.xml should return xml and a POST
to /foo.html should return html

Cheers
Michael

-- 
Michael Marth | Day JCR Cup 08 | Win a MacBook Pro: http://dev.day.com/

Re: SlingPostServlet: How to handle resource paths when creating content (Re: [jira] Commented: (SLING-588) Sling ignores specified node path when creating content)

Posted by Michael Marth <mm...@day.com>.
Hi Felix, Lars,

thanks for the help. I will give it a try.

Yet, I still wonder why we chose to ignore selectors and extensions on
POSTs. It appears inconsistent to me that we have these mechanisms that work
beautifully for GET requests, but on POSTs they don't.
Actually, before looking into the docu and asking here I spent quite some
time just trying to POST to a script with a selector because I naturally
assumed that this would work.
Maybe there is a good reason why POSTs with selectors are a bad idea, but
otherwise I suggest to re-consider them.
WDYT?

Michael



You can help yourself with a servlet which you write for your blog post
> resource type handling POST requests.
>
> In addition your servlet would implement the OptingServlet interface,
> which has the accepts(SlingHttpServletRequest) method. In this method
> you check whether the POST request is a Trackback request or not. If the
> request is a simple update POST, just return false and your servlet will
> be ignored.
>
> If the POST request is a Trackback request, return true and your servlet
> will be called to handle the POST request and the default
> SlingPostServlet will not be called.






-- 
Michael Marth | Day JCR Cup 08 | Win a MacBook Pro: http://dev.day.com/

Re: SlingPostServlet: How to handle resource paths when creating content (Re: [jira] Commented: (SLING-588) Sling ignores specified node path when creating content)

Posted by Felix Meschberger <fm...@gmail.com>.
Hi Michael,

Michael Marth schrieb:
> Hi Felix,
> 
> I have a question about that:
> 
> URL for the selection of the concrete representation (script). For other
>> requests (POST, DELETE, ...) you want to modify the resource (and don't
>> care for the representation) and hence _should_ address the resource
>> directly without any representational detail such as selectors and
>> extensions."
>>
> 
> I would like to implement two different POST features on one node. As
> always, a blog example :) The nodes are blog posts, one feature is posting
> reader comments, the second feature is trackbacks (which come along as POST
> requests from other blogs).
> 
> For the comments I am OK with the default behavior (I do not want to
> overwrite POST.esp). For the trackback feature I need to implement a custom
> behavior (as specified or rather agreed upon by the different blog systems).
> How could I construct a URL that would make it possible to distinguish the
> two POSTs if there are no selectors?

You can help yourself with a servlet which you write for your blog post
resource type handling POST requests.

In addition your servlet would implement the OptingServlet interface,
which has the accepts(SlingHttpServletRequest) method. In this method
you check whether the POST request is a Trackback request or not. If the
request is a simple update POST, just return false and your servlet will
be ignored.

If the POST request is a Trackback request, return true and your servlet
will be called to handle the POST request and the default
SlingPostServlet will not be called.

> 
> Related to this: trackback POSTs are supposed to return an xml document
> containing success or error messages. So in my understanding of Sling's
> handling of extensions for GET requests the URL for trackback POSTs should
> end in .xml. You might say that there is no problem, because Sling ignores
> the extension anyway, so it might as well be .xml, but it seems a bit
> inconsistent to me. I think a POST to /foo.xml should return xml and a POST
> to /foo.html should return html

Agreed. There is an issue actually deailing with this problem.

There is of course a subtle point: the SlingPostServlet actually returns
an XHTML response, though marked as text/html (which only half-way, what
you want). Nevertheless it is correct XML.


Hope this helps.

Regards
Felix



Re: SlingPostServlet: How to handle resource paths when creating content (Re: [jira] Commented: (SLING-588) Sling ignores specified node path when creating content)

Posted by Lars Trieloff <lt...@day.com>.
Hi Michael,

I think you should post to /blogentry/comments/ regardless if it is a
trackback or a comment, because the goal is to create a new node below
comments. I fear this means you have to override POST.esp and add a
hidden field requesting HTML output, because Trackback does not
require sending a proper Accept header and there is no easy way to
override the default response type for a specific path that I know of.

regards,

Lars

On Thu, Sep 18, 2008 at 11:21 AM, Michael Marth <mm...@day.com> wrote:
> Hi Felix,
>
> I have a question about that:
>
> URL for the selection of the concrete representation (script). For other
>> requests (POST, DELETE, ...) you want to modify the resource (and don't
>> care for the representation) and hence _should_ address the resource
>> directly without any representational detail such as selectors and
>> extensions."
>>
>
> I would like to implement two different POST features on one node. As
> always, a blog example :) The nodes are blog posts, one feature is posting
> reader comments, the second feature is trackbacks (which come along as POST
> requests from other blogs).
>
> For the comments I am OK with the default behavior (I do not want to
> overwrite POST.esp). For the trackback feature I need to implement a custom
> behavior (as specified or rather agreed upon by the different blog systems).
> How could I construct a URL that would make it possible to distinguish the
> two POSTs if there are no selectors?
>
> Related to this: trackback POSTs are supposed to return an xml document
> containing success or error messages. So in my understanding of Sling's
> handling of extensions for GET requests the URL for trackback POSTs should
> end in .xml. You might say that there is no problem, because Sling ignores
> the extension anyway, so it might as well be .xml, but it seems a bit
> inconsistent to me. I think a POST to /foo.xml should return xml and a POST
> to /foo.html should return html
>
> Cheers
> Michael
>
> --
> Michael Marth | Day JCR Cup 08 | Win a MacBook Pro: http://dev.day.com/
>