You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Markus Joschko <ma...@gmail.com> on 2011/02/24 14:50:46 UTC

Reuse of JcrNodeResource possible?

Hi,

we have to implement two slightly opposing sets of requirements:

1a) Create notification e-mails with links to resources
1b) Allow external systems to store references to resources and to
retrieve resource data through that reference at a later date

and

2) Moving resources within the tree based on business processes

By moving a resource, the path would naturally change, which would
render any e-mail URL or external reference useless. For this reason,
it would be desirable to be able to use the node's UUID or, in cases
where the node was created by an external system, an immutable
property of the node which contains an externally created Id. Any URL
or reference based on this information would therefore remain valid
regardless of where the node is in the tree.

Our proposed solution is to implement a new ResourceProvider, mounted
in the virtual tree (under /uuid for example), which would process
URLs such as /uuid/e07a566f-9099-4859-bcdb-aadf76275bf2.tidy.json and
invoke the javax.jcr.Session.getItem method with [<uuid>] (e.g.
[e07a566f-9099-4859-bcdb-aadf76275bf2]) as the argument.

This works and it is possible to retrieve a JCR node with this
implemention. However, it is not currently possible to reuse
JcrNodeResource, as this class is a package private class in a private
package (bundle: org.apache.sling.jcr.resource). We do not wish to
implement our own JcrNodeResource.

Would it be possible to make these classes (namely JcrItemResource,
JcrPropertyResource and JcrNodeResource) available to other bundles,
either directly or through a public factory class?

Thanks in advance

Re: Reuse of JcrNodeResource possible?

Posted by Julian Sedding <js...@gmail.com>.
Hi Markus

You might get what you want by delegating your requests to the
ResourceResolver. I.e. you look up your node by UUID (or using search)
via the JCR API. Then you retrieve Node's path and call
resolver.getResource() using this path. Here you have a
JcrNodeResource, which you can return directly. In case you need the
resource's getPath() method to return the originally requested path,
you can wrap it before returning.

I used a similar approach for implementing SLING-1778[0], so you may
get inspiration from the attached patch.

Regards
Julian

[0] https://issues.apache.org/jira/browse/SLING-1778


On Thu, Feb 24, 2011 at 7:18 PM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 24.02.11 17:15, "Markus Joschko" <ma...@gmail.com> wrote:
>>would prefer direct POSTs instead of having to deal with a redirect.
>
> But you can easily have internal redirects. I think writing a separate
> resource resolver (et. al.) for that seems overkill.
>
> The servlet would look up the real resource depending on ID/UUID/etc., and
> do a request dispatch (aka sling:include) on the new resource. The actual
> request, incl. POST method, parameters, etc., can be passed through.
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>

Re: Reuse of JcrNodeResource possible?

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 24.02.11 17:15, "Markus Joschko" <ma...@gmail.com> wrote:
>would prefer direct POSTs instead of having to deal with a redirect.

But you can easily have internal redirects. I think writing a separate
resource resolver (et. al.) for that seems overkill.

The servlet would look up the real resource depending on ID/UUID/etc., and
do a request dispatch (aka sling:include) on the new resource. The actual
request, incl. POST method, parameters, etc., can be passed through.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: Reuse of JcrNodeResource possible?

Posted by Carsten Ziegeler <cz...@apache.org>.
> On Thu, Feb 24, 2011 at 5:23 PM, Bertrand Delacretaz
> <bd...@apache.org> wrote:
>> On Thu, Feb 24, 2011 at 5:15 PM, Markus Joschko
>> <ma...@gmail.com> wrote:
>>> ...That brings us back to the original question whether it is possible to
>>> handle the JCRNodeResource less restrictive as
>>> it could be used by all kinds of alternative JCR based Resolvers....
>>
>> Could you instead use a (to be created) JCRNodeResourceFactory service
>> with a method like this?
>>
>>  Resource createJCRNodeResource(Session session, String path)
>>
>> (I haven't checked if that needs other parameters, just the general idea)
>>
>> This would avoid exporting the JCRNodeResource class and keep coupling low.
>>

I think we should not go down this road - the ResourceResolver is the
service creating resources.

Carsten


-- 
Carsten Ziegeler
cziegeler@apache.org

Re: Reuse of JcrNodeResource possible?

Posted by Markus Joschko <ma...@gmail.com>.
On Thu, Feb 24, 2011 at 5:23 PM, Bertrand Delacretaz
<bd...@apache.org> wrote:
> On Thu, Feb 24, 2011 at 5:15 PM, Markus Joschko
> <ma...@gmail.com> wrote:
>> ...That brings us back to the original question whether it is possible to
>> handle the JCRNodeResource less restrictive as
>> it could be used by all kinds of alternative JCR based Resolvers....
>
> Could you instead use a (to be created) JCRNodeResourceFactory service
> with a method like this?
>
>  Resource createJCRNodeResource(Session session, String path)
>
> (I haven't checked if that needs other parameters, just the general idea)
>
> This would avoid exporting the JCRNodeResource class and keep coupling low.
>

Yes, that would be fine. It was one of the alternatives of my original
suggestion.

public Resource createJcrResource(ResourceResolver resolver, Item
item) should work.

It couldn't be a static method though, as a DynamicClassLoaderManager
would need to be injected for the creation of the JcrNodeResource.

Re: Reuse of JcrNodeResource possible?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, Feb 24, 2011 at 5:15 PM, Markus Joschko
<ma...@gmail.com> wrote:
> ...That brings us back to the original question whether it is possible to
> handle the JCRNodeResource less restrictive as
> it could be used by all kinds of alternative JCR based Resolvers....

Could you instead use a (to be created) JCRNodeResourceFactory service
with a method like this?

  Resource createJCRNodeResource(Session session, String path)

(I haven't checked if that needs other parameters, just the general idea)

This would avoid exporting the JCRNodeResource class and keep coupling low.

-Bertrand

Re: Reuse of JcrNodeResource possible?

Posted by Markus Joschko <ma...@gmail.com>.
On Thu, Feb 24, 2011 at 5:08 PM, Bertrand Delacretaz
<bd...@apache.org> wrote:
> On Thu, Feb 24, 2011 at 5:00 PM, Markus Joschko
> <ma...@gmail.com> wrote:
>> Bertrand:
>>> I think redirects in POST are no problem with non-browser clients, as
>>> per http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
>>
>> Mhm, I understand that the opposite way:
>>
>> "The action required MAY be carried out by the user agent without
>> interaction with the user if and only if the method used in the second
>> request is GET or HEAD"
>
> In your case, IIUC there's no human user, so the client system could
> make that decision, IMO.

That's true. Still I would like to make it as easy as possible to use
the API and would prefer direct POSTs instead of having to deal with a
redirect.
The "speaking" URL is nothing the external system cares about.

>>
>>> Note that I'm not against expanding the resource resolver - but there
>>> might be a simpler and more RESTful way.
>>
>> The problem we face currently is simple: We have information that will
>> be moved frequently in a tree but have the requirement that other
>> systems need to access that information directly (without doing a
>> search).
>> Is a URL like http://x.y.z/UUID/1234.html less REST? For a human it is
>> not as descriptive but for a system that doesn't matter....
>
> Right, "more RESTful" was not really what I had in mind - it's more
> that http might provide everything needed to solve your problem with
> little changes on the Sling side.
>
> Anyway, access by UUID can be useful as well, so both options are
> probably worth exploring.

And in our case not only the UUID but also an arbitrary systemId which
is not managed by the JCR itself.
That brings us back to the original question whether it is possible to
handle the JCRNodeResource less restrictive as
it could be used by all kinds of alternative JCR based Resolvers.

Regards,
 Markus

Re: Reuse of JcrNodeResource possible?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, Feb 24, 2011 at 5:00 PM, Markus Joschko
<ma...@gmail.com> wrote:
> Bertrand:
>> I think redirects in POST are no problem with non-browser clients, as
>> per http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
>
> Mhm, I understand that the opposite way:
>
> "The action required MAY be carried out by the user agent without
> interaction with the user if and only if the method used in the second
> request is GET or HEAD"

In your case, IIUC there's no human user, so the client system could
make that decision, IMO.

>
>> Note that I'm not against expanding the resource resolver - but there
>> might be a simpler and more RESTful way.
>
> The problem we face currently is simple: We have information that will
> be moved frequently in a tree but have the requirement that other
> systems need to access that information directly (without doing a
> search).
> Is a URL like http://x.y.z/UUID/1234.html less REST? For a human it is
> not as descriptive but for a system that doesn't matter....

Right, "more RESTful" was not really what I had in mind - it's more
that http might provide everything needed to solve your problem with
little changes on the Sling side.

Anyway, access by UUID can be useful as well, so both options are
probably worth exploring.

-Bertrand

Re: Reuse of JcrNodeResource possible?

Posted by Markus Joschko <ma...@gmail.com>.
>>> Can't you do that using HTTP redirects?
>>>
>>> Client requests /permalink/FOO, and a servlet mounted at /permalink
>>> does an HTTP redirects to the actual resource, using whatever
>>> mechanism is appropriate based on the semantics of FOO.
>>
>> Do redirects also work when doing a POST? We would like to post to
>> such a URL as well...
>
> If the use case is:
>
> -Browser POSTs to the permalink
> -Sling redirects
> -Browser should now POST the same thing to new location

I am not so much concerned about the browser. The UI is in our control
so a simple
redirect to the proper URL when the resource is first accessed is
certainly possible.

I am more concerned about external systems that just have stored one
id in their database and now
want to look up/augment the information in our system using that id.


> I think redirects in POST are no problem with non-browser clients, as
> per http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3

Mhm, I understand that the opposite way:

"The action required MAY be carried out by the user agent without
interaction with the user if and only if the method used in the second
request is GET or HEAD"

> Note that I'm not against expanding the resource resolver - but there
> might be a simpler and more RESTful way.

The problem we face currently is simple: We have information that will
be moved frequently in a tree but have the requirement that other
systems need to access that information directly (without doing a
search).
Is a URL like http://x.y.z/UUID/1234.html less REST? For a human it is
not as descriptive but for a system that doesn't matter.

Re: Reuse of JcrNodeResource possible?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, Feb 24, 2011 at 4:23 PM, Markus Joschko
<ma...@gmail.com> wrote:
>> Can't you do that using HTTP redirects?
>>
>> Client requests /permalink/FOO, and a servlet mounted at /permalink
>> does an HTTP redirects to the actual resource, using whatever
>> mechanism is appropriate based on the semantics of FOO.
>
> Do redirects also work when doing a POST? We would like to post to
> such a URL as well...

If the use case is:

-Browser POSTs to the permalink
-Sling redirects
-Browser should now POST the same thing to new location

Then I'm not sure - but I wouldn't a form with a POST email to people
anyway, expecting them to execute it much later (as per your original
post).

> ...Clients are not only browsers but also other systems. We'd like to
> keep the handling as simple as possible (therefore the externalid
> support)...

I think redirects in POST are no problem with non-browser clients, as
per http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3

Note that I'm not against expanding the resource resolver - but there
might be a simpler and more RESTful way.

-Bertrand

Re: Reuse of JcrNodeResource possible?

Posted by Markus Joschko <ma...@gmail.com>.
> Can't you do that using HTTP redirects?
>
> Client requests /permalink/FOO, and a servlet mounted at /permalink
> does an HTTP redirects to the actual resource, using whatever
> mechanism is appropriate based on the semantics of FOO.

Do redirects also work when doing a POST? We would like to post to
such a URL as well.
Clients are not only browsers but also other systems. We'd like to
keep the handling as simple as possible (therefore the externalid
support).

Markus

Re: Reuse of JcrNodeResource possible?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Markus,

On Thu, Feb 24, 2011 at 2:50 PM, Markus Joschko
<ma...@gmail.com> wrote:
> ...we have to implement two slightly opposing sets of requirements:
>
> 1a) Create notification e-mails with links to resources
> 1b) Allow external systems to store references to resources and to
> retrieve resource data through that reference at a later date
>
> and
>
> 2) Moving resources within the tree based on business processes
>
> By moving a resource, the path would naturally change, which would
> render any e-mail URL or external reference useless...

Can't you do that using HTTP redirects?

Client requests /permalink/FOO, and a servlet mounted at /permalink
does an HTTP redirects to the actual resource, using whatever
mechanism is appropriate based on the semantics of FOO.

-Bertrand

Re: Reuse of JcrNodeResource possible?

Posted by Markus Joschko <ma...@gmail.com>.
For UUIDs that would be fine. However we also want to support the
transparent usage of externalIds (ids already used in an external
system and added as properties to the nodes). That's basically a
search as a lookup mechanism. The rest is similar to the UUID
approach. But it doesn't make sense to contribute that so we still
need access to the JCRNodeResource in order to not dupcliate the code.

Markus

On Thu, Feb 24, 2011 at 3:06 PM, Justin Edelson
<ju...@justinedelson.com> wrote:
> Would you be willing/interested in submitting a patch to add this functionality (the resource provider) to the JCR Resource bundle? I believe there's already a JIRA issue for adding something similar.
>
> That would be preferable IMHO to exporting the package.
>
> Justin
>
> On Feb 24, 2011, at 8:50 AM, Markus Joschko <ma...@gmail.com> wrote:
>
>> Hi,
>>
>> we have to implement two slightly opposing sets of requirements:
>>
>> 1a) Create notification e-mails with links to resources
>> 1b) Allow external systems to store references to resources and to
>> retrieve resource data through that reference at a later date
>>
>> and
>>
>> 2) Moving resources within the tree based on business processes
>>
>> By moving a resource, the path would naturally change, which would
>> render any e-mail URL or external reference useless. For this reason,
>> it would be desirable to be able to use the node's UUID or, in cases
>> where the node was created by an external system, an immutable
>> property of the node which contains an externally created Id. Any URL
>> or reference based on this information would therefore remain valid
>> regardless of where the node is in the tree.
>>
>> Our proposed solution is to implement a new ResourceProvider, mounted
>> in the virtual tree (under /uuid for example), which would process
>> URLs such as /uuid/e07a566f-9099-4859-bcdb-aadf76275bf2.tidy.json and
>> invoke the javax.jcr.Session.getItem method with [<uuid>] (e.g.
>> [e07a566f-9099-4859-bcdb-aadf76275bf2]) as the argument.
>>
>> This works and it is possible to retrieve a JCR node with this
>> implemention. However, it is not currently possible to reuse
>> JcrNodeResource, as this class is a package private class in a private
>> package (bundle: org.apache.sling.jcr.resource). We do not wish to
>> implement our own JcrNodeResource.
>>
>> Would it be possible to make these classes (namely JcrItemResource,
>> JcrPropertyResource and JcrNodeResource) available to other bundles,
>> either directly or through a public factory class?
>>
>> Thanks in advance
>

Re: Reuse of JcrNodeResource possible?

Posted by Justin Edelson <ju...@justinedelson.com>.
Would you be willing/interested in submitting a patch to add this functionality (the resource provider) to the JCR Resource bundle? I believe there's already a JIRA issue for adding something similar.

That would be preferable IMHO to exporting the package.

Justin

On Feb 24, 2011, at 8:50 AM, Markus Joschko <ma...@gmail.com> wrote:

> Hi,
> 
> we have to implement two slightly opposing sets of requirements:
> 
> 1a) Create notification e-mails with links to resources
> 1b) Allow external systems to store references to resources and to
> retrieve resource data through that reference at a later date
> 
> and
> 
> 2) Moving resources within the tree based on business processes
> 
> By moving a resource, the path would naturally change, which would
> render any e-mail URL or external reference useless. For this reason,
> it would be desirable to be able to use the node's UUID or, in cases
> where the node was created by an external system, an immutable
> property of the node which contains an externally created Id. Any URL
> or reference based on this information would therefore remain valid
> regardless of where the node is in the tree.
> 
> Our proposed solution is to implement a new ResourceProvider, mounted
> in the virtual tree (under /uuid for example), which would process
> URLs such as /uuid/e07a566f-9099-4859-bcdb-aadf76275bf2.tidy.json and
> invoke the javax.jcr.Session.getItem method with [<uuid>] (e.g.
> [e07a566f-9099-4859-bcdb-aadf76275bf2]) as the argument.
> 
> This works and it is possible to retrieve a JCR node with this
> implemention. However, it is not currently possible to reuse
> JcrNodeResource, as this class is a package private class in a private
> package (bundle: org.apache.sling.jcr.resource). We do not wish to
> implement our own JcrNodeResource.
> 
> Would it be possible to make these classes (namely JcrItemResource,
> JcrPropertyResource and JcrNodeResource) available to other bundles,
> either directly or through a public factory class?
> 
> Thanks in advance

Re: Reuse of JcrNodeResource possible?

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

I think the best way for you would be to embed the classes in question
in your bundle - we do this in some occasions as well.

I think we should not make the implemntations publically available or
add any other mechanism.

Regards
Carsten

Markus Joschko  wrote
> Hi,
> 
> we have to implement two slightly opposing sets of requirements:
> 
> 1a) Create notification e-mails with links to resources
> 1b) Allow external systems to store references to resources and to
> retrieve resource data through that reference at a later date
> 
> and
> 
> 2) Moving resources within the tree based on business processes
> 
> By moving a resource, the path would naturally change, which would
> render any e-mail URL or external reference useless. For this reason,
> it would be desirable to be able to use the node's UUID or, in cases
> where the node was created by an external system, an immutable
> property of the node which contains an externally created Id. Any URL
> or reference based on this information would therefore remain valid
> regardless of where the node is in the tree.
> 
> Our proposed solution is to implement a new ResourceProvider, mounted
> in the virtual tree (under /uuid for example), which would process
> URLs such as /uuid/e07a566f-9099-4859-bcdb-aadf76275bf2.tidy.json and
> invoke the javax.jcr.Session.getItem method with [<uuid>] (e.g.
> [e07a566f-9099-4859-bcdb-aadf76275bf2]) as the argument.
> 
> This works and it is possible to retrieve a JCR node with this
> implemention. However, it is not currently possible to reuse
> JcrNodeResource, as this class is a package private class in a private
> package (bundle: org.apache.sling.jcr.resource). We do not wish to
> implement our own JcrNodeResource.
> 
> Would it be possible to make these classes (namely JcrItemResource,
> JcrPropertyResource and JcrNodeResource) available to other bundles,
> either directly or through a public factory class?
> 
> Thanks in advance
> 


-- 
Carsten Ziegeler
cziegeler@apache.org