You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Claus Augusti <cl...@formatvorlage.de> on 2011/02/20 08:49:12 UTC
Problem with registering a servlet for initial POST / Override SlingPostServlet
Hi,
I am trying to register a servlet for a specific resource type,
overriding the SlingPostServlet, without any success so far. It works
only for subsequent requests.
I have these SCR annotations:
* @scr.component metatype="no" immediate="true"
* @scr.service interface="javax.servlet.Servlet"
* @scr.property name="sling.servlet.resourceTypes" value="wcmpp/image"
* @scr.property name="sling.servlet.methods" value="POST"
* @scr.property name="sling.servlet.prefix" value="0"
I am using Curl during development like this:
curl -F"sling:resourceType=wcmpp/image" -F"state=1" -F"title=foobar"
$SAURL/test/1
Doing a subsequent post to /test/1 triggers my servlet as expected, not
the SlingPostServlet. The only way I can get it to work at all for the
initial post is register the servlet using an additional:
@scr.property name="sling.servlet.paths"
values.0="sling/servlet/default/POST"
As specified, using an explicit path overrides everything else (and
makes my servlet the default servlet because of the prefix 0) and is not
the desired outcome.
What am I missing?
Any help is greatly appreciated.
Thanks,
Claus
Re: Problem with registering a servlet for initial POST / Override SlingPostServlet
Posted by sam lee <sk...@gmail.com>.
For creation of a resource, I would listen to a path or a selector.
For example,
POST /wcmpp/image
with parameters like: resourcePath=/content/wcmpp/image/foo .. etc
or,
POST /content/wcmpp/image/foo.create.json
with other parameters..
For the first case, you can set sling.servlet.paths property.
For the second case, you can set sling.servlet.selectors property.
On Sun, Feb 20, 2011 at 2:49 AM, Claus Augusti <cl...@formatvorlage.de>wrote:
> Hi,
>
> I am trying to register a servlet for a specific resource type,
> overriding the SlingPostServlet, without any success so far. It works
> only for subsequent requests.
>
> I have these SCR annotations:
>
> * @scr.component metatype="no" immediate="true"
> * @scr.service interface="javax.servlet.Servlet"
> * @scr.property name="sling.servlet.resourceTypes" value="wcmpp/image"
> * @scr.property name="sling.servlet.methods" value="POST"
> * @scr.property name="sling.servlet.prefix" value="0"
>
> I am using Curl during development like this:
>
> curl -F"sling:resourceType=wcmpp/image" -F"state=1" -F"title=foobar"
> $SAURL/test/1
>
> Doing a subsequent post to /test/1 triggers my servlet as expected, not
> the SlingPostServlet. The only way I can get it to work at all for the
> initial post is register the servlet using an additional:
>
> @scr.property name="sling.servlet.paths"
> values.0="sling/servlet/default/POST"
>
> As specified, using an explicit path overrides everything else (and
> makes my servlet the default servlet because of the prefix 0) and is not
> the desired outcome.
>
> What am I missing?
>
> Any help is greatly appreciated.
>
> Thanks,
>
> Claus
>
Re: Problem with registering a servlet for initial POST / Override SlingPostServlet
Posted by Justin Edelson <ju...@justinedelson.com>.
On Sun, Feb 20, 2011 at 8:39 AM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 20.02.11 08:49, "Claus Augusti" <cl...@formatvorlage.de> wrote:
>>curl -F"sling:resourceType=wcmpp/image" -F"state=1" -F"title=foobar"
>>$SAURL/test/1
>
> The sling:resourceType to resolve the resource type will only be taken
> from the existing resources (in the repository). Specifying
> "sling:resourceType" as a request parameter in this case will simply be
> used like any other property for the sling post servlet, when creating
> this node.
>
>>Doing a subsequent post to /test/1 triggers my servlet as expected, not
>>the SlingPostServlet.
>
> Because now ..../test/1 with sling:resourceType=wcmpp/image exists in the
> repository, hence the servlet resolution is different now.
>
>> The only way I can get it to work at all for the
>>initial post is register the servlet using an additional:
>>
>>@scr.property name="sling.servlet.paths"
>>values.0="sling/servlet/default/POST"
>>
>>As specified, using an explicit path overrides everything else (and
>>makes my servlet the default servlet because of the prefix 0) and is not
>>the desired outcome.
>
> Yes, this overrides the sling post servlet and you don't want to do that.
>
> The point is that servlet resolution for non-existing resources is a
> special case: normally, you don't want the client to know or specify the
> resource type, incl. non-existing resources. But since no resource exists,
> that could tell the type, handling must be different. The starting point
> is that non-existing resource get a special "sling:nonexisting" resource
> type, which you can handle. To separate them, you can act on selectors or
> extensions (see https://issues.apache.org/jira/browse/SLING-864 ) or have
> some custom handling based e.g. on paths.
One other option (although maybe this is what Alex is hinting to in
his last phrase) is to use the path-based resource type provider:
http://svn.apache.org/repos/asf/sling/trunk/samples/path-based-rtp/
Justin
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>
Re: Problem with registering a servlet for initial POST / Override
SlingPostServlet
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 20.02.11 08:49, "Claus Augusti" <cl...@formatvorlage.de> wrote:
>curl -F"sling:resourceType=wcmpp/image" -F"state=1" -F"title=foobar"
>$SAURL/test/1
The sling:resourceType to resolve the resource type will only be taken
from the existing resources (in the repository). Specifying
"sling:resourceType" as a request parameter in this case will simply be
used like any other property for the sling post servlet, when creating
this node.
>Doing a subsequent post to /test/1 triggers my servlet as expected, not
>the SlingPostServlet.
Because now ..../test/1 with sling:resourceType=wcmpp/image exists in the
repository, hence the servlet resolution is different now.
> The only way I can get it to work at all for the
>initial post is register the servlet using an additional:
>
>@scr.property name="sling.servlet.paths"
>values.0="sling/servlet/default/POST"
>
>As specified, using an explicit path overrides everything else (and
>makes my servlet the default servlet because of the prefix 0) and is not
>the desired outcome.
Yes, this overrides the sling post servlet and you don't want to do that.
The point is that servlet resolution for non-existing resources is a
special case: normally, you don't want the client to know or specify the
resource type, incl. non-existing resources. But since no resource exists,
that could tell the type, handling must be different. The starting point
is that non-existing resource get a special "sling:nonexisting" resource
type, which you can handle. To separate them, you can act on selectors or
extensions (see https://issues.apache.org/jira/browse/SLING-864 ) or have
some custom handling based e.g. on paths.
Regards,
Alex
--
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel