Discussion:
Sling Servlet using OSGI R6 annotations
Júnior
2016-11-28 11:19:13 UTC
Permalink
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*
Steven Walters
2016-11-28 12:14:52 UTC
Permalink
Post by Júnior
Hi,
I'm trying to register a servlet using the OSGI r6 annotations but It is
not working.
R6
*property = { *
* "sling.servlet.methods=GET",*
* "sling.servlet.paths=/system/mypath1",*
* "sling.servlet.paths=/system/mypath2",*
* },*
*immediate=true*
*)*
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.
Júnior
2016-11-28 12:17:19 UTC
Permalink
Hi Steven,

I am using this version:

<version>3.0.1</version>

Thanks
Post by Steven Walters
Post by Júnior
Hi,
I'm trying to register a servlet using the OSGI r6 annotations but It is
not working.
R6
*property = { *
* "sling.servlet.methods=GET",*
* "sling.servlet.paths=/system/mypath1",*
* "sling.servlet.paths=/system/mypath2",*
* },*
*immediate=true*
*)*
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*
Jörg Hoh
2016-11-28 12:30:20 UTC
Permalink
Hi,

please add the "@Service" annotation as well.

Jörg
Post by Júnior
Hi Steven,
<version>3.0.1</version>
Thanks
Post by Steven Walters
Post by Júnior
Hi,
I'm trying to register a servlet using the OSGI r6 annotations but It
is
Post by Steven Walters
Post by Júnior
not working.
R6
*property = { *
* "sling.servlet.methods=GET",*
* "sling.servlet.paths=/system/mypath1",*
* "sling.servlet.paths=/system/mypath2",*
* },*
*immediate=true*
*)*
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
Steven Walters
2016-11-28 12:36:25 UTC
Permalink
Hi,
@Service does not exist in the R6 annotations, instead, it's the
service attribute on @Component....
(which was specified in the pasted code)
Post by Júnior
Hi Steven,
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...
Stefan Seifert
2016-11-28 12:41:02 UTC
Permalink
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-----
Sent: Monday, November 28, 2016 12:19 PM
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.
R6
*property = { *
* "sling.servlet.methods=GET",*
* "sling.servlet.paths=/system/mypath1",*
* "sling.servlet.paths=/system/mypath2",*
* },*
*immediate=true*
*)*
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 Ass
Steven Walters
2016-11-28 13:19:35 UTC
Permalink
Post by Júnior
R6
*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
Júnior
2016-11-28 16:09:25 UTC
Permalink
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 :)
Post by Steven Walters
Post by Júnior
R6
*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*
Loading...