You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Reto Bachmann-Gmür <re...@apache.org> on 2012/12/11 21:19:59 UTC

HttpService: ServletContext not shared across filters

Helo

I'm trying to integrate an application that makes extensive use of
ServletContext for communication between components via attributes.
Unfortunately it seems that different Filters have different
servletContexts so that the attributes set to the context of one filter
cannot be accessed from the context of another filter. I also tries setting
org.apache.felix.http.shared_servlet_context_attributes to "true" but this
didn't make any difference.

Any idea how to have a shared ServletContext?

Cheers,
Reto

Re: HttpService: ServletContext not shared across filters

Posted by Reto Bachmann-Gmür <re...@wymiwyg.com>.
Thanks Rob and Cetan

It seems that sharing a context is a trade-off between security and
functionality. As for sharing properties and services OSGi has better means
than servlet context attributes I should convince the developers no longer
to use this path.

Reto

On Thu, Dec 13, 2012 at 11:08 AM, Rob Walker <ro...@ascert.com> wrote:

> Cheers for helping out here Chetan.
> I was pretty sure the trick needed was to get them to share their
> HttpContext, but I couldn't advise on how that needed to be done with this
> usage of the whiteboard pattern
> - Rob
>
>
> On 13/12/2012 11:47 AM, Chetan Mehrotra wrote:
>
>> Have a look at HttpWhiteboardConstants#**CONTEXT_ID [1]. From that it
>> appears that to share the context you need to
>>
>> 1. Register a HttpContext as a service with service property
>> 'contextId' set to some shared name say foo
>> 2. Register your filter with property contextId to 'foo'
>> 3. Also set property 'context.shared' to true with the filter
>>
>> This seems to allow sharing of the HttpContext and thus the servlet
>> context between various servlets
>>
>> Chetan Mehrotra
>> [1] https://github.com/apache/**felix/blob/trunk/http/**
>> whiteboard/src/main/java/org/**apache/felix/http/whiteboard/**
>> HttpWhiteboardConstants.java#**L51<https://github.com/apache/felix/blob/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java#L51>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>
>>
> --
>
>
> Ascert - Taking systems to the edge
> robw@ascert.com
> +27 21 300 2028 ext 5119
> www.ascert.com
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: HttpService: ServletContext not shared across filters

Posted by Rob Walker <ro...@ascert.com>.
Cheers for helping out here Chetan.
I was pretty sure the trick needed was to get them to share their 
HttpContext, but I couldn't advise on how that needed to be done with 
this usage of the whiteboard pattern
- Rob

On 13/12/2012 11:47 AM, Chetan Mehrotra wrote:
> Have a look at HttpWhiteboardConstants#CONTEXT_ID [1]. From that it
> appears that to share the context you need to
>
> 1. Register a HttpContext as a service with service property
> 'contextId' set to some shared name say foo
> 2. Register your filter with property contextId to 'foo'
> 3. Also set property 'context.shared' to true with the filter
>
> This seems to allow sharing of the HttpContext and thus the servlet
> context between various servlets
>
> Chetan Mehrotra
> [1] https://github.com/apache/felix/blob/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java#L51
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
>

-- 


Ascert - Taking systems to the edge
robw@ascert.com
+27 21 300 2028 ext 5119
www.ascert.com


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


Re: HttpService: ServletContext not shared across filters

Posted by Chetan Mehrotra <ch...@gmail.com>.
Have a look at HttpWhiteboardConstants#CONTEXT_ID [1]. From that it
appears that to share the context you need to

1. Register a HttpContext as a service with service property
'contextId' set to some shared name say foo
2. Register your filter with property contextId to 'foo'
3. Also set property 'context.shared' to true with the filter

This seems to allow sharing of the HttpContext and thus the servlet
context between various servlets

Chetan Mehrotra
[1] https://github.com/apache/felix/blob/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java#L51

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


Re: HttpService: ServletContext not shared across filters

Posted by Rob Walker <ro...@ascert.com>.
Unfortunately I haven't used the HttpService in this manner (or with 
Filters) so I don't think I'll be able to offer much more help.

I know in explicit, hard coded cases, if you create servlets in separate 
bundles even if they are of the same class, and you register them 
without making sure they use the same HttpContext, they won't share any 
ServletContext. I suspect that could be a cause of the problem you are 
seeing - although I don't know how you'd change it with the model you 
are using (which seems to be based form of dependency injection from 
config type approach)

- Rob

On 12/12/2012 3:48 PM, Reto Bachmann-Gmür wrote:
> Both Filter have annotations like this:
>
> @Service(value = javax.servlet.Filter.class)
> @Properties({
>      @Property(name ="pattern", value=".*")
> })
>
> The filters are provided from different bundles. I'm not setting any
> HttpContext explicitely.
>
> Cheers,
> Reto
>
> On Wed, Dec 12, 2012 at 1:09 PM, Rob Walker <ro...@ascert.com> wrote:
>
>> I would definitely double check that both filters use the same HttpContext
>> and aren't having their own default ones created. Can't say for sure it
>> will solve your problem, but I know that not using the same HttpContext
>> across servlets will pretty much guarantee they won't share anything.
>>
>> - Rob
>>
>>
>> On 12/12/2012 1:49 PM, Reto Bachmann-Gmür wrote:
>>
>>> On Dec 12, 2012 6:13 AM, "Rob Walker" <ro...@ascert.com> wrote:
>>>
>>>> One thing you don't mention is your bundle and alias usage structure.
>>>>
>>> Both filters are registered using the whiteboard extension and with the
>>> identical pattern.
>>>
>>> Cheers,
>>> Reto
>>>
>>>   Also, Filters (to my knowledge) weren't ever really a part of the OSGi
>>> HttpService spec - so you should be prepared for some digging and
>>> experimentation!
>>>
>>>> Are you registering the servlets used yourself within your own code (i.e.
>>>>
>>> using the HttpService registerServlet call? If so, then one thing you
>>> could
>>> try is to make sure you create your own HttpContext for the register
>>> servlet call, and use the same instance of that object for every servlet
>>> you register. I'm not 100% sure that will cure your case, but worth a try.
>>>
>>>> Also possible you might need both the above and the
>>>>
>>> shared_servlet_context_**attributes flag set
>>>
>>>> -- Rob
>>>>
>>>>
>>>> On 11/12/2012 10:19 PM, Reto Bachmann-Gmür wrote:
>>>>
>>>>> Helo
>>>>>
>>>>> I'm trying to integrate an application that makes extensive use of
>>>>> ServletContext for communication between components via attributes.
>>>>> Unfortunately it seems that different Filters have different
>>>>> servletContexts so that the attributes set to the context of one filter
>>>>> cannot be accessed from the context of another filter. I also tries
>>>>>
>>>> setting
>>>> org.apache.felix.http.shared_**servlet_context_attributes to "true" but
>>>> this
>>>> didn't make any difference.
>>>>> Any idea how to have a shared ServletContext?
>>>>>
>>>>> Cheers,
>>>>> Reto
>>>>>
>>>>>   --
>>>>
>>>> Ascert - Taking systems to the edge
>>>> robw@ascert.com
>>>> +27 21 300 2028 ext 5119
>>>> www.ascert.com
>>>>
>>>>
>>>> ------------------------------**------------------------------**
>>>> ---------
>>>> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>
>>>>
>> --
>>
>>
>> Ascert - Taking systems to the edge
>> robw@ascert.com
>> +27 21 300 2028 ext 5119
>> www.ascert.com
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>

-- 


Ascert - Taking systems to the edge
robw@ascert.com
+27 21 300 2028 ext 5119
www.ascert.com


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


Re: HttpService: ServletContext not shared across filters

Posted by Reto Bachmann-Gmür <re...@apache.org>.
Both Filter have annotations like this:

@Service(value = javax.servlet.Filter.class)
@Properties({
    @Property(name ="pattern", value=".*")
})

The filters are provided from different bundles. I'm not setting any
HttpContext explicitely.

Cheers,
Reto

On Wed, Dec 12, 2012 at 1:09 PM, Rob Walker <ro...@ascert.com> wrote:

> I would definitely double check that both filters use the same HttpContext
> and aren't having their own default ones created. Can't say for sure it
> will solve your problem, but I know that not using the same HttpContext
> across servlets will pretty much guarantee they won't share anything.
>
> - Rob
>
>
> On 12/12/2012 1:49 PM, Reto Bachmann-Gmür wrote:
>
>> On Dec 12, 2012 6:13 AM, "Rob Walker" <ro...@ascert.com> wrote:
>>
>>> One thing you don't mention is your bundle and alias usage structure.
>>>
>> Both filters are registered using the whiteboard extension and with the
>> identical pattern.
>>
>> Cheers,
>> Reto
>>
>>  Also, Filters (to my knowledge) weren't ever really a part of the OSGi
>>>
>> HttpService spec - so you should be prepared for some digging and
>> experimentation!
>>
>>> Are you registering the servlets used yourself within your own code (i.e.
>>>
>> using the HttpService registerServlet call? If so, then one thing you
>> could
>> try is to make sure you create your own HttpContext for the register
>> servlet call, and use the same instance of that object for every servlet
>> you register. I'm not 100% sure that will cure your case, but worth a try.
>>
>>> Also possible you might need both the above and the
>>>
>> shared_servlet_context_**attributes flag set
>>
>>> -- Rob
>>>
>>>
>>> On 11/12/2012 10:19 PM, Reto Bachmann-Gmür wrote:
>>>
>>>> Helo
>>>>
>>>> I'm trying to integrate an application that makes extensive use of
>>>> ServletContext for communication between components via attributes.
>>>> Unfortunately it seems that different Filters have different
>>>> servletContexts so that the attributes set to the context of one filter
>>>> cannot be accessed from the context of another filter. I also tries
>>>>
>>> setting
>>
>>> org.apache.felix.http.shared_**servlet_context_attributes to "true" but
>>>>
>>> this
>>
>>> didn't make any difference.
>>>>
>>>> Any idea how to have a shared ServletContext?
>>>>
>>>> Cheers,
>>>> Reto
>>>>
>>>>  --
>>>
>>>
>>> Ascert - Taking systems to the edge
>>> robw@ascert.com
>>> +27 21 300 2028 ext 5119
>>> www.ascert.com
>>>
>>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
> --
>
>
> Ascert - Taking systems to the edge
> robw@ascert.com
> +27 21 300 2028 ext 5119
> www.ascert.com
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<us...@felix.apache.org>
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: HttpService: ServletContext not shared across filters

Posted by Rob Walker <ro...@ascert.com>.
I would definitely double check that both filters use the same 
HttpContext and aren't having their own default ones created. Can't say 
for sure it will solve your problem, but I know that not using the same 
HttpContext across servlets will pretty much guarantee they won't share 
anything.

- Rob

On 12/12/2012 1:49 PM, Reto Bachmann-Gmür wrote:
> On Dec 12, 2012 6:13 AM, "Rob Walker" <ro...@ascert.com> wrote:
>> One thing you don't mention is your bundle and alias usage structure.
> Both filters are registered using the whiteboard extension and with the
> identical pattern.
>
> Cheers,
> Reto
>
>> Also, Filters (to my knowledge) weren't ever really a part of the OSGi
> HttpService spec - so you should be prepared for some digging and
> experimentation!
>> Are you registering the servlets used yourself within your own code (i.e.
> using the HttpService registerServlet call? If so, then one thing you could
> try is to make sure you create your own HttpContext for the register
> servlet call, and use the same instance of that object for every servlet
> you register. I'm not 100% sure that will cure your case, but worth a try.
>> Also possible you might need both the above and the
> shared_servlet_context_attributes flag set
>> -- Rob
>>
>>
>> On 11/12/2012 10:19 PM, Reto Bachmann-Gmür wrote:
>>> Helo
>>>
>>> I'm trying to integrate an application that makes extensive use of
>>> ServletContext for communication between components via attributes.
>>> Unfortunately it seems that different Filters have different
>>> servletContexts so that the attributes set to the context of one filter
>>> cannot be accessed from the context of another filter. I also tries
> setting
>>> org.apache.felix.http.shared_servlet_context_attributes to "true" but
> this
>>> didn't make any difference.
>>>
>>> Any idea how to have a shared ServletContext?
>>>
>>> Cheers,
>>> Reto
>>>
>> --
>>
>>
>> Ascert - Taking systems to the edge
>> robw@ascert.com
>> +27 21 300 2028 ext 5119
>> www.ascert.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>

-- 


Ascert - Taking systems to the edge
robw@ascert.com
+27 21 300 2028 ext 5119
www.ascert.com


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


Re: HttpService: ServletContext not shared across filters

Posted by Reto Bachmann-Gmür <re...@apache.org>.
On Dec 12, 2012 6:13 AM, "Rob Walker" <ro...@ascert.com> wrote:
>
> One thing you don't mention is your bundle and alias usage structure.

Both filters are registered using the whiteboard extension and with the
identical pattern.

Cheers,
Reto

> Also, Filters (to my knowledge) weren't ever really a part of the OSGi
HttpService spec - so you should be prepared for some digging and
experimentation!
>
> Are you registering the servlets used yourself within your own code (i.e.
using the HttpService registerServlet call? If so, then one thing you could
try is to make sure you create your own HttpContext for the register
servlet call, and use the same instance of that object for every servlet
you register. I'm not 100% sure that will cure your case, but worth a try.
>
> Also possible you might need both the above and the
shared_servlet_context_attributes flag set
>
> -- Rob
>
>
> On 11/12/2012 10:19 PM, Reto Bachmann-Gmür wrote:
>>
>> Helo
>>
>> I'm trying to integrate an application that makes extensive use of
>> ServletContext for communication between components via attributes.
>> Unfortunately it seems that different Filters have different
>> servletContexts so that the attributes set to the context of one filter
>> cannot be accessed from the context of another filter. I also tries
setting
>> org.apache.felix.http.shared_servlet_context_attributes to "true" but
this
>> didn't make any difference.
>>
>> Any idea how to have a shared ServletContext?
>>
>> Cheers,
>> Reto
>>
>
> --
>
>
> Ascert - Taking systems to the edge
> robw@ascert.com
> +27 21 300 2028 ext 5119
> www.ascert.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

Re: HttpService: ServletContext not shared across filters

Posted by Rob Walker <ro...@ascert.com>.
One thing you don't mention is your bundle and alias usage structure.

Also, Filters (to my knowledge) weren't ever really a part of the OSGi 
HttpService spec - so you should be prepared for some digging and 
experimentation!

Are you registering the servlets used yourself within your own code 
(i.e. using the HttpService registerServlet call? If so, then one thing 
you could try is to make sure you create your own HttpContext for the 
register servlet call, and use the same instance of that object for 
every servlet you register. I'm not 100% sure that will cure your case, 
but worth a try.

Also possible you might need both the above and the 
shared_servlet_context_attributes flag set

-- Rob

On 11/12/2012 10:19 PM, Reto Bachmann-Gmür wrote:
> Helo
>
> I'm trying to integrate an application that makes extensive use of
> ServletContext for communication between components via attributes.
> Unfortunately it seems that different Filters have different
> servletContexts so that the attributes set to the context of one filter
> cannot be accessed from the context of another filter. I also tries setting
> org.apache.felix.http.shared_servlet_context_attributes to "true" but this
> didn't make any difference.
>
> Any idea how to have a shared ServletContext?
>
> Cheers,
> Reto
>

-- 


Ascert - Taking systems to the edge
robw@ascert.com
+27 21 300 2028 ext 5119
www.ascert.com


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