You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Dominik Süß <do...@gmail.com> on 2009/07/31 10:49:13 UTC

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Hi Vidar,

did you give the Javaannotations a try (@SlingServlet [1]), we currently
only work with those instead of QDox and if I remember right I've seen a
testcomponent with the selectors which worked. The SlingServlet annotation
can be found in the felix scr annotations.

Best regards,
Dominik

[1] https://issues.apache.org/jira/browse/SLING-902



On Thu, Jul 30, 2009 at 6:09 PM, Vidar Ramdal <vi...@idium.no> wrote:

> What is the intended behavior for a servlet that is registered as follows:
>  * @scr.property name="sling.servlet.extensions" value="html"
>  * @scr.property name="sling.servlet.resourceTypes"
> value="sling/servlet/default"
>  * @scr.property name="sling.servlet.methods" values.0="GET"
> values.1="POST"
>
> It seems that "sling.servlet.extensions" is ignored, so that this
> servlet will respond to any extension, if there is no better match.
> From the docs [1] and [2] it is a little unclear what is supposed to
> happen, so it might not be a bug, but it still seems strange.
>
> [1]
> http://cwiki.apache.org/confluence/display/SLING/URL+to+Script+Resolution
> [2] http://sling.apache.org/site/servlet-resolution.html
>
>
> --
> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
> Akersgata 16, N-0158 Oslo, Norway
> +47 21 531941, ext 2070
>

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Carsten Ziegeler <cz...@apache.org>.
Alexander Klimetschek wrote:
> On Mon, Aug 3, 2009 at 5:04 PM, Carsten Ziegeler<cz...@apache.org> wrote:
>> We follow the DS spec and therefore do not read the annotations at
>> runtime. They're read by the SCR plugin during build time (again with
>> QDox)
> 
> I thought one of the main reasons for Java annotations was to support
> classes loaded from the repository. But this use case is still not
> supported, IIUC?
> 
Hmm, I don't know of this use case :) The reason for annotations was
...well..to use annotations in the source code and have IDE support.

Loading services from the repository can be done of course (though I
would not suggest to do it), but that would definitly leave the OSGi DS
spec and be a proprietary stuff.

Carsten
-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Aug 3, 2009 at 5:04 PM, Carsten Ziegeler<cz...@apache.org> wrote:
> We follow the DS spec and therefore do not read the annotations at
> runtime. They're read by the SCR plugin during build time (again with
> QDox)

I thought one of the main reasons for Java annotations was to support
classes loaded from the repository. But this use case is still not
supported, IIUC?

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Carsten Ziegeler <cz...@apache.org>.
Alexander Klimetschek wrote:
> On Fri, Jul 31, 2009 at 11:06 AM, Vidar Ramdal<vi...@idium.no> wrote:
>> No, I used only the old-fashioned Javadoc method, but should that make
>> a difference?
> 
> You are right, it should not make a difference, but the bug could only
> be in the QDox based way. With QDox, the properties are read from the
> java sources at build time and are put into the
> OSGI-INF/serviceComponents.xml file inside the bundle, which will be
> picked up by SCR when it is installed. With Java annotations the
> interpretation of the SCR annotation is done whenever the class is
> loaded (IIUC), so it's slightly different (and allows for any loaded
> class to be a service, eg. also ones where the source is in the JCR).
> 
No, this is not the case with the SCR annotations. :)
We follow the DS spec and therefore do not read the annotations at
runtime. They're read by the SCR plugin during build time (again with
QDox) - as both Javadoc tags and annotations provide the same
functionality and use the same code underneath there shouldn't be any
difference. If so, this could be a bug :)

Regards
Carsten
-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Vidar Ramdal <vi...@idium.no>.
>> On Fri, Jul 31, 2009 at 11:06 AM, Vidar Ramdal<vi...@idium.no> wrote:
>>> Also, I see that if I drop the "sling.servlet.extensions" property,
>>> the servlet seems to be registered as expected:
>>> * @scr.property name="sling.servlet.extensions" value="html"
>>> * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

> 2009/7/31 Alexander Klimetschek <ak...@day.com>:
>> I guess you mean if you drop the "sling.servlet.methods" property.

2009/7/31 Vidar Ramdal <vi...@idium.no>:
> Yes, you're right. Sorry :)
>
>> That makes sense, as it then would be registered for GET only and
>> that's the only method for which extensions are currently supported
>> (well, also HEAD afaik).
>
>>> But with "sling.servlet.extensions" set to the array of GET and POST,
>>> the servlet responds to requests without the extension:
>>> * @scr.property name="sling.servlet.extensions" value="html"
>>>  * @scr.property name="sling.servlet.resourceTypes"
>>> value="sling/servlet/default"
>>>  * @scr.property name="sling.servlet.methods" values.0="GET" values.1="POST"
>>>
>>> This seems like a bug to me. I'll file a JIRA for it, if nobody
>>> believes behavior this is intentional.
>>
>> No, extensions should be supported for all methods (because I think
>> that is more intuitive), but currently they are only supported for
>> GET.
>
> Agree.
>
>> What happens if you only set GET on sling.servlet.methods? It might be
>> the case that the extension is completely ignored for all methods if
>> you specify sling.servlet.methods with GET *and* POST. Or did you only
>> see extensions being ignored for POST (which would be as expected)?
>
> Even with only GET, the servlet responds to all extensions.
>
> So now I register the servlet with:
>  * @scr.property name="sling.servlet.extensions" value="html"
>  * @scr.property name="sling.servlet.resourceTypes"
> value="sling/servlet/default"
>  * @scr.property name="sling.servlet.methods" value="GET"
>
> But still, the servlet responds to requests where I believe it
> shouldn't, e.g. GET /node.json.
> When I disable the rogue servlet, /node.json returns the expected JSON
> rendering.
>
> I'll file a JIRA for this for now, and debug it more over the weekend.

https://issues.apache.org/jira/browse/SLING-1069

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Akersgata 16, N-0158 Oslo, Norway
+47 21 531941, ext 2070

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Vidar Ramdal <vi...@idium.no>.
2009/7/31 Alexander Klimetschek <ak...@day.com>:
> On Fri, Jul 31, 2009 at 11:06 AM, Vidar Ramdal<vi...@idium.no> wrote:

>> Also, I see that if I drop the "sling.servlet.extensions" property,
>> the servlet seems to be registered as expected:
>> * @scr.property name="sling.servlet.extensions" value="html"
>> * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"
>
> I guess you mean if you drop the "sling.servlet.methods" property.

Yes, you're right. Sorry :)

> That makes sense, as it then would be registered for GET only and
> that's the only method for which extensions are currently supported
> (well, also HEAD afaik).

>> But with "sling.servlet.extensions" set to the array of GET and POST,
>> the servlet responds to requests without the extension:
>> * @scr.property name="sling.servlet.extensions" value="html"
>>  * @scr.property name="sling.servlet.resourceTypes"
>> value="sling/servlet/default"
>>  * @scr.property name="sling.servlet.methods" values.0="GET" values.1="POST"
>>
>> This seems like a bug to me. I'll file a JIRA for it, if nobody
>> believes behavior this is intentional.
>
> No, extensions should be supported for all methods (because I think
> that is more intuitive), but currently they are only supported for
> GET.

Agree.

> What happens if you only set GET on sling.servlet.methods? It might be
> the case that the extension is completely ignored for all methods if
> you specify sling.servlet.methods with GET *and* POST. Or did you only
> see extensions being ignored for POST (which would be as expected)?

Even with only GET, the servlet responds to all extensions.

So now I register the servlet with:
 * @scr.property name="sling.servlet.extensions" value="html"
 * @scr.property name="sling.servlet.resourceTypes"
value="sling/servlet/default"
 * @scr.property name="sling.servlet.methods" value="GET"

But still, the servlet responds to requests where I believe it
shouldn't, e.g. GET /node.json.
When I disable the rogue servlet, /node.json returns the expected JSON
rendering.

I'll file a JIRA for this for now, and debug it more over the weekend.

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Akersgata 16, N-0158 Oslo, Norway
+47 21 531941, ext 2070

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jul 31, 2009 at 11:06 AM, Vidar Ramdal<vi...@idium.no> wrote:
> No, I used only the old-fashioned Javadoc method, but should that make
> a difference?

You are right, it should not make a difference, but the bug could only
be in the QDox based way. With QDox, the properties are read from the
java sources at build time and are put into the
OSGI-INF/serviceComponents.xml file inside the bundle, which will be
picked up by SCR when it is installed. With Java annotations the
interpretation of the SCR annotation is done whenever the class is
loaded (IIUC), so it's slightly different (and allows for any loaded
class to be a service, eg. also ones where the source is in the JCR).

> Also, I see that if I drop the "sling.servlet.extensions" property,
> the servlet seems to be registered as expected:
> * @scr.property name="sling.servlet.extensions" value="html"
> * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

I guess you mean if you drop the "sling.servlet.methods" property.
That makes sense, as it then would be registered for GET only and
that's the only method for which extensions are currently supported
(well, also HEAD afaik).

> But with "sling.servlet.extensions" set to the array of GET and POST,
> the servlet responds to requests without the extension:
> * @scr.property name="sling.servlet.extensions" value="html"
>  * @scr.property name="sling.servlet.resourceTypes"
> value="sling/servlet/default"
>  * @scr.property name="sling.servlet.methods" values.0="GET" values.1="POST"
>
> This seems like a bug to me. I'll file a JIRA for it, if nobody
> believes behavior this is intentional.

No, extensions should be supported for all methods (because I think
that is more intuitive), but currently they are only supported for
GET.

What happens if you only set GET on sling.servlet.methods? It might be
the case that the extension is completely ignored for all methods if
you specify sling.servlet.methods with GET *and* POST. Or did you only
see extensions being ignored for POST (which would be as expected)?

See SLING-892 [1] for the enhancement request to support extensions
for all methods.

[1] https://issues.apache.org/jira/browse/SLING-892

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Servlet registration: sling.servlet.extensions ignored with default resource type

Posted by Vidar Ramdal <vi...@idium.no>.
> On Thu, Jul 30, 2009 at 6:09 PM, Vidar Ramdal <vi...@idium.no> wrote:
>
>> What is the intended behavior for a servlet that is registered as follows:
>>  * @scr.property name="sling.servlet.extensions" value="html"
>>  * @scr.property name="sling.servlet.resourceTypes"
>> value="sling/servlet/default"
>>  * @scr.property name="sling.servlet.methods" values.0="GET"
>> values.1="POST"
>>
>> It seems that "sling.servlet.extensions" is ignored, so that this
>> servlet will respond to any extension, if there is no better match.
>> From the docs [1] and [2] it is a little unclear what is supposed to
>> happen, so it might not be a bug, but it still seems strange.

2009/7/31 Dominik Süß <do...@gmail.com>:

> did you give the Javaannotations a try (@SlingServlet [1]), we currently
> only work with those instead of QDox and if I remember right I've seen a
> testcomponent with the selectors which worked. The SlingServlet annotation
> can be found in the felix scr annotations.

No, I used only the old-fashioned Javadoc method, but should that make
a difference?

Also, I see that if I drop the "sling.servlet.extensions" property,
the servlet seems to be registered as expected:
* @scr.property name="sling.servlet.extensions" value="html"
* @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

But with "sling.servlet.extensions" set to the array of GET and POST,
the servlet responds to requests without the extension:
* @scr.property name="sling.servlet.extensions" value="html"
 * @scr.property name="sling.servlet.resourceTypes"
value="sling/servlet/default"
 * @scr.property name="sling.servlet.methods" values.0="GET" values.1="POST"

This seems like a bug to me. I'll file a JIRA for it, if nobody
believes behavior this is intentional.

> [1] https://issues.apache.org/jira/browse/SLING-902

>> [1] http://cwiki.apache.org/confluence/display/SLING/URL+to+Script+Resolution
>> [2] http://sling.apache.org/site/servlet-resolution.html

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Akersgata 16, N-0158 Oslo, Norway
+47 21 531941, ext 2070