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 2011/02/20 10:13:03 UTC

Resources and Servlets

Hi,

In Sling script can not be directly executed. So JSPs and Servlets,
which are registered in sling are not directly targeted by urls.
For any URL, a 'resource' is identified first, and then a script,
which can be JSP, Servlet, ESP etc.. is executed for that resource.
I understand this  for 'content' resources which are in JCR. I am
slightly confused when no resource exists and sling uses
NonExistingResource.
I will try an example..
1. GET /mycompany/accountsummary.html
2. Sling will try to get resource in JCR repository for
/mycompany/accountsummary
3. Its not available in JCR repository, so it uses NonExistingResource.
4. Sling tries to find a script/servlet for path /mycompany/accountsummary??
   I am little confused at this point.

I am trying to understand how Servlets registered for a specific path,
fit into resource rendering workflow of sling.

Thanks,
Unmesh

Re: Add Configuration to Bundle at Install

Posted by Vidar Ramdal <vi...@idium.no>.
> On Sun, Feb 20, 2011 at 7:20 PM, Shay Thompson <st...@adobe.com> wrote:
>> I have a bundle which after installing requires the user to go to the Configuration tab in the Felix Web Console, click on the Bundle name or the + symbol to open the 'Create new factory configuration' window and then hit Save to create a new configuration for that bundle with the default values.
>>
>> My question is, is there a setting I can put somewhere in the bundle so when it gets installed a default Configuration is created for it automatically?  Some switch or setting in the manifest perhaps?
>>

On Mon, Feb 21, 2011 at 1:43 AM, Justin Edelson
<ju...@justinedelson.com> wrote:
> AFAIK, you have to do this in code. But it isn't a lot of code :)
>
> Take a look at the Activator in the jackrabbit server bundle. Either
> on bundle start or when the ConfigAdmin service becomes available
> (which ever comes first), the verifyConfiguration() method is called.
>
> This method does the following:
> * lists the configurations for the factory PID
> * if there aren't any configurations for the PID, create a default one
> and save it.
>
> You could also use JCRInstall or FileInstall. These will let you
> install a default configuration.

... and that default configuration could be supplied in your bundle.

You might find some useful information on this in this thread:
http://sling.markmail.org/thread/vd2az5cj3sogf7u2#mid:lqogsvyschzzcnwj+state:results

Especially note the meaning of dashes in the config node name, as
explained by Bertrand in this message:
http://markmail.org/message/6lum4u6vnu2doanb

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00
Quando omni flunkus moritatus!

Re: Add Configuration to Bundle at Install

Posted by Justin Edelson <ju...@justinedelson.com>.
AFAIK, you have to do this in code. But it isn't a lot of code :)

Take a look at the Activator in the jackrabbit server bundle. Either
on bundle start or when the ConfigAdmin service becomes available
(which ever comes first), the verifyConfiguration() method is called.

This method does the following:
* lists the configurations for the factory PID
* if there aren't any configurations for the PID, create a default one
and save it.

You could also use JCRInstall or FileInstall. These will let you
install a default configuration. HOWEVER, only writing code will let
you have logic like "only create this configuration if there aren't
any for this PID" (which is the true meaning of a default
configuration)

HTH,
Justin

On Sun, Feb 20, 2011 at 7:20 PM, Shay Thompson <st...@adobe.com> wrote:
>
> First off, forgive me if this should be sent to Felix list.
>
> I have a bundle which after installing requires the user to go to the Configuration tab in the Felix Web Console, click on the Bundle name or the + symbol to open the 'Create new factory configuration' window and then hit Save to create a new configuration for that bundle with the default values.
>
> My question is, is there a setting I can put somewhere in the bundle so when it gets installed a default Configuration is created for it automatically?  Some switch or setting in the manifest perhaps?
>
> Thanks,
> Shay
>
> ______________________________________________________________________________
>
> Shay Thompson - Lead Computer Scientist
> Adobe Systems, Inc. - AES Foundation
>
>
>

Add Configuration to Bundle at Install

Posted by Shay Thompson <st...@adobe.com>.
First off, forgive me if this should be sent to Felix list.

I have a bundle which after installing requires the user to go to the Configuration tab in the Felix Web Console, click on the Bundle name or the + symbol to open the 'Create new factory configuration' window and then hit Save to create a new configuration for that bundle with the default values.

My question is, is there a setting I can put somewhere in the bundle so when it gets installed a default Configuration is created for it automatically?  Some switch or setting in the manifest perhaps?

Thanks,
Shay

______________________________________________________________________________

Shay Thompson - Lead Computer Scientist
Adobe Systems, Inc. - AES Foundation



Re: Resources and Servlets

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Instead of using resourceType (which requires a node to exist set to a
certain resource type), you can trigger the script by urls if you use
@scr.property name="sling.servlet.paths" value="/mycompany/accountsummary"
instead of using the one for sling.servlet.resourceTypes scr properties.

See this post:
http://dev.day.com/content/ddc/blog/2010/03/sling_servlets_intro.html

<http://dev.day.com/content/ddc/blog/2010/03/sling_servlets_intro.html>
Sarwar


On Sun, Feb 20, 2011 at 9:13 AM, Unmesh Joshi <un...@gmail.com> wrote:

> Hi,
>
> In Sling script can not be directly executed. So JSPs and Servlets,
> which are registered in sling are not directly targeted by urls.
> For any URL, a 'resource' is identified first, and then a script,
> which can be JSP, Servlet, ESP etc.. is executed for that resource.
> I understand this  for 'content' resources which are in JCR. I am
> slightly confused when no resource exists and sling uses
> NonExistingResource.
> I will try an example..
> 1. GET /mycompany/accountsummary.html
> 2. Sling will try to get resource in JCR repository for
> /mycompany/accountsummary
> 3. Its not available in JCR repository, so it uses NonExistingResource.
> 4. Sling tries to find a script/servlet for path
> /mycompany/accountsummary??
>   I am little confused at this point.
>
> I am trying to understand how Servlets registered for a specific path,
> fit into resource rendering workflow of sling.
>
> Thanks,
> Unmesh
>

Re: Resources and Servlets

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

Am Sonntag, den 20.02.2011, 19:12 +0000 schrieb Alexander Klimetschek: 
> On 20.02.11 18:38, "Unmesh Joshi" <un...@gmail.com> wrote:
> 
> >> If you mean "sling.servlet.paths" that just models the same behavior as
> >>if
> >> you would place a jsp under that path, e.g.
> >> /apps/myapp/components/foo/foo.servlet (servlet being used as extension
> >> for java servlets). Under the hood, the sling servlet resolution
> >>mechanism
> >> always works based on paths, AFAIK, so this is simply an alternate way
> >>for
> >> servlets than using "sling.servlet.methods",
> >>"sling.servlet.resourceType"
> >> etc.
> >But when we use sling.servlet.paths, even if resource is not
> >available, the servlet gets invoked for the path. How is that? Am I
> >missing anything?
> >
> 
> Ah, yes, that is one special case, for java servlets. Not sure how if it
> depends on the sling.servlet.paths ending with .servlet...

Yes, servlets are special in this respect: A servlet is registered as a
virtual resource in the resource tree. The resource type of this virtual
resource is actually the path at which the servlet is registered. Thus
servlets can be directly addressed ...

We can't do that for scripts because scripts are actually just files
sitting in the repository with a resource type of nt:file. So, if you
address a script you generally get the script source.

Regards
Felix


Re: Resources and Servlets

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 20.02.11 18:38, "Unmesh Joshi" <un...@gmail.com> wrote:

>> If you mean "sling.servlet.paths" that just models the same behavior as
>>if
>> you would place a jsp under that path, e.g.
>> /apps/myapp/components/foo/foo.servlet (servlet being used as extension
>> for java servlets). Under the hood, the sling servlet resolution
>>mechanism
>> always works based on paths, AFAIK, so this is simply an alternate way
>>for
>> servlets than using "sling.servlet.methods",
>>"sling.servlet.resourceType"
>> etc.
>But when we use sling.servlet.paths, even if resource is not
>available, the servlet gets invoked for the path. How is that? Am I
>missing anything?
>

Ah, yes, that is one special case, for java servlets. Not sure how if it
depends on the sling.servlet.paths ending with .servlet...

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: Resources and Servlets

Posted by Unmesh Joshi <un...@gmail.com>.
> If you mean "sling.servlet.paths" that just models the same behavior as if
> you would place a jsp under that path, e.g.
> /apps/myapp/components/foo/foo.servlet (servlet being used as extension
> for java servlets). Under the hood, the sling servlet resolution mechanism
> always works based on paths, AFAIK, so this is simply an alternate way for
> servlets than using "sling.servlet.methods", "sling.servlet.resourceType"
> etc.
But when we use sling.servlet.paths, even if resource is not
available, the servlet gets invoked for the path. How is that? Am I
missing anything?

Re: Resources and Servlets

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 20.02.11 17:54, "Unmesh Joshi" <un...@gmail.com> wrote:

>Two questions..
>1. How servlets registered for a specific path fit into overall resource
>model?

If you mean "sling.servlet.paths" that just models the same behavior as if
you would place a jsp under that path, e.g.
/apps/myapp/components/foo/foo.servlet (servlet being used as extension
for java servlets). Under the hood, the sling servlet resolution mechanism
always works based on paths, AFAIK, so this is simply an alternate way for
servlets than using "sling.servlet.methods", "sling.servlet.resourceType"
etc.

>2. It looks like, in CQ there is a way to just set allowedPaths
>property on template and even if there is no content node, the script
>jsp for component (resource type) gets triggered, for path prefix
>followed by name of the jsp.html. How does this work?
>(I know this might not be correct place to ask CQ questions.)

Not sure what behavior this is. In CQ templates, allowedPaths has nothing
to do with script/servlet resolution. It only is one way to define the
location where this template can be used when you use the create page
dialog. See http://dev.day.com/docs/en/cq/current/developing/templates.html

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: Resources and Servlets

Posted by Unmesh Joshi <un...@gmail.com>.
Two questions..
1. How servlets registered for a specific path fit into overall resource model?
2. It looks like, in CQ there is a way to just set allowedPaths
property on template and even if there is no content node, the script
jsp for component (resource type) gets triggered, for path prefix
followed by name of the jsp.html. How does this work?
(I know this might not be correct place to ask CQ questions.)

Thanks,
Unmesh




On Sun, Feb 20, 2011 at 7:12 PM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 20.02.11 10:13, "Unmesh Joshi" <un...@gmail.com> wrote:
>>1. GET /mycompany/accountsummary.html
>>2. Sling will try to get resource in JCR repository for
>>/mycompany/accountsummary
>>3. Its not available in JCR repository, so it uses NonExistingResource.
>>4. Sling tries to find a script/servlet for path
>>/mycompany/accountsummary??
>
> No, non-existing resources have "sling:nonexisting" as resource type, so
> /(apps|libs)/sling/nonexisting would be the servlet/JSP path for those
> requests.
>
> See also my other mail: http://markmail.org/message/z7po24ac6f6zoxgd
>
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>

Re: Resources and Servlets

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 20.02.11 10:13, "Unmesh Joshi" <un...@gmail.com> wrote:
>1. GET /mycompany/accountsummary.html
>2. Sling will try to get resource in JCR repository for
>/mycompany/accountsummary
>3. Its not available in JCR repository, so it uses NonExistingResource.
>4. Sling tries to find a script/servlet for path
>/mycompany/accountsummary??

No, non-existing resources have "sling:nonexisting" as resource type, so
/(apps|libs)/sling/nonexisting would be the servlet/JSP path for those
requests.

See also my other mail: http://markmail.org/message/z7po24ac6f6zoxgd


Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel