Hi guys,

Many thanks for your suggestions! The resource providers are indeed
very useful for some part of my work. As you already mentioned it's
basically the solution to unify the external data with some existing
node tree structured data.

@Olaf: The idea of NEBA is really nice. Though I'm not using it
directly, I found some of its interesting points that can be applied.

Cheers,
Duy

On Mon, Mar 9, 2015 at 1:06 PM, Olaf <o...@x100.de> wrote:
> Hi Duy,
>
> +1 for using resource providers. It is also the recommended approach for 
> integrating third-party data sources - if you intend to leverage Sling's 
> resource resolution and -rendering for the views. If that is not the case, I 
> would say it does not make much sense to use Sling - after all, you would 
> bypass almost all of its core features and merely use it as a middleware 
> platform.
>
> Another option is to use NEBA (http://neba.io), in which case you can use 
> Spring MVC (http://neba.io/userguide.html#springmvc), which would make the 
> path-based parameter extraction significantly easier. I don't what you 
> external data sources are, but in case it's relational, you could then also 
> use Spring's JDBC templating or ORM abstraction to access that data.
>
> Kind regards,
> Olaf
> -----Original Message-----
> From: Julian Sedding [mailto:jsedd...@gmail.com]
> Sent: Montag, 9. März 2015 12:09
> To: users@sling.apache.org
> Subject: Re: Route mapping for dynamic resources in Sling
>
> Hi Duy
>
> You may want to implement a ResourceProvider. It allows you to hook an 
> arbitrary resource subtree into Sling's resource tree backed by your won 
> logic. For the read-only case that's not even very complicated.
>
> Bertrand created a PlanetResourceProvider example some time ago[0].
> That may be helpful.
>
> Regards
> Julian
>
> [0]
>  
> http://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/resourceprovider/
>
> On Mon, Mar 9, 2015 at 9:42 AM, Duy Nguyen <duy.phngu...@gmail.com> wrote:
>> For some reasons (large data set, continuous changes in the original
>> data, etc.), I'm not motivated to import the whole external data into
>> the node tree structure.
>>
>> You're right that the universal servlet solution seems to be the very
>> last choice, but I couldn't find any other way without importing the
>> data.
>>
>> Any other advices are very welcomed!
>>
>> Thanks,
>> Duy
>>
>> On Sun, Mar 8, 2015 at 1:22 PM,  <jason.bai...@24601.org> wrote:
>>>
>>>
>>>
>>> So in my naïve response to your situation. I don’t see the problem with 
>>> mapping directly to the resource model,  the first thing I would do is to 
>>> import the information into the node tree structure. The exact structure 
>>> isn’t really important as long as it mirrors the intent of the request.
>>>
>>>
>>>
>>>
>>> /content/document1
>>>
>>> /content/document2
>>>
>>> /content/document2/true/version1
>>>
>>> /content/document2/true/version2
>>>
>>>
>>>
>>>
>>> Then for each level where a file should be returned uses a sling 
>>> sling:resourceType that returns the file.
>>>
>>>
>>>
>>>
>>> If you have restrictions, like you know the name of the file but the 
>>> versions of the file are maintained separately and you don't have an 
>>> ability to import.
>>>
>>>
>>>
>>>
>>> You can have a node structure like
>>>
>>>
>>>
>>>
>>> /content/{document}/true
>>>
>>>
>>>
>>>
>>> With the sling:resourceType for the document retrieving the document in 
>>> question and the resourceType for true locating the version that's being 
>>> requested.
>>>
>>>
>>>
>>>
>>> If you don't know the document ahead of time, then you're back to a very 
>>> generic servlet interacting with another system. I would still avoid the 
>>> universal solution and look to implement something very specific for these 
>>> types of requests, based an identifier for the service.
>>>
>>>
>>> -Jason
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> From: Duy Nguyen
>>> Sent: ‎Friday‎, ‎March‎ ‎6‎, ‎2015 ‎12‎:‎14‎ ‎PM
>>> To: users@sling.apache.org
>>>
>>>
>>>
>>>
>>>
>>> Hi,
>>>
>>> Sorry for the formatting error, as there were 3 different urls actually:
>>>
>>> /myhost/{documentName}
>>>
>>> /myhost//{hasRevision}/{revisionID}
>>>
>>> /myhost/-/users/{userName}
>>>
>>> * So in your example, it is like:
>>>
>>> /host/whitepaper
>>>
>>> /host/whitepaper/true/version-1
>>>
>>> /host/-/users/john123
>>>
>>> (I avoid .pdf as it can be misleading to a selector which is not the
>>> idea of my question)
>>>
>>> ---
>>> Duy
>>>
>>>
>>> On Fri, Mar 6, 2015, at 15:15, Jason E Bailey wrote:
>>>
>>> So I can get a clear picture of the request, a typical request would
>>> be for?
>>>
>>> /host/whitepaper.pdf/host/true/version-1/host/-/users/john123
>>>
>>>
>>> --=20
>>> Jason
>>>
>>> On Fri, Mar 6, 2015, at 09:50 AM, Duy Nguyen wrote:
>>>>  Hello,
>>>>=20
>>>> I'm bringing here a use case in Sling and look forward to receiving
>>>>some  opinions from the community.
>>>>=20
>>>> I need to write a server-side app that serves customized RESTful
>>>>APIs for  a  client app (which is stable and the set of APIs is
>>>>fixed). The problem  comes from "ugly" API urls that can hardly be
>>>>mapped into the resource  model of Sling, for example:
>>>>=20
>>>> */myhost/{documentName}/myhost/{**documentName*
>>>> *}/{hasRevision}/{revisionID}/myhost/-/users/{userName}*
>>>>=20
>>>> Especially properties like =E2=80=9CdocumentName",
>>>>=E2=80=9CrevisionID" a=
>>> nd "userName"
>>>> are
>>>> not necessarily stored in jcr resources, but can also be from
>>>> external sources. The flag =E2=80=9ChasRevision=E2=80=9D is either
>>>> true or false v=
>>> alue, to check
>>>> if
>>>> the document has revision to be returned. So there must be some
>>>>middleware  that handles the requests coming to each of those paths
>>>>(to determine if  the needed resource can be retrieved from jcr or
>>>>external sources, and  revision to be taken into account).
>>>>=20
>>>> Thinking in the implementation of some regular web frameworks
>>>>(Django,  Sinatra, etc.), it can be done by route mapping, such as:
>>>> *get("/myhost/:**documentName*
>>>> */:hasRevision?/:revisionID?") function()
>>>> {=E2=80=A6}get("/myhost/-/users/:userName") function() {=E2=80=A6}*
>>>>=20
>>>> Initially I have come up with two solutions in Sling:
>>>>=20
>>>> 1- Write a "global SlingServlet" for "/myhost/", and then the rest
>>>>of the  url are params that will be analyzed in the servlet to handle
>>>>different  request patterns. However I don't think this is a very
>>>>elegant solution,  because this only one servlet is responsible for
>>>>all requests following  the  path.
>>>>=20
>>>> 2- Use Sling Resource Mappings
>>>>
>>>><http://sling.apache.org/documentation/the-sling-engine/mappings-for-
>>>>reso=
>>> urce-resolution.html>
>>>> to
>>>> redirect the requests (categorized by reg-ex) to different
>>>>resources, and  then write separate SlingServlet for each of those
>>>>resources. I still  have  some doubt if this is feasible.
>>>>=20
>>>> Do you have some suggestions?
>>>>=20
>>>> Thanks,
>>>> Duy
>

Reply via email to