You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Bertrand Delacretaz <bd...@apache.org> on 2009/08/12 14:29:38 UTC
All servlet registration parameters should be combined with AND, not
OR
Hi,
Do people agree that all servlet registration parameters listed at
http://sling.apache.org/site/servlets.html should be ANDed?
If I register a servlet with
sling.servlet.extensions" value="html"
sling.servlet.resourceTypes" value="sling/servlet/default"
sling.servlet.methods" value="GET"
It seems logical to imply "process only GET requests for the default
resource type, with an html extension".
Running some tests while looking at SLING-1069, this is not the case -
such a servlet will process requests for various combinations of the
registered method, extension and resource type, for example:
HEAD request with an html extension (after disabling the SimpleWebdavServlet)
GET request with a .json or .xyz extension.
This is due to the servlet being registered for these paths:
/apps/sling/servlet/default/html.servlet (should that include GET to
be more precise, or is there some magic regarding GET?)
/apps/sling/servlet/default/GET.servlet (looks wrong)
ANDing the servlet registration parameters would make more sense to me
- that's not backwards compatible though, so some existing apps might
need changes. But I think the current behavior is confusing.
-Bertrand
Re: All servlet registration parameters should be combined with AND,
not OR
Posted by Felix Meschberger <fm...@gmail.com>.
Hi
Yikes !!
Bertrand Delacretaz schrieb:
> Hi,
>
> Do people agree that all servlet registration parameters listed at
> http://sling.apache.org/site/servlets.html should be ANDed?
>
> If I register a servlet with
>
> sling.servlet.extensions" value="html"
> sling.servlet.resourceTypes" value="sling/servlet/default"
> sling.servlet.methods" value="GET"
>
> It seems logical to imply "process only GET requests for the default
> resource type, with an html extension".
>
> Running some tests while looking at SLING-1069, this is not the case -
> such a servlet will process requests for various combinations of the
> registered method, extension and resource type, for example:
>
> HEAD request with an html extension (after disabling the SimpleWebdavServlet)
> GET request with a .json or .xyz extension.
This is a somewhat issue (or feature ?): HEAD requests are treated like
GET requests for the purpose of servlet resolution since HEAD is a GET
without response body.
>
> This is due to the servlet being registered for these paths:
>
> /apps/sling/servlet/default/html.servlet (should that include GET to
> be more precise, or is there some magic regarding GET?)
> /apps/sling/servlet/default/GET.servlet (looks wrong)
>
> ANDing the servlet registration parameters would make more sense to me
> - that's not backwards compatible though, so some existing apps might
> need changes. But I think the current behavior is confusing.
Yes, you are somewhat absolutely right (what a precisely imprecise
sentence ;-) )
The code *is* buggy, but the issue is probably different:
* For GET/HEAD requests, the method name is not required in the name if
there is an extension available for registration (as in the example)
* For non-GET/HEAD requests, the extension is ignored (in fact no
extension registration is really to be done!)
So the correct behaviour would probably be:
(1) extensions=html, methods=GET
-> register .../html.servlet
(the .../GET.servlet registration is overkill)
(2) extensions=html, methods=POST
-> register .../POST.servlet
(the current registration of .../html.servlet would be wrong here)
(3) extensions=html, methods=GET,POST
-> register .../html.servlet (for GET) and .../POST.servlet
Looking at this, I don't think this results in much of a backwards
compatiblity issue.
Regards
Felix
Re: All servlet registration parameters should be combined with AND,
not OR
Posted by Alexander Klimetschek <ak...@day.com>.
On Wed, Aug 12, 2009 at 3:37 PM, Vidar Ramdal<vi...@idium.no> wrote:
> On Wed, Aug 12, 2009 at 2:29 PM, Bertrand
> Delacretaz<bd...@apache.org> wrote:
>
>> Do people agree that all servlet registration parameters listed at
>> http://sling.apache.org/site/servlets.html should be ANDed?
>>
>
> I agree.
>
> I find it hard to believe that anyone intentionally would register a servlet
>> sling.servlet.extensions" value="html"
>> sling.servlet.resourceTypes" value="sling/servlet/default"
>> sling.servlet.methods" value="GET"
>
> ... for the purpose of responding to requests with no extension. Thus,
> I don't think breaking backwards compatibility will affect many
> people.
+1 for AND.
People which (implicitly) rely on OR will be forced to make their
registrations more explicit, and I would say that this is ok and
actually a good thing (tm).
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: All servlet registration parameters should be combined with AND,
not OR
Posted by Vidar Ramdal <vi...@idium.no>.
On Wed, Aug 12, 2009 at 2:29 PM, Bertrand
Delacretaz<bd...@apache.org> wrote:
> Do people agree that all servlet registration parameters listed at
> http://sling.apache.org/site/servlets.html should be ANDed?
>
> If I register a servlet with
>
> sling.servlet.extensions" value="html"
> sling.servlet.resourceTypes" value="sling/servlet/default"
> sling.servlet.methods" value="GET"
>
> It seems logical to imply "process only GET requests for the default
> resource type, with an html extension".
>
> Running some tests while looking at SLING-1069, this is not the case -
> such a servlet will process requests for various combinations of the
> registered method, extension and resource type, for example:
>
> HEAD request with an html extension (after disabling the SimpleWebdavServlet)
> GET request with a .json or .xyz extension.
>
> This is due to the servlet being registered for these paths:
>
> /apps/sling/servlet/default/html.servlet (should that include GET to
> be more precise, or is there some magic regarding GET?)
> /apps/sling/servlet/default/GET.servlet (looks wrong)
>
> ANDing the servlet registration parameters would make more sense to me
> - that's not backwards compatible though, so some existing apps might
> need changes. But I think the current behavior is confusing.
I agree.
I find it hard to believe that anyone intentionally would register a servlet
> sling.servlet.extensions" value="html"
> sling.servlet.resourceTypes" value="sling/servlet/default"
> sling.servlet.methods" value="GET"
... for the purpose of responding to requests with no extension. Thus,
I don't think breaking backwards compatibility will affect many
people.
Alternatively, we could introduce another sling.servlet config
property, call it "sling.servlet.operator" or something, with possible
values "and" and "or". For backwards compatibility, the default would
be "or".
Thus, the sample servlet would be registered in the same way as
before. If you'd want it to only respond to .html requests, you would
add "sling.servlet.operator" = "and".
But I'd rather avoid introducing such a property.
--
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Akersgata 16, N-0158 Oslo, Norway
+47 21 531941, ext 2070
Re: All servlet registration parameters should be combined with AND,
not OR
Posted by Felix Meschberger <fm...@gmail.com>.
Hi
Mike Müller schrieb:
> .... snip ...
>> Good question. Currently the ResourceProvider registration cannot cope
>> well will registrations with duplicate paths and only uses the first
>> registration and further registration is ignored. So the solution is:
>> First come first serve ;-)
>
> Maybe it is possible to log warnings here if more than one servlet is
> registered for the same "path" (no matter if through resourcetypes,
> extensions or the path property). I think otherwise it can be error-prone,
> because in OSGi it can be unclear which bundle is started at which time.
Actually the resoure resolver logs an error message if it encounters a
duplicate ResourceProvider registration.
>
> And maybe there's another feature for the future: In some cases it could
> make sense to overwrite a registration of an already registered servlet.
> For example if an other bundle registers more than one servlet, but only
> one should be replaced programatically (without change the bundle or stop
> it).
Well, the question is: How would we define such a "selective
replacement" ? The actual handling of the registered servlets is
delegated to the ResourceResolver which manages the ResourceProviders,
which is how the servlets are added in to the resource tree.
Regards
Felix
>
> best regards
> mike
RE: All servlet registration parameters should be combined with
AND, not OR
Posted by Mike Müller <mi...@mysign.ch>.
Hi
> >> Do people agree that all servlet registration parameters listed at
> >> http://sling.apache.org/site/servlets.html should be ANDed?
> >>
> >> If I register a servlet with
> >>
> >> sling.servlet.extensions" value="html"
> >> sling.servlet.resourceTypes" value="sling/servlet/default"
> >> sling.servlet.methods" value="GET"
> >>
> >> It seems logical to imply "process only GET requests for
> the default
> >> resource type, with an html extension".
> >>
> >> Running some tests while looking at SLING-1069, this is
> not the case -
> >> such a servlet will process requests for various
> combinations of the
> >> registered method, extension and resource type, for example:
> >>
> >> HEAD request with an html extension (after disabling the
> >> SimpleWebdavServlet)
> >> GET request with a .json or .xyz extension.
> >>
> >> This is due to the servlet being registered for these paths:
> >>
> >> /apps/sling/servlet/default/html.servlet (should that
> include GET to
> >> be more precise, or is there some magic regarding GET?)
> >> /apps/sling/servlet/default/GET.servlet (looks wrong)
> >>
> >> ANDing the servlet registration parameters would make more
> sense to me
> >> - that's not backwards compatible though, so some existing
> apps might
> >> need changes. But I think the current behavior is confusing.
> >
> > +1,
> > and the most precises registered servlet should handle the request.
> > That means the more properties (extenstions, methods, resourcetypes,
> > selectors) matches the request the higher the chance that a servlet
> > is selected to handle the request.
>
> Exactly, that is implemented in the servlet resolver.
>
> > What's about the path property? For example imagine a
> servlet registered
> > with the matching extenstion, the matching resourcetype and
> the matching
> > method. If there's another servlet registered with the matching path
> > I think the servlet with the path should be in charge to handle the
> > request.
>
> You mean servlet 1 is registered as (resourcetypes="xyz",
> extensions="html") under /apps/xyz/html.servlet and a servlet 2 with
> (path="xyz/html") would also be registered as /apps/xyz/html.servlet ?
>
> Good question. Currently the ResourceProvider registration cannot cope
> well will registrations with duplicate paths and only uses the first
> registration and further registration is ignored. So the solution is:
> First come first serve ;-)
Maybe it is possible to log warnings here if more than one servlet is
registered for the same "path" (no matter if through resourcetypes,
extensions or the path property). I think otherwise it can be error-prone,
because in OSGi it can be unclear which bundle is started at which time.
And maybe there's another feature for the future: In some cases it could
make sense to overwrite a registration of an already registered servlet.
For example if an other bundle registers more than one servlet, but only
one should be replaced programatically (without change the bundle or stop
it).
best regards
mike
Re: All servlet registration parameters should be combined with AND,
not OR
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
Mike Müller schrieb:
>> Do people agree that all servlet registration parameters listed at
>> http://sling.apache.org/site/servlets.html should be ANDed?
>>
>> If I register a servlet with
>>
>> sling.servlet.extensions" value="html"
>> sling.servlet.resourceTypes" value="sling/servlet/default"
>> sling.servlet.methods" value="GET"
>>
>> It seems logical to imply "process only GET requests for the default
>> resource type, with an html extension".
>>
>> Running some tests while looking at SLING-1069, this is not the case -
>> such a servlet will process requests for various combinations of the
>> registered method, extension and resource type, for example:
>>
>> HEAD request with an html extension (after disabling the
>> SimpleWebdavServlet)
>> GET request with a .json or .xyz extension.
>>
>> This is due to the servlet being registered for these paths:
>>
>> /apps/sling/servlet/default/html.servlet (should that include GET to
>> be more precise, or is there some magic regarding GET?)
>> /apps/sling/servlet/default/GET.servlet (looks wrong)
>>
>> ANDing the servlet registration parameters would make more sense to me
>> - that's not backwards compatible though, so some existing apps might
>> need changes. But I think the current behavior is confusing.
>
> +1,
> and the most precises registered servlet should handle the request.
> That means the more properties (extenstions, methods, resourcetypes,
> selectors) matches the request the higher the chance that a servlet
> is selected to handle the request.
Exactly, that is implemented in the servlet resolver.
> What's about the path property? For example imagine a servlet registered
> with the matching extenstion, the matching resourcetype and the matching
> method. If there's another servlet registered with the matching path
> I think the servlet with the path should be in charge to handle the
> request.
You mean servlet 1 is registered as (resourcetypes="xyz",
extensions="html") under /apps/xyz/html.servlet and a servlet 2 with
(path="xyz/html") would also be registered as /apps/xyz/html.servlet ?
Good question. Currently the ResourceProvider registration cannot cope
well will registrations with duplicate paths and only uses the first
registration and further registration is ignored. So the solution is:
First come first serve ;-)
Regards
Felix
RE: All servlet registration parameters should be combined with
AND, not OR
Posted by Mike Müller <mi...@mysign.ch>.
> Do people agree that all servlet registration parameters listed at
> http://sling.apache.org/site/servlets.html should be ANDed?
>
> If I register a servlet with
>
> sling.servlet.extensions" value="html"
> sling.servlet.resourceTypes" value="sling/servlet/default"
> sling.servlet.methods" value="GET"
>
> It seems logical to imply "process only GET requests for the default
> resource type, with an html extension".
>
> Running some tests while looking at SLING-1069, this is not the case -
> such a servlet will process requests for various combinations of the
> registered method, extension and resource type, for example:
>
> HEAD request with an html extension (after disabling the
> SimpleWebdavServlet)
> GET request with a .json or .xyz extension.
>
> This is due to the servlet being registered for these paths:
>
> /apps/sling/servlet/default/html.servlet (should that include GET to
> be more precise, or is there some magic regarding GET?)
> /apps/sling/servlet/default/GET.servlet (looks wrong)
>
> ANDing the servlet registration parameters would make more sense to me
> - that's not backwards compatible though, so some existing apps might
> need changes. But I think the current behavior is confusing.
+1,
and the most precises registered servlet should handle the request.
That means the more properties (extenstions, methods, resourcetypes,
selectors) matches the request the higher the chance that a servlet
is selected to handle the request.
What's about the path property? For example imagine a servlet registered
with the matching extenstion, the matching resourcetype and the matching
method. If there's another servlet registered with the matching path
I think the servlet with the path should be in charge to handle the
request.
WDYT?
best regards
mike