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/05 12:58:32 UTC

Resource Accessing in Services: question about how HttpService works

Hello,

When resources are registered via the registerResources of HttpService the
specified name is (IIUC) a path within theresources of the caller, i.e.
what the caller would get invoking getClass().getResource(name). However
the HttpService is a service exposed by another bundle, how can this access
the resources in the caller (or know from which bundle it was invoked from)?

Thanks for helping me understand!

Reto

Re: Resource Accessing in Services: question about how HttpService works

Posted by Rob Walker <ro...@ascert.com>.
The registerResource call isn't primarily intended as a way for 1 bundle 
to expose resources to be accessible to other bundles.

It's purpose is to register an alias as a sort of "mount point" which 
allows resources in the bundle to be accessed by web browsers (i.e. HTTP 
GET calls) using a URL e.g. http://ip:port/<some-root>/<alias>/<resource>

If you want a bundle to access resources in another bundle there are 
other, better ways.

Regards

-- Rob Walker

On 05/12/2012 1:58 PM, Reto Bachmann-Gmür wrote:
> Hello,
>
> When resources are registered via the registerResources of HttpService the
> specified name is (IIUC) a path within theresources of the caller, i.e.
> what the caller would get invoking getClass().getResource(name). However
> the HttpService is a service exposed by another bundle, how can this access
> the resources in the caller (or know from which bundle it was invoked from)?
>
> Thanks for helping me understand!
>
> 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: Resource Accessing in Services: question about how HttpService works

Posted by Reto Bachmann-Gmür <re...@wymiwyg.com>.
On Wed, Dec 5, 2012 at 5:19 PM, Chetan Mehrotra
<ch...@gmail.com>wrote:

> > This bundle never created an HttpContext, it
> > still looks magic to me how the webservers knows what to expose...
>
> The magic lies in HttpService being a service factory [1].


Thanks to you wizards disclosing your tricks :)

Reto

Re: Resource Accessing in Services: question about how HttpService works

Posted by Chetan Mehrotra <ch...@gmail.com>.
> This bundle never created an HttpContext, it
> still looks magic to me how the webservers knows what to expose...

The magic lies in HttpService being a service factory [1]. So whenever
a bundle obtains a reference to HttpService it *knows* which bundle
the reference is being given to. Further it creates a default http
context based on the bundle [2]. So when you register resource it
knows from which bundle the request for that resource needs to be
served.

Chetan Mehrotra
[1] https://github.com/apache/felix/blob/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
[2] https://github.com/apache/felix/blob/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java#L119

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


Re: Resource Accessing in Services: question about how HttpService works

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

In the case of the Felix Http Service implementation, the Http Service is implemented as a ServiceFactory. So each bundle will gets its own Http Service instance which knows about the using bundle. So The default Http Context can access this bundle and read the resources.

Regards
Felix

Am 05.12.2012 um 16:02 schrieb Reto Bachmann-Gmür:

> On Wed, Dec 5, 2012 at 3:27 PM, Felix Meschberger <fm...@adobe.com>wrote:
> 
>> Hi,
>> 
>> Am 05.12.2012 um 12:58 schrieb Reto Bachmann-Gmür:
>> 
>>> Hello,
>>> 
>>> When resources are registered via the registerResources of HttpService
>> the
>>> specified name is (IIUC) a path within theresources of the caller, i.e.
>>> what the caller would get invoking getClass().getResource(name). However
>>> the HttpService is a service exposed by another bundle, how can this
>> access
>>> the resources in the caller (or know from which bundle it was invoked
>> from)?
>> 
>> The Http Service does not access the resources. In stead it derives a
>> resource path from the request URL and the resource registration and calls
>> the getResource method of the HttpContext supplied with the resource
>> registration. Generally the HttpContext is created by the bundle
>> registering the resource and thus has access to its own resources.
>> 
> 
> If I invoke the service on the clerezza shell with:
> 
> zz>import org.osgi.service.http.HttpService
> zz>val s = $[HttpService]
> zz>s.registerResources("/test", "/META-INF", null);
> 
> at http://localhost:8080/test/MANIFEST.MF I get the manifest of the
> Clerezza Shell Service bundle. This bundle never created an HttpContext, it
> still looks magic to me how the webservers knows what to expose...
> 
> Cheers,
> Reto
> 
> 
>> 
>> Regards
>> Felix
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
>> 


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


Re: Resource Accessing in Services: question about how HttpService works

Posted by Reto Bachmann-Gmür <re...@apache.org>.
On Wed, Dec 5, 2012 at 3:27 PM, Felix Meschberger <fm...@adobe.com>wrote:

> Hi,
>
> Am 05.12.2012 um 12:58 schrieb Reto Bachmann-Gmür:
>
> > Hello,
> >
> > When resources are registered via the registerResources of HttpService
> the
> > specified name is (IIUC) a path within theresources of the caller, i.e.
> > what the caller would get invoking getClass().getResource(name). However
> > the HttpService is a service exposed by another bundle, how can this
> access
> > the resources in the caller (or know from which bundle it was invoked
> from)?
>
> The Http Service does not access the resources. In stead it derives a
> resource path from the request URL and the resource registration and calls
> the getResource method of the HttpContext supplied with the resource
> registration. Generally the HttpContext is created by the bundle
> registering the resource and thus has access to its own resources.
>

If I invoke the service on the clerezza shell with:

zz>import org.osgi.service.http.HttpService
zz>val s = $[HttpService]
zz>s.registerResources("/test", "/META-INF", null);

at http://localhost:8080/test/MANIFEST.MF I get the manifest of the
Clerezza Shell Service bundle. This bundle never created an HttpContext, it
still looks magic to me how the webservers knows what to expose...

Cheers,
Reto


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

Re: Resource Accessing in Services: question about how HttpService works

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

Am 05.12.2012 um 12:58 schrieb Reto Bachmann-Gmür:

> Hello,
> 
> When resources are registered via the registerResources of HttpService the
> specified name is (IIUC) a path within theresources of the caller, i.e.
> what the caller would get invoking getClass().getResource(name). However
> the HttpService is a service exposed by another bundle, how can this access
> the resources in the caller (or know from which bundle it was invoked from)?

The Http Service does not access the resources. In stead it derives a resource path from the request URL and the resource registration and calls the getResource method of the HttpContext supplied with the resource registration. Generally the HttpContext is created by the bundle registering the resource and thus has access to its own resources.

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