You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Bernd Winterstein <be...@winterstein-web.de> on 2013/10/29 13:12:54 UTC

Custom Resource Implementation

Hi experts!

I've implemented a custom Resource with resource type "application/xyz".
The Resource is able to adaptTo ValueMap and InputStream.
A ResourceProvider with root  "/demoprovider" delivers an instance with
properties "sling:resourceType":"application/xyz and
"jcr:primaryType":"nt:unstructured".
A request on "/demoprovider/something.html" will create a new instance of
the custom resource and render it via the StreamRendererServlet.

Now I implemented a sling render Servlet for "resourceTypes =
"application/xyz". But the request is always delegated to the
DefaultGetServlet.
What am I missing? Is there some example code? Do I need a custom
ResourceResolver?

Regards

Bernd

Re: Custom Resource Implementation

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Oct 29, 2013 at 2:46 PM, Bernd Winterstein
<be...@winterstein-web.de> wrote:
> After recreating the sling.home directory it works now. Thanks a lot :-)

Ah, good to hear - you probably had some old stuff in there.
-Bertrand

Re: Custom Resource Implementation

Posted by Bernd Winterstein <be...@winterstein-web.de>.
After recreating the sling.home directory it works now. Thanks a lot :-)


2013/10/29 Bertrand Delacretaz <bd...@apache.org>

> On Tue, Oct 29, 2013 at 1:50 PM, Bernd Winterstein
> <be...@winterstein-web.de> wrote:
> > ...I can try to map the servlet to the /demoprovider path. Maybe it
> helps....
>
> That won't work for subpaths - I just added an HTML rendering test of
> our example Planet resources, at http://svn.apache.org/r1536699
>
> You might want to compare with what you're doing, and/or run that test
> in your environment to verify it (the test-services bundle requires
> the org.apache.sling.junit.core bundle).
>
> -Bertrand
>

Re: Custom Resource Implementation

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Oct 29, 2013 at 1:50 PM, Bernd Winterstein
<be...@winterstein-web.de> wrote:
> ...I can try to map the servlet to the /demoprovider path. Maybe it helps....

That won't work for subpaths - I just added an HTML rendering test of
our example Planet resources, at http://svn.apache.org/r1536699

You might want to compare with what you're doing, and/or run that test
in your environment to verify it (the test-services bundle requires
the org.apache.sling.junit.core bundle).

-Bertrand

Re: Custom Resource Implementation

Posted by Bernd Winterstein <be...@winterstein-web.de>.
Doesn't help.


2013/10/29 Bernd Winterstein <be...@winterstein-web.de>

> Yes it does.
> I can try to map the servlet to the /demoprovider path. Maybe it helps.
>
>
> 2013/10/29 Bertrand Delacretaz <bd...@apache.org>
>
>> On Tue, Oct 29, 2013 at 1:12 PM, Bernd Winterstein
>> <be...@winterstein-web.de> wrote:
>> > ...A ResourceProvider with root  "/demoprovider" delivers an instance
>> with
>> > properties "sling:resourceType":"application/xyz and
>> > "jcr:primaryType":"nt:unstructured"....
>>
>> Does your custom Resource's getResourceType() method return
>> application/xyz ?
>>
>> If not, I suspect the property with that name is not taken into
>> account for servlet selection.
>>
>> -Bertrand
>>
>
>

Re: Custom Resource Implementation

Posted by Bernd Winterstein <be...@winterstein-web.de>.
Yes it does.
I can try to map the servlet to the /demoprovider path. Maybe it helps.


2013/10/29 Bertrand Delacretaz <bd...@apache.org>

> On Tue, Oct 29, 2013 at 1:12 PM, Bernd Winterstein
> <be...@winterstein-web.de> wrote:
> > ...A ResourceProvider with root  "/demoprovider" delivers an instance
> with
> > properties "sling:resourceType":"application/xyz and
> > "jcr:primaryType":"nt:unstructured"....
>
> Does your custom Resource's getResourceType() method return
> application/xyz ?
>
> If not, I suspect the property with that name is not taken into
> account for servlet selection.
>
> -Bertrand
>

Re: Custom Resource Implementation

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Oct 29, 2013 at 1:12 PM, Bernd Winterstein
<be...@winterstein-web.de> wrote:
> ...A ResourceProvider with root  "/demoprovider" delivers an instance with
> properties "sling:resourceType":"application/xyz and
> "jcr:primaryType":"nt:unstructured"....

Does your custom Resource's getResourceType() method return application/xyz ?

If not, I suspect the property with that name is not taken into
account for servlet selection.

-Bertrand

Re: Custom Resource Implementation

Posted by Bernd Winterstein <be...@winterstein-web.de>.
      0 (2013-10-29 13:40:58) TIMER_START{Request Processing}
      0 (2013-10-29 13:40:58) COMMENT timer_end format is {<elapsed
msec>,<timer name>} <optional message>
      0 (2013-10-29 13:40:58) LOG Method=GET, PathInfo=/demoprovider/xyz.do
      0 (2013-10-29 13:40:58) TIMER_START{ResourceResolution}
      0 (2013-10-29 13:40:58) TIMER_END{0,ResourceResolution}
URI=/demoprovider/xyz.do resolves to
Resource=DemoResource{path='/demoprovider/xyz.do',
metadata={sling.resolutionPathInfo=,
sling.resolutionPath=/demoprovider/xyz.do},
valueMap=org.apache.sling.api.wrappers.ValueMapDecorator@ec54fd :
{sling:resourceType=application/xyz, title=wurst, demo:property1=wurst,
jcr:createdBy=wurst, jcr:primaryType=nt:unstructured},
resolver=org.apache.sling.jcr.resource.internal.JcrResourceResolver@1bfd78c}
      0 (2013-10-29 13:40:58) LOG Resource Path Info: SlingRequestPathInfo:
path='/demoprovider/xyz.do', selectorString='null', extension='null',
suffix='null'
      0 (2013-10-29 13:40:58) TIMER_START{ServletResolution}
      0 (2013-10-29 13:40:58)
TIMER_START{resolveServlet(DemoResource{path='/demoprovider/xyz.do',
metadata={sling.resolutionPathInfo=,
sling.resolutionPath=/demoprovider/xyz.do},
valueMap=org.apache.sling.api.wrappers.ValueMapDecorator@ec54fd :
{sling:resourceType=application/xyz, title=wurst, demo:property1=wurst,
jcr:createdBy=wurst, jcr:primaryType=nt:unstructured},
resolver=org.apache.sling.jcr.resource.internal.JcrResourceResolver@1bfd78c
})}
      0 (2013-10-29 13:40:58)
TIMER_END{0,resolveServlet(DemoResource{path='/demoprovider/xyz.do',
metadata={sling.resolutionPathInfo=,
sling.resolutionPath=/demoprovider/xyz.do},
valueMap=org.apache.sling.api.wrappers.ValueMapDecorator@ec54fd :
{sling:resourceType=application/xyz, title=wurst, demo:property1=wurst,
jcr:createdBy=wurst, jcr:primaryType=nt:unstructured},
resolver=org.apache.sling.jcr.resource.internal.JcrResourceResolver@1bfd78c})}
Using servlet org.apache.sling.servlets.get.DefaultGetServlet
      0 (2013-10-29 13:40:58) TIMER_END{0,ServletResolution}
URI=/demoprovider/xyz.do handled by
Servlet=org.apache.sling.servlets.get.DefaultGetServlet
      0 (2013-10-29 13:40:58) LOG Applying Requestfilters
      0 (2013-10-29 13:40:58) LOG Calling filter:
org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
      0 (2013-10-29 13:40:58)
TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0}
      1 (2013-10-29 13:40:58) LOG Using
org.apache.sling.servlets.get.impl.helpers.StreamRendererServlet to render
for extension=null
      1 (2013-10-29 13:40:58)
TIMER_END{1,org.apache.sling.servlets.get.DefaultGetServlet#0}
      1 (2013-10-29 13:40:58) TIMER_END{1,Request Processing} Request
Processing



2013/10/29 Bertrand Delacretaz <bd...@apache.org>
>
> Hi Bernd,
>
> On Tue, Oct 29, 2013 at 1:31 PM, Bernd Winterstein
> <be...@winterstein-web.de> wrote:
> ...
> >
{"title":"Demo","sling:resourceType":"application/xyz","jcr:createdBy":"admin","jcr:created":"Tue
> > Oct 29 2013 08:54:58 GMT+0100","jcr:primaryType":"sling:Folder"}
> >
> > When I call it via the registered extension e.g. /content/xyz.do  I can
> > verify that my servlet is called...
>
> Ok, so your servlet's setup is correct .
>
> > ...But via /demoprovider/xyz.do it is always rendered via the
> > DefaultGetServlet....
>
> What does /system/console/requests say in that case?
>
> -Bertrand

Re: Custom Resource Implementation

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Bernd,

On Tue, Oct 29, 2013 at 1:31 PM, Bernd Winterstein
<be...@winterstein-web.de> wrote:
...
> {"title":"Demo","sling:resourceType":"application/xyz","jcr:createdBy":"admin","jcr:created":"Tue
> Oct 29 2013 08:54:58 GMT+0100","jcr:primaryType":"sling:Folder"}
>
> When I call it via the registered extension e.g. /content/xyz.do  I can
> verify that my servlet is called...

Ok, so your servlet's setup is correct .

> ...But via /demoprovider/xyz.do it is always rendered via the
> DefaultGetServlet....

What does /system/console/requests say in that case?

-Bertrand

Re: Custom Resource Implementation

Posted by Bernd Winterstein <be...@winterstein-web.de>.
Hi Bertrand
Thanks for your answer

I created the following node:

{"title":"Demo","sling:resourceType":"application/xyz","jcr:createdBy":"admin","jcr:created":"Tue
Oct 29 2013 08:54:58 GMT+0100","jcr:primaryType":"sling:Folder"}

When I call it via the registered extension e.g. /content/xyz.do  I can
verify that my servlet is called.

TIMER_START{ServletResolution}
TIMER_START{resolveServlet(JcrNodeResource, type=application/xyz,
superType=null, path=/content/xyz)}
TIMER_END{0,resolveServlet(JcrNodeResource, type=application/xyz,
superType=null, path=/content/xyz)} Using servlet
de.cloudsurfers.slinTIMER_END{0,ServletResolution} URI=/content/xyz.do
handled by Servlet=de.cloudsurfers.sling.renderer.DemoRenderer

But via /demoprovider/xyz.do it is always rendered via the
DefaultGetServlet.



2013/10/29 Bertrand Delacretaz <bd...@apache.org>
>
> Hi,
>
> On Tue, Oct 29, 2013 at 1:12 PM, Bernd Winterstein
> <be...@winterstein-web.de> wrote:
> > ...A ResourceProvider with root  "/demoprovider" delivers an instance
with
> > properties "sling:resourceType":"application/xyz and
> > "jcr:primaryType":"nt:unstructured"...
>
> > ...Now I implemented a sling render Servlet for "resourceTypes =
> > "application/xyz". But the request is always delegated to the
> > DefaultGetServlet....
>
> Did you try creating a JCR node with that resource type, to verify
> that your servlet is called?
>
> I suspect it's not, because apart from that your setup looks correct.
>
> You might want also to check /system/console/requests to see exactly
> what's happening.
>
> We have a simple example ResourceProvider at [1], you might want to
> try with that one and see what's different.
>
> -Bertrand
>
> [1]
https://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/resourceprovider/

Re: Custom Resource Implementation

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Oct 29, 2013 at 1:12 PM, Bernd Winterstein
<be...@winterstein-web.de> wrote:
> ...A ResourceProvider with root  "/demoprovider" delivers an instance with
> properties "sling:resourceType":"application/xyz and
> "jcr:primaryType":"nt:unstructured"...

> ...Now I implemented a sling render Servlet for "resourceTypes =
> "application/xyz". But the request is always delegated to the
> DefaultGetServlet....

Did you try creating a JCR node with that resource type, to verify
that your servlet is called?

I suspect it's not, because apart from that your setup looks correct.

You might want also to check /system/console/requests to see exactly
what's happening.

We have a simple example ResourceProvider at [1], you might want to
try with that one and see what's different.

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/resourceprovider/