You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Bryce Ewing <br...@smx.co.nz> on 2008/07/02 06:46:10 UTC
Resources provided by Restlet
Hi,
I am presently trying to facilitate two parts of our software platform
to work well together. One of these is a REST based interface for data
management to provision customers / users etc. which has been developed
using Restlet and Hibernate (and has been developed as OSGi bundles).
And the other is our portal which is being developed using sling to
provide the pages that make up the portal as well as serving up the
javascript administration interface (using ExtJS).
Through the admin interface a logged in user can manage data through
ajax rest based calls. In order for these calls to work the rest admin
api needs to be served up within the same uri space as the rest of the
portal / admin interface.
I have had a look into the ResourceProvider interface and how this
works, and other than getting quite confused along the way my
understanding is that this is only for accessing data from other sources
(not supporting POST/PUT/DELETE?). I may be wrong here, not sure.
So really my question is what would be a good way of having the two uri
spaces visible as one?
I was thinking that it may be that I should just mount the Restlet
servlet on certain root uri's, which will override sling... but then
this data would not be accessible through sling at all. This may be a
good short term solution (and one that it would be good to be able to
know how to do?).
Preferably I would like all of the data to be visible directly within sling.
Thanks in advance.
Bryce
Re: Resources provided by Restlet
Posted by Bryce Ewing <br...@smx.co.nz>.
Update: I have restlet now providing the data through a servlet that is
mounted at one point in the same uri space, still would be keen to join
the spaces.
Bryce Ewing wrote:
> Hi,
>
> I am presently trying to facilitate two parts of our software platform
> to work well together. One of these is a REST based interface for
> data management to provision customers / users etc. which has been
> developed using Restlet and Hibernate (and has been developed as OSGi
> bundles). And the other is our portal which is being developed using
> sling to provide the pages that make up the portal as well as serving
> up the javascript administration interface (using ExtJS).
>
> Through the admin interface a logged in user can manage data through
> ajax rest based calls. In order for these calls to work the rest
> admin api needs to be served up within the same uri space as the rest
> of the portal / admin interface.
>
> I have had a look into the ResourceProvider interface and how this
> works, and other than getting quite confused along the way my
> understanding is that this is only for accessing data from other
> sources (not supporting POST/PUT/DELETE?). I may be wrong here, not
> sure.
>
> So really my question is what would be a good way of having the two
> uri spaces visible as one?
>
> I was thinking that it may be that I should just mount the Restlet
> servlet on certain root uri's, which will override sling... but then
> this data would not be accessible through sling at all. This may be a
> good short term solution (and one that it would be good to be able to
> know how to do?).
>
> Preferably I would like all of the data to be visible directly within
> sling.
>
> Thanks in advance.
> Bryce
Re: Resources provided by Restlet
Posted by Felix Meschberger <fm...@gmail.com>.
Hi Bryce,
Bryce Ewing schrieb:
> Thanks Felix,
>
> What you have suggested sounds ideal and I think that will do exactly
> what I want. I wont be able to do this right at the moment due to
> pressing deadlines, but will let you know once I get a chance to come
> back to this.
Great! Looking forward to hearing from you on this topic again !
Regards
Felix
>
> Cheers
> Bryce
>
> Felix Meschberger wrote:
>> Hi Bryce,
>>
>> Sorry for chiming in late, I was distracted by other work ...
>>
>> Yes, your problem might well be solved by a combination a
>> ResourceProvider and a registered Servlet.
>>
>> The ResourceProvider would make the RESTlet provides resources visible
>> in Sling's virtual resource tree. So if you map /users to in RESTlet,
>> your ResourceProvider would provide a Resource backed by Hibernate
>> representing the collection of users. This collection would have a
>> specific resource type, say "restlet".
>>
>> The Servlet you provide is registered for the resource types provided
>> by the ResourceProvider (use the sling.servlet.resourceTypes service
>> property) and for "all" methods (set sling.servlet.methods to the
>> special value "*"). The Servlet's service() method would simply
>> forward to the RESTlet servlet.
>>
>> Now all requests to the resources provided by the RESTlet
>> ResourceProvider having no request extension (e.g. /users or
>> /users/123) would be handled by your Servlet forwarding to RESTlet.
>>
>> In addtion - for presentation - you might create servlets or scripts
>> for the RESTlet resource types for specific extensions. E.g. you
>> create a script /apps/restlet/html.jsp to handle requests to /users.html
>>
>> Does this help ?
>>
>> Regards
>> Felix
>>
>> Bryce Ewing schrieb:
>>> Ok, I think I have managed to totally confuse you, so will try to
>>> come up with a concrete example.
>>>
>>> Restlet User example:
>>> POST {
>>> firstName: "First",
>>> lastName: "Last",
>>> address: {
>>> line1: "Line 1",
>>> line2: "Line 2",
>>> city: "City", ... etc.
>>> }
>>> }
>>> to /users creates /users/123
>>>
>>> This will now return the same json representation when a GET is
>>> performed on the /users/123 uri (PUT against this uri will update the
>>> user, and DELETE will remove them). All of this is being performed
>>> through the restlet part of the system.
>>>
>>> Then say across the fence on the portal part of the system (which is
>>> being delivered by sling) we have a uri /addressbook/users/123.html
>>> that will display an html representation of the user along with their
>>> address, and this will be rendered into the portal template etc. by a
>>> script say /apps/addressbook/html.ftl
>>>
>>> I think that this part might be able to be accomplished with
>>> ResourceProvider, though slightly confused how this works, but I am
>>> not sure if I would also be able to do a PUT against
>>> /addressbook/users/123 in order to update the user entry or whether I
>>> would have to go straight to the /users/123 uri to do this?
>>>
>>> Bertrand Delacretaz wrote:
>>>> On Wed, Jul 2, 2008 at 11:41 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>>>>
>>>>> ...What I have done at present is to move all the restlet based api
>>>>> under /api
>>>>> (managed by a restlet servlet). But I would also like to be able
>>>>> to access
>>>>> the data from within Sling and use the same rendering methods etc....
>>>>>
>>>>
>>>> That's where I'm not sure what you mean, can you give an example of an
>>>> URL that would be processed by Sling, and what you expect it to do?
>>>> And what would differentiate that URL from one that's processed by
>>>> Restlet?
>>>>
>>>> -Bertrand
>>>>
>>>
>
Re: Resources provided by Restlet
Posted by Bryce Ewing <br...@smx.co.nz>.
Thanks Felix,
What you have suggested sounds ideal and I think that will do exactly
what I want. I wont be able to do this right at the moment due to
pressing deadlines, but will let you know once I get a chance to come
back to this.
Cheers
Bryce
Felix Meschberger wrote:
> Hi Bryce,
>
> Sorry for chiming in late, I was distracted by other work ...
>
> Yes, your problem might well be solved by a combination a
> ResourceProvider and a registered Servlet.
>
> The ResourceProvider would make the RESTlet provides resources visible
> in Sling's virtual resource tree. So if you map /users to in RESTlet,
> your ResourceProvider would provide a Resource backed by Hibernate
> representing the collection of users. This collection would have a
> specific resource type, say "restlet".
>
> The Servlet you provide is registered for the resource types provided
> by the ResourceProvider (use the sling.servlet.resourceTypes service
> property) and for "all" methods (set sling.servlet.methods to the
> special value "*"). The Servlet's service() method would simply
> forward to the RESTlet servlet.
>
> Now all requests to the resources provided by the RESTlet
> ResourceProvider having no request extension (e.g. /users or
> /users/123) would be handled by your Servlet forwarding to RESTlet.
>
> In addtion - for presentation - you might create servlets or scripts
> for the RESTlet resource types for specific extensions. E.g. you
> create a script /apps/restlet/html.jsp to handle requests to /users.html
>
> Does this help ?
>
> Regards
> Felix
>
> Bryce Ewing schrieb:
>> Ok, I think I have managed to totally confuse you, so will try to
>> come up with a concrete example.
>>
>> Restlet User example:
>> POST {
>> firstName: "First",
>> lastName: "Last",
>> address: {
>> line1: "Line 1",
>> line2: "Line 2",
>> city: "City", ... etc.
>> }
>> }
>> to /users creates /users/123
>>
>> This will now return the same json representation when a GET is
>> performed on the /users/123 uri (PUT against this uri will update the
>> user, and DELETE will remove them). All of this is being performed
>> through the restlet part of the system.
>>
>> Then say across the fence on the portal part of the system (which is
>> being delivered by sling) we have a uri /addressbook/users/123.html
>> that will display an html representation of the user along with their
>> address, and this will be rendered into the portal template etc. by a
>> script say /apps/addressbook/html.ftl
>>
>> I think that this part might be able to be accomplished with
>> ResourceProvider, though slightly confused how this works, but I am
>> not sure if I would also be able to do a PUT against
>> /addressbook/users/123 in order to update the user entry or whether I
>> would have to go straight to the /users/123 uri to do this?
>>
>> Bertrand Delacretaz wrote:
>>> On Wed, Jul 2, 2008 at 11:41 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>>>
>>>> ...What I have done at present is to move all the restlet based api
>>>> under /api
>>>> (managed by a restlet servlet). But I would also like to be able
>>>> to access
>>>> the data from within Sling and use the same rendering methods etc....
>>>>
>>>
>>> That's where I'm not sure what you mean, can you give an example of an
>>> URL that would be processed by Sling, and what you expect it to do?
>>> And what would differentiate that URL from one that's processed by
>>> Restlet?
>>>
>>> -Bertrand
>>>
>>
Re: Resources provided by Restlet
Posted by Felix Meschberger <fm...@gmail.com>.
Hi Bryce,
Sorry for chiming in late, I was distracted by other work ...
Yes, your problem might well be solved by a combination a
ResourceProvider and a registered Servlet.
The ResourceProvider would make the RESTlet provides resources visible
in Sling's virtual resource tree. So if you map /users to in RESTlet,
your ResourceProvider would provide a Resource backed by Hibernate
representing the collection of users. This collection would have a
specific resource type, say "restlet".
The Servlet you provide is registered for the resource types provided by
the ResourceProvider (use the sling.servlet.resourceTypes service
property) and for "all" methods (set sling.servlet.methods to the
special value "*"). The Servlet's service() method would simply forward
to the RESTlet servlet.
Now all requests to the resources provided by the RESTlet
ResourceProvider having no request extension (e.g. /users or /users/123)
would be handled by your Servlet forwarding to RESTlet.
In addtion - for presentation - you might create servlets or scripts for
the RESTlet resource types for specific extensions. E.g. you create a
script /apps/restlet/html.jsp to handle requests to /users.html
Does this help ?
Regards
Felix
Bryce Ewing schrieb:
> Ok, I think I have managed to totally confuse you, so will try to come
> up with a concrete example.
>
> Restlet User example:
> POST {
> firstName: "First",
> lastName: "Last",
> address: {
> line1: "Line 1",
> line2: "Line 2",
> city: "City", ... etc.
> }
> }
> to /users creates /users/123
>
> This will now return the same json representation when a GET is
> performed on the /users/123 uri (PUT against this uri will update the
> user, and DELETE will remove them). All of this is being performed
> through the restlet part of the system.
>
> Then say across the fence on the portal part of the system (which is
> being delivered by sling) we have a uri /addressbook/users/123.html that
> will display an html representation of the user along with their
> address, and this will be rendered into the portal template etc. by a
> script say /apps/addressbook/html.ftl
>
> I think that this part might be able to be accomplished with
> ResourceProvider, though slightly confused how this works, but I am not
> sure if I would also be able to do a PUT against /addressbook/users/123
> in order to update the user entry or whether I would have to go straight
> to the /users/123 uri to do this?
>
> Bertrand Delacretaz wrote:
>> On Wed, Jul 2, 2008 at 11:41 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>>
>>> ...What I have done at present is to move all the restlet based api
>>> under /api
>>> (managed by a restlet servlet). But I would also like to be able to
>>> access
>>> the data from within Sling and use the same rendering methods etc....
>>>
>>
>> That's where I'm not sure what you mean, can you give an example of an
>> URL that would be processed by Sling, and what you expect it to do?
>> And what would differentiate that URL from one that's processed by
>> Restlet?
>>
>> -Bertrand
>>
>
Re: Resources provided by Restlet
Posted by Bryce Ewing <br...@smx.co.nz>.
Ok, I think I have managed to totally confuse you, so will try to come
up with a concrete example.
Restlet User example:
POST {
firstName: "First",
lastName: "Last",
address: {
line1: "Line 1",
line2: "Line 2",
city: "City", ... etc.
}
}
to /users creates /users/123
This will now return the same json representation when a GET is
performed on the /users/123 uri (PUT against this uri will update the
user, and DELETE will remove them). All of this is being performed
through the restlet part of the system.
Then say across the fence on the portal part of the system (which is
being delivered by sling) we have a uri /addressbook/users/123.html that
will display an html representation of the user along with their
address, and this will be rendered into the portal template etc. by a
script say /apps/addressbook/html.ftl
I think that this part might be able to be accomplished with
ResourceProvider, though slightly confused how this works, but I am not
sure if I would also be able to do a PUT against /addressbook/users/123
in order to update the user entry or whether I would have to go straight
to the /users/123 uri to do this?
Bertrand Delacretaz wrote:
> On Wed, Jul 2, 2008 at 11:41 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>
>> ...What I have done at present is to move all the restlet based api under /api
>> (managed by a restlet servlet). But I would also like to be able to access
>> the data from within Sling and use the same rendering methods etc....
>>
>
> That's where I'm not sure what you mean, can you give an example of an
> URL that would be processed by Sling, and what you expect it to do?
> And what would differentiate that URL from one that's processed by
> Restlet?
>
> -Bertrand
>
Re: Resources provided by Restlet
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Jul 2, 2008 at 11:41 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...What I have done at present is to move all the restlet based api under /api
> (managed by a restlet servlet). But I would also like to be able to access
> the data from within Sling and use the same rendering methods etc....
That's where I'm not sure what you mean, can you give an example of an
URL that would be processed by Sling, and what you expect it to do?
And what would differentiate that URL from one that's processed by
Restlet?
-Bertrand
Re: Resources provided by Restlet
Posted by Bryce Ewing <br...@smx.co.nz>.
I am not sure what you know about Restlet, but what I have is certain
resources mounted at certain uri's and yes there is a /users uri that
maps to a Resource that returns a json array of user's. Performing a
POST on /users will create a new user, PUTting against /users/{userId}
will update the details of the user.... all of this is done through
Restlet and backed by Hibernate.
So we already have a lot of the REST API available through this. This
is all managed from within a javascript application that does ajax
GET/PUT/POST/DELETE calls.
What I have done at present is to move all the restlet based api under
/api (managed by a restlet servlet). But I would also like to be able
to access the data from within Sling and use the same rendering methods etc.
I think that the ResourceProvider does this for GET's but I am unsure
whether I could do the same for POST's etc.
Bertrand Delacretaz wrote:
> On Wed, Jul 2, 2008 at 6:46 AM, Bryce Ewing <br...@smx.co.nz> wrote:
>
>
>> ...I was thinking that it may be that I should just mount the Restlet servlet
>> on certain root uri's, which will override sling... but then this data would
>> not be accessible through sling at all. This may be a good short term
>> solution (and one that it would be good to be able to know how to do?)
>>
>> Preferably I would like all of the data to be visible directly within sling....
>>
>
> I'm not sure if I understand exactly what you're after, is that something like
>
> GET /users -> served by Restlet
> GET /users.html -> served by Sling
>
> If that's the case, the simplest way might be to create a front-end
> servlet that implements this decision and forwards to the appropriate
> servlet, to avoid having to hack the Sling or Restlet servlets.
>
> Another approach, if you have an httpd front-end, would be to rewrite
> URLs to redirect them to the appropriate backend.
>
> -Bertrand
>
Re: Resources provided by Restlet
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Jul 2, 2008 at 6:46 AM, Bryce Ewing <br...@smx.co.nz> wrote:
> ...I was thinking that it may be that I should just mount the Restlet servlet
> on certain root uri's, which will override sling... but then this data would
> not be accessible through sling at all. This may be a good short term
> solution (and one that it would be good to be able to know how to do?)
>
> Preferably I would like all of the data to be visible directly within sling....
I'm not sure if I understand exactly what you're after, is that something like
GET /users -> served by Restlet
GET /users.html -> served by Sling
If that's the case, the simplest way might be to create a front-end
servlet that implements this decision and forwards to the appropriate
servlet, to avoid having to hack the Sling or Restlet servlets.
Another approach, if you have an httpd front-end, would be to rewrite
URLs to redirect them to the appropriate backend.
-Bertrand