Hi Jan, On Thu, Nov 7, 2013 at 1:39 PM, Jan Algermissen <[email protected]> wrote: > ...I am complteley new to Sling and tasked with creating a ResourceProvider > implementation...
That sounds cool ;-) > > My ResourceProvider needs to contact an upstream HTTP server(s), so it needs > to use an HTTP client, > preferably the Apache HTTP Client... Sounds good, if needed you'll find numerous examples of using that in our test code. To cache the content that you'll download, you could write it to the JCR repository, depending on its lifetime, total size and frequency of modification. Then, decide to serve the content from that cache if fresh enough, or download it if needed. > - Where do I best put the HTTP client instance and where do I configure it?... You install the httpclient OSGi, bundle and if it's not OSGi-aware in terms of config (which IIRC is the case) you can write an OSGi service that supplies you with configured instances, based on OSGi configs. If you need just one httpclient instance you can keep it inside your resource provider bundle. > ...I am looking for the right spot of the Sling runtime here, to wire the > client to.... Not sure what you mean by "wire to". The simplest ResourceProvider example that we have is the planets resource provider used in our tests, you should be able to use it as an example. I'd start with a single bundle that contains the resource provider and HTTP acquisition logic. > > - Or is there maybe a client instance in the Sling runtime that I can just > obtain and use from within my ResourceResolver?... The Sling launchpad contains org.apache.geronimo.bundles.commons-httpclient but that's httpclient 3.x - a similar bundle is available for 4.x IIRC, and then you can just instantiate the client as usual. > > - Do I have to write a Factory for my Resolver?... No, see the planets example, it's very simple. > And how does a Sling application specify it wants to work with resource from > my provider?... IOW, How does the bootstrapping work? > ...- Do I also have to write a ResourceResolver and bootstrap that, too?... No, just the provider. > ...Will instances of my ResourceProvider be used concurrently, or is a new > instance created for every request to sling?... If you set it up like PlanetsResourceProvider only one instance will be created, and one PlanetResource instance for each resource. > > - How do I obtain a reference to my (global) HTTP client inside my > ResourceProvider?... If you need to share it, make it a service. Or just instantiate and configure it in the provider. > Excuse the big bunch of newbie questions... No worries, it's a good opportunity to see how good our docs and examples are! -Bertrand [1] http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/resourceprovider/
