You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Júnior <fj...@gmail.com> on 2016/11/28 11:19:13 UTC

Sling Servlet using OSGI R6 annotations

Hi,

I'm trying to register a servlet using the OSGI r6 annotations but It is
not working.

Follow the configurations I am using:

R6

*@Component(service=Servlet.class,*

*property = { *

*     "sling.servlet.methods=GET",*

*     "sling.servlet.paths=/system/mypath1",*

*     "sling.servlet.paths=/system/mypath2",*

*   },*

*immediate=true*

*)*


But When I use the @SlingServlet annotation it works:

*@SlingServlet(paths={"/system/mypath1", "/system/mypath2"},
methods={"GET"})*

Am I missing some configuration?

Does someone have an example of this kind of configuration?

Thanks
-- 
Francisco Ribeiro
*SCEA|SCJP|SCWCD|IBM Certified SOA Associate*

Re: Sling Servlet using OSGI R6 annotations

Posted by Steven Walters <ke...@gmail.com>.
On Mon, Nov 28, 2016 at 9:30 PM, Jörg Hoh <jh...@googlemail.com> wrote:
> Hi,
>
> please add the "@Service" annotation as well.

@Service does not exist in the R6 annotations, instead, it's the
service attribute on @Component....
(which was specified in the pasted code)

>
> 2016-11-28 13:17 GMT+01:00 Júnior <fj...@gmail.com>:
>
>> Hi Steven,
>>
>> I am using this version:
>>

That is sufficient I believe, though I've been using 3.2.0.
I've been using R6, though haven't gotten around to registering a
servlet with it yet, so I will go and see if I can make a small
example of this...

Re: Sling Servlet using OSGI R6 annotations

Posted by Jörg Hoh <jh...@googlemail.com>.
Hi,

please add the "@Service" annotation as well.

Jörg

2016-11-28 13:17 GMT+01:00 Júnior <fj...@gmail.com>:

> Hi Steven,
>
> I am using this version:
>
> <version>3.0.1</version>
>
> Thanks
>
> 2016-11-28 10:14 GMT-02:00 Steven Walters <ke...@gmail.com>:
>
> > On Mon, Nov 28, 2016 at 8:19 PM, Júnior <fj...@gmail.com> wrote:
> > > Hi,
> > >
> > > I'm trying to register a servlet using the OSGI r6 annotations but It
> is
> > > not working.
> > >
> > > Follow the configurations I am using:
> > >
> > > R6
> > >
> > > *@Component(service=Servlet.class,*
> > >
> > > *property = { *
> > >
> > > *     "sling.servlet.methods=GET",*
> > >
> > > *     "sling.servlet.paths=/system/mypath1",*
> > >
> > > *     "sling.servlet.paths=/system/mypath2",*
> > >
> > > *   },*
> > >
> > > *immediate=true*
> > >
> > > *)*
> > >
> > >
> > > But When I use the @SlingServlet annotation it works:
> > >
> > > *@SlingServlet(paths={"/system/mypath1", "/system/mypath2"},
> > > methods={"GET"})*
> > >
> > > Am I missing some configuration?
> > >
> > > Does someone have an example of this kind of configuration?
> >
> > Which version of maven-bundle-plugin (or bnd-maven-plugin) are you
> > using in your build?
> > If I recall correctly, the R6 annotations require the use of the 3.x
> > versions of either of the plugins to have the annotations be processed
> > appropriately.
> >
>
>
>
> --
> Francisco Ribeiro
> *SCEA|SCJP|SCWCD|IBM Certified SOA Associate*
>



-- 
Cheers,
Jörg Hoh,

http://cqdump.wordpress.com
Twitter: @joerghoh

Re: Sling Servlet using OSGI R6 annotations

Posted by Júnior <fj...@gmail.com>.
Hi Steven,

I am using this version:

<version>3.0.1</version>

Thanks

2016-11-28 10:14 GMT-02:00 Steven Walters <ke...@gmail.com>:

> On Mon, Nov 28, 2016 at 8:19 PM, Júnior <fj...@gmail.com> wrote:
> > Hi,
> >
> > I'm trying to register a servlet using the OSGI r6 annotations but It is
> > not working.
> >
> > Follow the configurations I am using:
> >
> > R6
> >
> > *@Component(service=Servlet.class,*
> >
> > *property = { *
> >
> > *     "sling.servlet.methods=GET",*
> >
> > *     "sling.servlet.paths=/system/mypath1",*
> >
> > *     "sling.servlet.paths=/system/mypath2",*
> >
> > *   },*
> >
> > *immediate=true*
> >
> > *)*
> >
> >
> > But When I use the @SlingServlet annotation it works:
> >
> > *@SlingServlet(paths={"/system/mypath1", "/system/mypath2"},
> > methods={"GET"})*
> >
> > Am I missing some configuration?
> >
> > Does someone have an example of this kind of configuration?
>
> Which version of maven-bundle-plugin (or bnd-maven-plugin) are you
> using in your build?
> If I recall correctly, the R6 annotations require the use of the 3.x
> versions of either of the plugins to have the annotations be processed
> appropriately.
>



-- 
Francisco Ribeiro
*SCEA|SCJP|SCWCD|IBM Certified SOA Associate*

Re: Sling Servlet using OSGI R6 annotations

Posted by Steven Walters <ke...@gmail.com>.
On Mon, Nov 28, 2016 at 8:19 PM, Júnior <fj...@gmail.com> wrote:
> Hi,
>
> I'm trying to register a servlet using the OSGI r6 annotations but It is
> not working.
>
> Follow the configurations I am using:
>
> R6
>
> *@Component(service=Servlet.class,*
>
> *property = { *
>
> *     "sling.servlet.methods=GET",*
>
> *     "sling.servlet.paths=/system/mypath1",*
>
> *     "sling.servlet.paths=/system/mypath2",*
>
> *   },*
>
> *immediate=true*
>
> *)*
>
>
> But When I use the @SlingServlet annotation it works:
>
> *@SlingServlet(paths={"/system/mypath1", "/system/mypath2"},
> methods={"GET"})*
>
> Am I missing some configuration?
>
> Does someone have an example of this kind of configuration?

Which version of maven-bundle-plugin (or bnd-maven-plugin) are you
using in your build?
If I recall correctly, the R6 annotations require the use of the 3.x
versions of either of the plugins to have the annotations be processed
appropriately.

Re: Sling Servlet using OSGI R6 annotations

Posted by Júnior <fj...@gmail.com>.
It worked:

I needed to add the configurations Stefan said and updated the maven-plugin
to use the version 3.2.0.

And after that, using the configurations Steven sent the servlet started
working.

Thanks for all your help :)

2016-11-28 11:19 GMT-02:00 Steven Walters <ke...@gmail.com>:

> >Follow the configurations I am using:
> >
> >R6
> >
> >*@Component(service=Servlet.class,*
> >
> >*property = { *
> >
> >*     "sling.servlet.methods=GET",*
> >
> >*     "sling.servlet.paths=/system/mypath1",*
> >
> >*     "sling.servlet.paths=/system/mypath2",*
> >
> >*   },*
> >
> >*immediate=true*
> >
> >*)*
> >
> >
> >Am I missing some configuration?
> >
> >Does someone have an example of this kind of configuration?
>
> Updating an example project I already had on using OSGi R6, I was able
> to pretty much get the code you pasted to work as is at [1], with pom
> at [2].
>
> You should also make sure that you have "SCR (Declarative Services)"
> (according to the felix webconsole this is "Apache Felix Declarative
> Services (org.apache.felix.scr)") of version 2.x active within your
> OSGi framework (I'm currently running with outdated 2.0.2), as this is
> also required for R6 support.
>
> when I first used R6, I did try with maven-bundle-plugin 3.0.1, but
> there were some issues with it around the use of
> @ObjectClassDefinition.
> This issue was was fixed later (due to an update of underlying bnd),
> so was worth upgrading to 3.2.0 for.
>
> [1] https://github.com/kemuri-9/samples/blob/master/ds-
> annotations/src/main/java/net/kemuri9/samples/dsannotations/
> impl/SimpleSlingServlet.java
> [2] https://github.com/kemuri-9/samples/blob/master/ds-annotations/pom.xml
>



-- 
Francisco Ribeiro
*SCEA|SCJP|SCWCD|IBM Certified SOA Associate*

Re: Sling Servlet using OSGI R6 annotations

Posted by Steven Walters <ke...@gmail.com>.
>Follow the configurations I am using:
>
>R6
>
>*@Component(service=Servlet.class,*
>
>*property = { *
>
>*     "sling.servlet.methods=GET",*
>
>*     "sling.servlet.paths=/system/mypath1",*
>
>*     "sling.servlet.paths=/system/mypath2",*
>
>*   },*
>
>*immediate=true*
>
>*)*
>
>
>Am I missing some configuration?
>
>Does someone have an example of this kind of configuration?

Updating an example project I already had on using OSGi R6, I was able
to pretty much get the code you pasted to work as is at [1], with pom
at [2].

You should also make sure that you have "SCR (Declarative Services)"
(according to the felix webconsole this is "Apache Felix Declarative
Services (org.apache.felix.scr)") of version 2.x active within your
OSGi framework (I'm currently running with outdated 2.0.2), as this is
also required for R6 support.

when I first used R6, I did try with maven-bundle-plugin 3.0.1, but
there were some issues with it around the use of
@ObjectClassDefinition.
This issue was was fixed later (due to an update of underlying bnd),
so was worth upgrading to 3.2.0 for.

[1] https://github.com/kemuri-9/samples/blob/master/ds-annotations/src/main/java/net/kemuri9/samples/dsannotations/impl/SimpleSlingServlet.java
[2] https://github.com/kemuri-9/samples/blob/master/ds-annotations/pom.xml

RE: Sling Servlet using OSGI R6 annotations

Posted by Stefan Seifert <ss...@pro-vision.de>.
please have a look of the SCR metadata for your servlet is generated and part of the JAR file. look for a file OSGI-INF\<server-class>.xml.

if it does not exist check your maven configuration of maven-bundle-plugin.
afaik bnd only generates the SCR metadata for OSGI annotations if the properties _dsannotations and _metatypeannotations are set. see [1] for an example.

additionaly check in the XML file if your array of paths is generated correctly - i'm not sure if it is correct to have two "sling.servlet.paths" property entries to achieve this.

stefan

[1] https://github.com/wcm-io/wcm-io-tooling/blob/develop/maven/aem-global-parent/pom.xml#L238


>-----Original Message-----
>From: Júnior [mailto:fjunior87@gmail.com]
>Sent: Monday, November 28, 2016 12:19 PM
>To: users@sling.apache.org
>Subject: Sling Servlet using OSGI R6 annotations
>
>Hi,
>
>I'm trying to register a servlet using the OSGI r6 annotations but It is
>not working.
>
>Follow the configurations I am using:
>
>R6
>
>*@Component(service=Servlet.class,*
>
>*property = { *
>
>*     "sling.servlet.methods=GET",*
>
>*     "sling.servlet.paths=/system/mypath1",*
>
>*     "sling.servlet.paths=/system/mypath2",*
>
>*   },*
>
>*immediate=true*
>
>*)*
>
>
>But When I use the @SlingServlet annotation it works:
>
>*@SlingServlet(paths={"/system/mypath1", "/system/mypath2"},
>methods={"GET"})*
>
>Am I missing some configuration?
>
>Does someone have an example of this kind of configuration?
>
>Thanks
>--
>Francisco Ribeiro
>*SCEA|SCJP|SCWCD|IBM Certified SOA Associate*