You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Thomas Driessen <th...@ds-lab.org> on 2015/05/22 12:50:35 UTC

Servlet whiteboard registration vs. direct registration - Filter not working

Hi again,

I have two Servlets and one Filter.
The first servlet is registrated via whiteboard like this:

@Component(properties={
@Property(name="osgi.http.whiteboard.servlet.name", value="MyServlet"),
@Property(name="osgi.http.whiteboard.servlet.pattern", value="/testone")})
public class MyWhiteboardServlet implements Servlet {
...

The second Servlet is registrated directly via HttpService like this:

@Component
public class MyManualServlet implements Servlet {
 @ServiceDependency
private volatile HttpService httpService;
 @Start
public void start(){
try {
httpService.registerServlet("/testtwo", this, null, null);
} catch (ServletException e) {
e.printStackTrace();
} catch (NamespaceException e) {
e.printStackTrace();
}
}
...

Then I added a Filter also via whiteboard registration like this:

@Component(properties={
@Property(name="osgi.http.whiteboard.filter.name", value="MyFilter"),
@Property(name="osgi.http.whiteboard.filter.pattern", value="/*")})
public class MyFilter implements Filter {
...

Everythings starts up fine, but when it comes to requests, only the
"MyWhiteboardServlet" is filtered correctly. When I try to access the
"MyManualServlet" nothing happens and the Filter is not invoked.

Is this an intended behaviour?

I know I'm mixing up different registration styles, but I assumed, that
internally both are registered the same way?
In my current project I'm forced to support both styles, as some third
party libraries I use, are using the direct registration, while others use
the whiteboard registration.

Any advice on this problem is appreciated :)

Best regards,
Thomas
-- 
M.Sc. Thomas Driessen
Software Methodologies for Distributed Systems
Institute of Computer Science
University of Augsburg
Universitätsstr. 6a
86135 Augsburg, Germany

Tel:    +49 821 598-2486
email: thomas.driessen@informatik.uni-augsburg.de

Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Carsten Ziegeler <cz...@apache.org>.
I've created FELIX-4904 to track this

Carsten

Am 23.05.15 um 12:25 schrieb Carsten Ziegeler:
> Hi Thomas,
> 
> right now, the http service part and the http whiteboard part use
> different servlet contexts. That's why a filter registered through one
> way does not apply to servlets registered the other way.
> The semantics of the context handling between those two solutions is
> slightly different and mixing them in one context creates some problems.
> Afaik, other implementations of the http whiteboard do the same and keep
> things separate. And by separate it means that the default context of
> the http service is not the same context as the default context of the
> http whiteboard service.
> 
> Now, each whiteboard service can specify a "select" property to select
> the contexts it applies to, by default this is the default context of
> the whiteboard service. This is an LDAP filter expression where you can
> specify "select all contexts". We can argue that in this case it should
> also apply to the default context of the http service - right now, it
> doesn't but I guess this would be valuable addition. However, this part
> is not handled by the spec, so you bind yourself to a particular
> implementation atm.
> 
> 
> Carsten
> 
> Am 22.05.15 um 12:50 schrieb Thomas Driessen:
>> Hi again,
>>
>> I have two Servlets and one Filter.
>> The first servlet is registrated via whiteboard like this:
>>
>> @Component(properties={
>> @Property(name="osgi.http.whiteboard.servlet.name", value="MyServlet"),
>> @Property(name="osgi.http.whiteboard.servlet.pattern", value="/testone")})
>> public class MyWhiteboardServlet implements Servlet {
>> ...
>>
>> The second Servlet is registrated directly via HttpService like this:
>>
>> @Component
>> public class MyManualServlet implements Servlet {
>>  @ServiceDependency
>> private volatile HttpService httpService;
>>  @Start
>> public void start(){
>> try {
>> httpService.registerServlet("/testtwo", this, null, null);
>> } catch (ServletException e) {
>> e.printStackTrace();
>> } catch (NamespaceException e) {
>> e.printStackTrace();
>> }
>> }
>> ...
>>
>> Then I added a Filter also via whiteboard registration like this:
>>
>> @Component(properties={
>> @Property(name="osgi.http.whiteboard.filter.name", value="MyFilter"),
>> @Property(name="osgi.http.whiteboard.filter.pattern", value="/*")})
>> public class MyFilter implements Filter {
>> ...
>>
>> Everythings starts up fine, but when it comes to requests, only the
>> "MyWhiteboardServlet" is filtered correctly. When I try to access the
>> "MyManualServlet" nothing happens and the Filter is not invoked.
>>
>> Is this an intended behaviour?
>>
>> I know I'm mixing up different registration styles, but I assumed, that
>> internally both are registered the same way?
>> In my current project I'm forced to support both styles, as some third
>> party libraries I use, are using the direct registration, while others use
>> the whiteboard registration.
>>
>> Any advice on this problem is appreciated :)
>>
>> Best regards,
>> Thomas
>>
> 
> 


-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi Thomas,

right now, the http service part and the http whiteboard part use
different servlet contexts. That's why a filter registered through one
way does not apply to servlets registered the other way.
The semantics of the context handling between those two solutions is
slightly different and mixing them in one context creates some problems.
Afaik, other implementations of the http whiteboard do the same and keep
things separate. And by separate it means that the default context of
the http service is not the same context as the default context of the
http whiteboard service.

Now, each whiteboard service can specify a "select" property to select
the contexts it applies to, by default this is the default context of
the whiteboard service. This is an LDAP filter expression where you can
specify "select all contexts". We can argue that in this case it should
also apply to the default context of the http service - right now, it
doesn't but I guess this would be valuable addition. However, this part
is not handled by the spec, so you bind yourself to a particular
implementation atm.


Carsten

Am 22.05.15 um 12:50 schrieb Thomas Driessen:
> Hi again,
> 
> I have two Servlets and one Filter.
> The first servlet is registrated via whiteboard like this:
> 
> @Component(properties={
> @Property(name="osgi.http.whiteboard.servlet.name", value="MyServlet"),
> @Property(name="osgi.http.whiteboard.servlet.pattern", value="/testone")})
> public class MyWhiteboardServlet implements Servlet {
> ...
> 
> The second Servlet is registrated directly via HttpService like this:
> 
> @Component
> public class MyManualServlet implements Servlet {
>  @ServiceDependency
> private volatile HttpService httpService;
>  @Start
> public void start(){
> try {
> httpService.registerServlet("/testtwo", this, null, null);
> } catch (ServletException e) {
> e.printStackTrace();
> } catch (NamespaceException e) {
> e.printStackTrace();
> }
> }
> ...
> 
> Then I added a Filter also via whiteboard registration like this:
> 
> @Component(properties={
> @Property(name="osgi.http.whiteboard.filter.name", value="MyFilter"),
> @Property(name="osgi.http.whiteboard.filter.pattern", value="/*")})
> public class MyFilter implements Filter {
> ...
> 
> Everythings starts up fine, but when it comes to requests, only the
> "MyWhiteboardServlet" is filtered correctly. When I try to access the
> "MyManualServlet" nothing happens and the Filter is not invoked.
> 
> Is this an intended behaviour?
> 
> I know I'm mixing up different registration styles, but I assumed, that
> internally both are registered the same way?
> In my current project I'm forced to support both styles, as some third
> party libraries I use, are using the direct registration, while others use
> the whiteboard registration.
> 
> Any advice on this problem is appreciated :)
> 
> Best regards,
> Thomas
> 


-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Pierre De Rop <pi...@gmail.com>.
Hello Thomas,

Just a remark, when you define a DM @Component annotation on a class which
implements an interface, then the interface is automatically registered in
the OSGi service registry. So, in the case of your MyManualServlet, since
you are registering it manually from the @Start method, then I think you
should add the "provides={}" attribute in the @Component annotation in
order to indicate that you don't want the annotation to auto-register your
servlet.

Something like this:

@Component(provides={})
public class MyManualServlet implements Servlet {
     @ServiceDependency
     private volatile HttpService httpService;

    @Start
    public void start(){
        try {
           httpService.registerServlet("/testtwo", this, null, null);
        } catch (ServletException e) {
          e.printStackTrace();
        } catch (NamespaceException e) {
          e.printStackTrace();
        }
    }
...

Now, I did not yet played with the latest http servlet from felix-trunk.
So, can you please indicate me the exact list of bundles you are using at
runtime ?  I will then try to do what you are trying to do what you are
trying to do, and will see if I reproduce the problem.

Looking at the previous posts you did, it sounds like you are using the
http api/base/runtime bundles at runtime ?

kind regards;
/Pierre

On Fri, May 22, 2015 at 12:50 PM, Thomas Driessen <
thomas.driessen@ds-lab.org> wrote:

> Hi again,
>
> I have two Servlets and one Filter.
> The first servlet is registrated via whiteboard like this:
>
> @Component(properties={
> @Property(name="osgi.http.whiteboard.servlet.name", value="MyServlet"),
> @Property(name="osgi.http.whiteboard.servlet.pattern", value="/testone")})
> public class MyWhiteboardServlet implements Servlet {
> ...
>
> The second Servlet is registrated directly via HttpService like this:
>
> @Component
> public class MyManualServlet implements Servlet {
>  @ServiceDependency
> private volatile HttpService httpService;
>  @Start
> public void start(){
> try {
> httpService.registerServlet("/testtwo", this, null, null);
> } catch (ServletException e) {
> e.printStackTrace();
> } catch (NamespaceException e) {
> e.printStackTrace();
> }
> }
> ...
>
> Then I added a Filter also via whiteboard registration like this:
>
> @Component(properties={
> @Property(name="osgi.http.whiteboard.filter.name", value="MyFilter"),
> @Property(name="osgi.http.whiteboard.filter.pattern", value="/*")})
> public class MyFilter implements Filter {
> ...
>
> Everythings starts up fine, but when it comes to requests, only the
> "MyWhiteboardServlet" is filtered correctly. When I try to access the
> "MyManualServlet" nothing happens and the Filter is not invoked.
>
> Is this an intended behaviour?
>
> I know I'm mixing up different registration styles, but I assumed, that
> internally both are registered the same way?
> In my current project I'm forced to support both styles, as some third
> party libraries I use, are using the direct registration, while others use
> the whiteboard registration.
>
> Any advice on this problem is appreciated :)
>
> Best regards,
> Thomas
> --
> M.Sc. Thomas Driessen
> Software Methodologies for Distributed Systems
> Institute of Computer Science
> University of Augsburg
> Universitätsstr. 6a
> 86135 Augsburg, Germany
>
> Tel:    +49 821 598-2486
> email: thomas.driessen@informatik.uni-augsburg.de
>

Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Thomas Driessen <th...@ds-lab.org>.
I completly skipped the osgi.http.whiteboard.context.select in your last
mail.

It works!

Thank you so much :)

2015-06-08 16:38 GMT+02:00 Carsten Ziegeler <cz...@apache.org>:

> Hi Thomas,
>
> you need to set the property osgi.http.whiteboard.context.select
> to the value
> "(osgi.http.whiteboard.context.name=org.osgi.service.http)"
> for the whiteboard services. This should attach them to the default
> context of the http service.
>
> (The property osgi.http.whiteboard.context.name is not supported for
> whiteboard services - except when registering a context)
>
> Regards
> Carsten
>
> Am 08.06.15 um 16:21 schrieb Thomas Driessen:
> > Hi Carsten,
> >
> > sry for bothering you again, but I still have the same problem as before.
> >
> > I checked out the recent code from github, compiled everything, used the
> > property osgi.http.whiteboard.context.name=org.osgi.service.http,
> >  but still Filters and Servlets registered via the whiteboard mechanism
> > seem to have another ServletContext than those registered directly via
> > HttpContext or ExtHttpContext.
> > Whiteboard-Filter intercept requests to Whiteboard-Servlets but none
> else.
> > ExtHttpService-Filter intercept requests to all other Servlets but
> > Whiteboard-Servlets.
> > Shouldn't that be changed by using the above mentioned property? I
> thought
> > I have to set the property in order to force Whiteboard-registered
> Filters
> > / Servlets to use the same ServletContext as those registered directly
> over
> > HttpService/ExtHttpService.
> >
> > I've created a sample setup for you on
> > https://github.com/Sandared/filtertestsetup so that you might have a
> look
> > on it.
> > Perhaps I'm missing something.
> >
> > Best regards,
> > Thomas
> >
> > 2015-05-27 15:46 GMT+02:00 Thomas Driessen <th...@ds-lab.org>:
> >
> >> Hi Carsten,
> >>
> >> thanks a lot for that quick fix :) I'll see if it works in my setup
> within
> >> the next days.
> >>
> >> Best regards,
> >> Thomas
> >>
> >>
> >> 2015-05-27 14:53 GMT+02:00 Carsten Ziegeler <cz...@apache.org>:
> >>
> >>> I've committed an untested version to svn. If you register a whiteboard
> >>> service with the select property set to
> >>> "(osgi.http.whiteboard.context.name=org.osgi.service.http)" this
> >>> whiteboard service will be registered in the context of the http
> >>> service, which means a filter will be applied to such servlets.
> >>>
> >>> Carsten
> >>> --
> >>> Carsten Ziegeler
> >>> Adobe Research Switzerland
> >>> cziegeler@apache.org
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> >>> For additional commands, e-mail: users-help@felix.apache.org
> >>>
> >>>
> >>
> >>
> >> --
> >> M.Sc. Thomas Driessen
> >> Software Methodologies for Distributed Systems
> >> Institute of Computer Science
> >> University of Augsburg
> >> Universitätsstr. 6a
> >> 86135 Augsburg, Germany
> >>
> >> Tel:    +49 821 598-2486
> >> email: thomas.driessen@informatik.uni-augsburg.de
> >>
> >
> >
> >
>
>
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
M.Sc. Thomas Driessen
Software Methodologies for Distributed Systems
Institute of Computer Science
University of Augsburg
Universitätsstr. 6a
86135 Augsburg, Germany

Tel:    +49 821 598-2486
email: thomas.driessen@informatik.uni-augsburg.de

Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi Thomas,

you need to set the property osgi.http.whiteboard.context.select
to the value
"(osgi.http.whiteboard.context.name=org.osgi.service.http)"
for the whiteboard services. This should attach them to the default
context of the http service.

(The property osgi.http.whiteboard.context.name is not supported for
whiteboard services - except when registering a context)

Regards
Carsten

Am 08.06.15 um 16:21 schrieb Thomas Driessen:
> Hi Carsten,
> 
> sry for bothering you again, but I still have the same problem as before.
> 
> I checked out the recent code from github, compiled everything, used the
> property osgi.http.whiteboard.context.name=org.osgi.service.http,
>  but still Filters and Servlets registered via the whiteboard mechanism
> seem to have another ServletContext than those registered directly via
> HttpContext or ExtHttpContext.
> Whiteboard-Filter intercept requests to Whiteboard-Servlets but none else.
> ExtHttpService-Filter intercept requests to all other Servlets but
> Whiteboard-Servlets.
> Shouldn't that be changed by using the above mentioned property? I thought
> I have to set the property in order to force Whiteboard-registered Filters
> / Servlets to use the same ServletContext as those registered directly over
> HttpService/ExtHttpService.
> 
> I've created a sample setup for you on
> https://github.com/Sandared/filtertestsetup so that you might have a look
> on it.
> Perhaps I'm missing something.
> 
> Best regards,
> Thomas
> 
> 2015-05-27 15:46 GMT+02:00 Thomas Driessen <th...@ds-lab.org>:
> 
>> Hi Carsten,
>>
>> thanks a lot for that quick fix :) I'll see if it works in my setup within
>> the next days.
>>
>> Best regards,
>> Thomas
>>
>>
>> 2015-05-27 14:53 GMT+02:00 Carsten Ziegeler <cz...@apache.org>:
>>
>>> I've committed an untested version to svn. If you register a whiteboard
>>> service with the select property set to
>>> "(osgi.http.whiteboard.context.name=org.osgi.service.http)" this
>>> whiteboard service will be registered in the context of the http
>>> service, which means a filter will be applied to such servlets.
>>>
>>> Carsten
>>> --
>>> Carsten Ziegeler
>>> Adobe Research Switzerland
>>> cziegeler@apache.org
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>
>>
>> --
>> M.Sc. Thomas Driessen
>> Software Methodologies for Distributed Systems
>> Institute of Computer Science
>> University of Augsburg
>> Universitätsstr. 6a
>> 86135 Augsburg, Germany
>>
>> Tel:    +49 821 598-2486
>> email: thomas.driessen@informatik.uni-augsburg.de
>>
> 
> 
> 


-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Thomas Driessen <th...@ds-lab.org>.
Hi Carsten,

sry for bothering you again, but I still have the same problem as before.

I checked out the recent code from github, compiled everything, used the
property osgi.http.whiteboard.context.name=org.osgi.service.http,
 but still Filters and Servlets registered via the whiteboard mechanism
seem to have another ServletContext than those registered directly via
HttpContext or ExtHttpContext.
Whiteboard-Filter intercept requests to Whiteboard-Servlets but none else.
ExtHttpService-Filter intercept requests to all other Servlets but
Whiteboard-Servlets.
Shouldn't that be changed by using the above mentioned property? I thought
I have to set the property in order to force Whiteboard-registered Filters
/ Servlets to use the same ServletContext as those registered directly over
HttpService/ExtHttpService.

I've created a sample setup for you on
https://github.com/Sandared/filtertestsetup so that you might have a look
on it.
Perhaps I'm missing something.

Best regards,
Thomas

2015-05-27 15:46 GMT+02:00 Thomas Driessen <th...@ds-lab.org>:

> Hi Carsten,
>
> thanks a lot for that quick fix :) I'll see if it works in my setup within
> the next days.
>
> Best regards,
> Thomas
>
>
> 2015-05-27 14:53 GMT+02:00 Carsten Ziegeler <cz...@apache.org>:
>
>> I've committed an untested version to svn. If you register a whiteboard
>> service with the select property set to
>> "(osgi.http.whiteboard.context.name=org.osgi.service.http)" this
>> whiteboard service will be registered in the context of the http
>> service, which means a filter will be applied to such servlets.
>>
>> Carsten
>> --
>> Carsten Ziegeler
>> Adobe Research Switzerland
>> cziegeler@apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
>
> --
> M.Sc. Thomas Driessen
> Software Methodologies for Distributed Systems
> Institute of Computer Science
> University of Augsburg
> Universitätsstr. 6a
> 86135 Augsburg, Germany
>
> Tel:    +49 821 598-2486
> email: thomas.driessen@informatik.uni-augsburg.de
>



-- 
M.Sc. Thomas Driessen
Software Methodologies for Distributed Systems
Institute of Computer Science
University of Augsburg
Universitätsstr. 6a
86135 Augsburg, Germany

Tel:    +49 821 598-2486
email: thomas.driessen@informatik.uni-augsburg.de

Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Thomas Driessen <th...@ds-lab.org>.
Hi Carsten,

thanks a lot for that quick fix :) I'll see if it works in my setup within
the next days.

Best regards,
Thomas


2015-05-27 14:53 GMT+02:00 Carsten Ziegeler <cz...@apache.org>:

> I've committed an untested version to svn. If you register a whiteboard
> service with the select property set to
> "(osgi.http.whiteboard.context.name=org.osgi.service.http)" this
> whiteboard service will be registered in the context of the http
> service, which means a filter will be applied to such servlets.
>
> Carsten
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
M.Sc. Thomas Driessen
Software Methodologies for Distributed Systems
Institute of Computer Science
University of Augsburg
Universitätsstr. 6a
86135 Augsburg, Germany

Tel:    +49 821 598-2486
email: thomas.driessen@informatik.uni-augsburg.de

Re: Servlet whiteboard registration vs. direct registration - Filter not working

Posted by Carsten Ziegeler <cz...@apache.org>.
I've committed an untested version to svn. If you register a whiteboard
service with the select property set to
"(osgi.http.whiteboard.context.name=org.osgi.service.http)" this
whiteboard service will be registered in the context of the http
service, which means a filter will be applied to such servlets.

Carsten
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org