You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by Reto Bachmann-Gmür <re...@apache.org> on 2011/09/01 21:54:24 UTC

Wink OSGI service

Hello

I've recently wrote a wink-based patch to integrate jax-rs support in
Sling [1]. In a very similar way Wink could be used in Clerezza where
we're currently using our own jax-rs implementation.

In both projects there are in my view the following requirement:

1. Possibility for jax-rs components (providers and resources) and/or
applications to be registered and unregistered in an OSGi environment
2. Possibility to handle a request with a Jax-RS resource other than
the one with matching @Path annotation

The second requirements might need a bit more explanation. In sling
servlets are typically bound to a type of JCR-resources even though
this goes beyond the jax-rs spec it would be nice to bind jax-rs style
classes to such a JCR-resource type, the patch I attached to
SLING-2192 allows this, see my blog post [2] for an example usage.
Similarly in Clerezza jax-rs style resource can be bound to an
RDF-Type [3].

It would be good to implement the basic support for these two
requirements directly in wink. Roughly this would correspond to the
org.apache.sling.jaxrs.wink package in the sling-patch. The following
I think could be discussed and improved:
- Unregistration of components cause the a new RequestProcessor to be created
- Setting a root-resource shadowing the one that would be located
using the path is done with a ThreadLocal variable, this might better
be passed as property of the ServletRequest

Before creating an issue and attaching a patch I though I ask here if
this functionality would be welcomed in Wink.

Cheers,
Reto

1. https://issues.apache.org/jira/secure/attachment/12492153/SLING-2192-with-sling-style-style-registration.patch
2. https://farewellutopia.com/2011/08/23/Add-some-jax-rs-support-to-sling
3. For an example see:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.scripting/src/main/java/org/apache/clerezza/platform/scripting/ScriptGeneratedResourceTypeHandler.java

Re: Wink OSGI service

Posted by Luciano Resende <lu...@gmail.com>.
On Wed, Sep 21, 2011 at 3:01 PM, Reto Bachmann-Gmür <re...@apache.org> wrote:
> Hi,
>
> For the ongoing discussion about SLING-2192 it would be great if I could get
> some feedback on the patch I propose for WINK-351 as to be able to estimate
> if and when this could become part of wink. The patch would greatly simplify
> the task of integrating wink into Sling or Clerezza.
>
> Cheers,
> Reto
>

I gotta find some time to look into these... others from the community
are welcome to jump in as well :)


-- 
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/

Re: Wink OSGI service

Posted by Reto Bachmann-Gmür <re...@apache.org>.
Hi,

For the ongoing discussion about SLING-2192 it would be great if I could get
some feedback on the patch I propose for WINK-351 as to be able to estimate
if and when this could become part of wink. The patch would greatly simplify
the task of integrating wink into Sling or Clerezza.

Cheers,
Reto

On Sat, Sep 17, 2011 at 1:38 PM, Reto Bachmann-Gmür <re...@apache.org> wrote:

> Hi Luciano,
>
> I've created WINK-351 and attached the patch to it.
>
> After wink has been compiled with the patch you can:
>
> cd wink-examples/ext/OSGi/
> mvn pax:run
>
> This should start an OSGi environment with the needed bundles, if all
> goes well you will be greeted at
>
> http://localhost:8080/demo/jaxrs/greeting?name=Luciano
>
> Cheers,
> Reto
>
>
> On Thu, Sep 8, 2011 at 6:49 PM, Reto Bachmann-Gmür <re...@apache.org>
> wrote:
> >
> > On Sep 8, 2011 6:39 PM, "Luciano Resende" <lu...@gmail.com> wrote:
> >>
> >> On Fri, Sep 2, 2011 at 1:06 PM, Reto Bachmann-Gmür <re...@apache.org>
> >> wrote:
> >> > On Fri, Sep 2, 2011 at 6:22 PM, Luciano Resende <luckbr1975@gmail.com
> >
> >> > wrote:
> >> > ...
> >> >>> The second requirements might need a bit more explanation. In sling
> >> >>> servlets are typically bound to a type of JCR-resources even though
> >> >>> this goes beyond the jax-rs spec it would be nice to bind jax-rs
> style
> >> >>> classes to such a JCR-resource type, the patch I attached to
> >> >>> SLING-2192 allows this, see my blog post [2] for an example usage.
> >> >>> Similarly in Clerezza jax-rs style resource can be bound to an
> >> >>> RDF-Type [3].
> >> >>>
> >> >>
> >> >> As for your second example, maybe a simple way would be to have
> >> >> JCR-resource types defined as specific media types, in this way, you
> >> >> could envision having a single endpoint for CRUD operations in your
> >> >> JCR repository to work based on the media type being requested. WDYT
> ?
> >> >
> >> > Hi Luciano,
> >> >
> >> > I must admit that I don't know as much of jcr and sling as I know
> >> > about clerezza. Not sure if I understand you correctly, but the
> >> > jcr:type of resource (which can be an arbitrary string) seems
> >> > orthogonal to the media type: on one hand we have the selection of the
> >> > root-resource on the other the production of an appropriate
> >> > representation.
> >> >
> >> > Sling has a mechanism that has shown to work well that associates code
> >> > handling the request to a specific URI, without changing this
> >> > mechanism I'd like support for jax-rs root resource like classes
> >> > ("like" because the @Path-Annotation are missing or ignored) as an
> >> > alternative to servlets or scripts. I think Wink should not directly
> >> > support other ways to bind resource-classes to URI than @Path, but it
> >> > should provide an easy way for frameworks integrating wink (like sling
> >> > or clerezza) to support other mechanisms.
> >> >
> >> > To avoid osgi-dependencies in wink-server I suggest providing an
> >> > wink-osgi-service bundle that provides a service with the following
> >> > methods
> >> >
> >> > //handles a request using previously bound root resources
> >> > void handleRequest(HttpServletRequest request, HttpServletResponse
> >> > response)
> >> >
> >> > //that's the method that allows easy integration with Sling or
> Clerezza
> >> > void handleRequest(HttpServletRequest request, HttpServletResponse
> >> > response, Object rootResource)
> >> >
> >> > //bind root resource or provider, binding classes seems against OSGi
> >> > architecture
> >> > void bindComponent(Object component)
> >> >
> >> > void unbindComponent(Object component)
> >> >
> >> > //framework supporting other request processing mechanism can use this
> >> > method to check if Wink can handle a request (with the currently bound
> >> > root resources)
> >> > boolean hasRootResourceForUriPath(String uriPath)
> >> >
> >> > Do you think a new module providing such a bundle and service would
> >> > fit into Wink? If so I'll open an issue and attach a patch to it. It
> >> > can be implemented without modifying other code, even though in future
> >> > the existing RequestProcessor might be adapted for a more seamless
> >> > integration.
> >>
> >> Is this new module have any Sling or Clerezza dependencies ?
> >>
> > No.
> >
> > Reto
> >
>

Re: Wink OSGI service

Posted by Reto Bachmann-Gmür <re...@apache.org>.
Hi Luciano,

I've created WINK-351 and attached the patch to it.

After wink has been compiled with the patch you can:

cd wink-examples/ext/OSGi/
mvn pax:run

This should start an OSGi environment with the needed bundles, if all
goes well you will be greeted at

http://localhost:8080/demo/jaxrs/greeting?name=Luciano

Cheers,
Reto


On Thu, Sep 8, 2011 at 6:49 PM, Reto Bachmann-Gmür <re...@apache.org> wrote:
>
> On Sep 8, 2011 6:39 PM, "Luciano Resende" <lu...@gmail.com> wrote:
>>
>> On Fri, Sep 2, 2011 at 1:06 PM, Reto Bachmann-Gmür <re...@apache.org>
>> wrote:
>> > On Fri, Sep 2, 2011 at 6:22 PM, Luciano Resende <lu...@gmail.com>
>> > wrote:
>> > ...
>> >>> The second requirements might need a bit more explanation. In sling
>> >>> servlets are typically bound to a type of JCR-resources even though
>> >>> this goes beyond the jax-rs spec it would be nice to bind jax-rs style
>> >>> classes to such a JCR-resource type, the patch I attached to
>> >>> SLING-2192 allows this, see my blog post [2] for an example usage.
>> >>> Similarly in Clerezza jax-rs style resource can be bound to an
>> >>> RDF-Type [3].
>> >>>
>> >>
>> >> As for your second example, maybe a simple way would be to have
>> >> JCR-resource types defined as specific media types, in this way, you
>> >> could envision having a single endpoint for CRUD operations in your
>> >> JCR repository to work based on the media type being requested. WDYT ?
>> >
>> > Hi Luciano,
>> >
>> > I must admit that I don't know as much of jcr and sling as I know
>> > about clerezza. Not sure if I understand you correctly, but the
>> > jcr:type of resource (which can be an arbitrary string) seems
>> > orthogonal to the media type: on one hand we have the selection of the
>> > root-resource on the other the production of an appropriate
>> > representation.
>> >
>> > Sling has a mechanism that has shown to work well that associates code
>> > handling the request to a specific URI, without changing this
>> > mechanism I'd like support for jax-rs root resource like classes
>> > ("like" because the @Path-Annotation are missing or ignored) as an
>> > alternative to servlets or scripts. I think Wink should not directly
>> > support other ways to bind resource-classes to URI than @Path, but it
>> > should provide an easy way for frameworks integrating wink (like sling
>> > or clerezza) to support other mechanisms.
>> >
>> > To avoid osgi-dependencies in wink-server I suggest providing an
>> > wink-osgi-service bundle that provides a service with the following
>> > methods
>> >
>> > //handles a request using previously bound root resources
>> > void handleRequest(HttpServletRequest request, HttpServletResponse
>> > response)
>> >
>> > //that's the method that allows easy integration with Sling or Clerezza
>> > void handleRequest(HttpServletRequest request, HttpServletResponse
>> > response, Object rootResource)
>> >
>> > //bind root resource or provider, binding classes seems against OSGi
>> > architecture
>> > void bindComponent(Object component)
>> >
>> > void unbindComponent(Object component)
>> >
>> > //framework supporting other request processing mechanism can use this
>> > method to check if Wink can handle a request (with the currently bound
>> > root resources)
>> > boolean hasRootResourceForUriPath(String uriPath)
>> >
>> > Do you think a new module providing such a bundle and service would
>> > fit into Wink? If so I'll open an issue and attach a patch to it. It
>> > can be implemented without modifying other code, even though in future
>> > the existing RequestProcessor might be adapted for a more seamless
>> > integration.
>>
>> Is this new module have any Sling or Clerezza dependencies ?
>>
> No.
>
> Reto
>

Re: Wink OSGI service

Posted by Reto Bachmann-Gmür <re...@apache.org>.
On Sep 8, 2011 6:39 PM, "Luciano Resende" <lu...@gmail.com> wrote:
>
> On Fri, Sep 2, 2011 at 1:06 PM, Reto Bachmann-Gmür <re...@apache.org>
wrote:
> > On Fri, Sep 2, 2011 at 6:22 PM, Luciano Resende <lu...@gmail.com>
wrote:
> > ...
> >>> The second requirements might need a bit more explanation. In sling
> >>> servlets are typically bound to a type of JCR-resources even though
> >>> this goes beyond the jax-rs spec it would be nice to bind jax-rs style
> >>> classes to such a JCR-resource type, the patch I attached to
> >>> SLING-2192 allows this, see my blog post [2] for an example usage.
> >>> Similarly in Clerezza jax-rs style resource can be bound to an
> >>> RDF-Type [3].
> >>>
> >>
> >> As for your second example, maybe a simple way would be to have
> >> JCR-resource types defined as specific media types, in this way, you
> >> could envision having a single endpoint for CRUD operations in your
> >> JCR repository to work based on the media type being requested. WDYT ?
> >
> > Hi Luciano,
> >
> > I must admit that I don't know as much of jcr and sling as I know
> > about clerezza. Not sure if I understand you correctly, but the
> > jcr:type of resource (which can be an arbitrary string) seems
> > orthogonal to the media type: on one hand we have the selection of the
> > root-resource on the other the production of an appropriate
> > representation.
> >
> > Sling has a mechanism that has shown to work well that associates code
> > handling the request to a specific URI, without changing this
> > mechanism I'd like support for jax-rs root resource like classes
> > ("like" because the @Path-Annotation are missing or ignored) as an
> > alternative to servlets or scripts. I think Wink should not directly
> > support other ways to bind resource-classes to URI than @Path, but it
> > should provide an easy way for frameworks integrating wink (like sling
> > or clerezza) to support other mechanisms.
> >
> > To avoid osgi-dependencies in wink-server I suggest providing an
> > wink-osgi-service bundle that provides a service with the following
> > methods
> >
> > //handles a request using previously bound root resources
> > void handleRequest(HttpServletRequest request, HttpServletResponse
response)
> >
> > //that's the method that allows easy integration with Sling or Clerezza
> > void handleRequest(HttpServletRequest request, HttpServletResponse
> > response, Object rootResource)
> >
> > //bind root resource or provider, binding classes seems against OSGi
> > architecture
> > void bindComponent(Object component)
> >
> > void unbindComponent(Object component)
> >
> > //framework supporting other request processing mechanism can use this
> > method to check if Wink can handle a request (with the currently bound
> > root resources)
> > boolean hasRootResourceForUriPath(String uriPath)
> >
> > Do you think a new module providing such a bundle and service would
> > fit into Wink? If so I'll open an issue and attach a patch to it. It
> > can be implemented without modifying other code, even though in future
> > the existing RequestProcessor might be adapted for a more seamless
> > integration.
>
> Is this new module have any Sling or Clerezza dependencies ?
>
No.

Reto

Re: Wink OSGI service

Posted by Luciano Resende <lu...@gmail.com>.
On Fri, Sep 2, 2011 at 1:06 PM, Reto Bachmann-Gmür <re...@apache.org> wrote:
> On Fri, Sep 2, 2011 at 6:22 PM, Luciano Resende <lu...@gmail.com> wrote:
> ...
>>> The second requirements might need a bit more explanation. In sling
>>> servlets are typically bound to a type of JCR-resources even though
>>> this goes beyond the jax-rs spec it would be nice to bind jax-rs style
>>> classes to such a JCR-resource type, the patch I attached to
>>> SLING-2192 allows this, see my blog post [2] for an example usage.
>>> Similarly in Clerezza jax-rs style resource can be bound to an
>>> RDF-Type [3].
>>>
>>
>> As for your second example, maybe a simple way would be to have
>> JCR-resource types defined as specific media types, in this way, you
>> could envision having a single endpoint for CRUD operations in your
>> JCR repository to work based on the media type being requested. WDYT ?
>
> Hi Luciano,
>
> I must admit that I don't know as much of jcr and sling as I know
> about clerezza. Not sure if I understand you correctly, but the
> jcr:type of resource (which can be an arbitrary string) seems
> orthogonal to the media type: on one hand we have the selection of the
> root-resource on the other the production of an appropriate
> representation.
>
> Sling has a mechanism that has shown to work well that associates code
> handling the request to a specific URI, without changing this
> mechanism I'd like support for jax-rs root resource like classes
> ("like" because the @Path-Annotation are missing or ignored) as an
> alternative to servlets or scripts. I think Wink should not directly
> support other ways to bind resource-classes to URI than @Path, but it
> should provide an easy way for frameworks integrating wink (like sling
> or clerezza) to support other mechanisms.
>
> To avoid osgi-dependencies in wink-server I suggest providing an
> wink-osgi-service bundle that provides a service with the following
> methods
>
> //handles a request using previously bound root resources
> void handleRequest(HttpServletRequest request, HttpServletResponse response)
>
> //that's the method that allows easy integration with Sling or Clerezza
> void handleRequest(HttpServletRequest request, HttpServletResponse
> response, Object rootResource)
>
> //bind root resource or provider, binding classes seems against OSGi
> architecture
> void bindComponent(Object component)
>
> void unbindComponent(Object component)
>
> //framework supporting other request processing mechanism can use this
> method to check if Wink can handle a request (with the currently bound
> root resources)
> boolean hasRootResourceForUriPath(String uriPath)
>
> Do you think a new module providing such a bundle and service would
> fit into Wink? If so I'll open an issue and attach a patch to it. It
> can be implemented without modifying other code, even though in future
> the existing RequestProcessor might be adapted for a more seamless
> integration.

Is this new module have any Sling or Clerezza dependencies ?


-- 
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/

Re: Wink OSGI service

Posted by Reto Bachmann-Gmür <re...@apache.org>.
On Fri, Sep 2, 2011 at 6:22 PM, Luciano Resende <lu...@gmail.com> wrote:
...
>> The second requirements might need a bit more explanation. In sling
>> servlets are typically bound to a type of JCR-resources even though
>> this goes beyond the jax-rs spec it would be nice to bind jax-rs style
>> classes to such a JCR-resource type, the patch I attached to
>> SLING-2192 allows this, see my blog post [2] for an example usage.
>> Similarly in Clerezza jax-rs style resource can be bound to an
>> RDF-Type [3].
>>
>
> As for your second example, maybe a simple way would be to have
> JCR-resource types defined as specific media types, in this way, you
> could envision having a single endpoint for CRUD operations in your
> JCR repository to work based on the media type being requested. WDYT ?

Hi Luciano,

I must admit that I don't know as much of jcr and sling as I know
about clerezza. Not sure if I understand you correctly, but the
jcr:type of resource (which can be an arbitrary string) seems
orthogonal to the media type: on one hand we have the selection of the
root-resource on the other the production of an appropriate
representation.

Sling has a mechanism that has shown to work well that associates code
handling the request to a specific URI, without changing this
mechanism I'd like support for jax-rs root resource like classes
("like" because the @Path-Annotation are missing or ignored) as an
alternative to servlets or scripts. I think Wink should not directly
support other ways to bind resource-classes to URI than @Path, but it
should provide an easy way for frameworks integrating wink (like sling
or clerezza) to support other mechanisms.

To avoid osgi-dependencies in wink-server I suggest providing an
wink-osgi-service bundle that provides a service with the following
methods

//handles a request using previously bound root resources
void handleRequest(HttpServletRequest request, HttpServletResponse response)

//that's the method that allows easy integration with Sling or Clerezza
void handleRequest(HttpServletRequest request, HttpServletResponse
response, Object rootResource)

//bind root resource or provider, binding classes seems against OSGi
architecture
void bindComponent(Object component)

void unbindComponent(Object component)

//framework supporting other request processing mechanism can use this
method to check if Wink can handle a request (with the currently bound
root resources)
boolean hasRootResourceForUriPath(String uriPath)

Do you think a new module providing such a bundle and service would
fit into Wink? If so I'll open an issue and attach a patch to it. It
can be implemented without modifying other code, even though in future
the existing RequestProcessor might be adapted for a more seamless
integration.

Cheers,
Reto

Re: Wink OSGI service

Posted by Luciano Resende <lu...@gmail.com>.
On Thu, Sep 1, 2011 at 12:54 PM, Reto Bachmann-Gmür <re...@apache.org> wrote:
> Hello
>
> I've recently wrote a wink-based patch to integrate jax-rs support in
> Sling [1]. In a very similar way Wink could be used in Clerezza where
> we're currently using our own jax-rs implementation.
>

+1, very good initiative.

> In both projects there are in my view the following requirement:
>
> 1. Possibility for jax-rs components (providers and resources) and/or
> applications to be registered and unregistered in an OSGi environment
> 2. Possibility to handle a request with a Jax-RS resource other than
> the one with matching @Path annotation
>
> The second requirements might need a bit more explanation. In sling
> servlets are typically bound to a type of JCR-resources even though
> this goes beyond the jax-rs spec it would be nice to bind jax-rs style
> classes to such a JCR-resource type, the patch I attached to
> SLING-2192 allows this, see my blog post [2] for an example usage.
> Similarly in Clerezza jax-rs style resource can be bound to an
> RDF-Type [3].
>

As for your second example, maybe a simple way would be to have
JCR-resource types defined as specific media types, in this way, you
could envision having a single endpoint for CRUD operations in your
JCR repository to work based on the media type being requested. WDYT ?

> It would be good to implement the basic support for these two
> requirements directly in wink. Roughly this would correspond to the
> org.apache.sling.jaxrs.wink package in the sling-patch. The following
> I think could be discussed and improved:
> - Unregistration of components cause the a new RequestProcessor to be created
> - Setting a root-resource shadowing the one that would be located
> using the path is done with a ThreadLocal variable, this might better
> be passed as property of the ServletRequest
>
> Before creating an issue and attaching a patch I though I ask here if
> this functionality would be welcomed in Wink.
>
> Cheers,
> Reto
>
> 1. https://issues.apache.org/jira/secure/attachment/12492153/SLING-2192-with-sling-style-style-registration.patch
> 2. https://farewellutopia.com/2011/08/23/Add-some-jax-rs-support-to-sling
> 3. For an example see:
> http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.scripting/src/main/java/org/apache/clerezza/platform/scripting/ScriptGeneratedResourceTypeHandler.java
>



-- 
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/

Wink OSGI service

Posted by Reto Bachmann-Gmür <re...@apache.org>.
Hello

I've recently wrote a wink-based patch to integrate jax-rs support in
Sling [1]. In a very similar way Wink could be used in Clerezza where
we're currently using our own jax-rs implementation.

In both projects there are in my view the following requirement:

1. Possibility for jax-rs components (providers and resources) and/or
applications to be registered and unregistered in an OSGi environment
2. Possibility to handle a request with a Jax-RS resource other than
the one with matching @Path annotation

The second requirements might need a bit more explanation. In sling
servlets are typically bound to a type of JCR-resources even though
this goes beyond the jax-rs spec it would be nice to bind jax-rs style
classes to such a JCR-resource type, the patch I attached to
SLING-2192 allows this, see my blog post [2] for an example usage.
Similarly in Clerezza jax-rs style resource can be bound to an
RDF-Type [3].

It would be good to implement the basic support for these two
requirements directly in wink. Roughly this would correspond to the
org.apache.sling.jaxrs.wink package in the sling-patch. The following
I think could be discussed and improved:
- Unregistration of components cause the a new RequestProcessor to be created
- Setting a root-resource shadowing the one that would be located
using the path is done with a ThreadLocal variable, this might better
be passed as property of the ServletRequest

Before creating an issue and attaching a patch I though I ask here if
this functionality would be welcomed in Wink.

Cheers,
Reto

1. https://issues.apache.org/jira/secure/attachment/12492153/SLING-2192-with-sling-style-style-registration.patch
2. https://farewellutopia.com/2011/08/23/Add-some-jax-rs-support-to-sling
3. For an example see:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.scripting/src/main/java/org/apache/clerezza/platform/scripting/ScriptGeneratedResourceTypeHandler.java