Sling servlet txt extension not working with OSGi DS 1.2 annotations | Community
Skip to main content
tims19814439
Level 2
Jan 2, 2019 3:56 PM UTC

Sling servlet txt extension not working with OSGi DS 1.2 annotations

I am trying to create a servlet to serve a robots.txt. The servlet to handle this request is mapped on the website page resource and looks like this:

When I visit the page like this "/content/website.robots.txt" I am presented with an 404 error and the get of the servlet is never called.

When I change "sling.servlet.extensions" to xml and visit "/content/website.robots.xml" the get gets called and the servlet works.

I am using AEM 6.2 with OSGI 6.0.0

Is it impossible to map to .txt as extension or am I doing something wrong ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

14 replies

joerghoh
Employee
Jan 3, 2019 9:55 AM UTC

It seems to me that you are using the Felix SCR annotations. In that case you need to add the

@Service()

annotation to the class definition as well (no additional parameters required). That should do the trick.

Translate
tims19814439
Level 2
Jan 3, 2019 12:06 PM UTC

I'm actually using the OSGI component annotation the felix annotations are not available in the 6.2 architype I'm using

Translate
joerghoh
Employee
Jan 3, 2019 12:15 PM UTC

Hm, correct... I wonder why I was thinking that you are using the SCR ones ... :-/

Can you post the the generated xmls in target/classes/OSGI-INF for this class?

And btw the resource type is just "webstie/components/structure/websitepage"; the resource type is normally never the full path to the component.

Translate
Gaurav-Behl
Level 10
Jan 3, 2019 5:29 AM UTC

Turn on 'Enable Plain Text' option on 'Apache Sling GET Servlet' in configMgr since you are using METHOD_GET and test if it works.

Translate
tims19814439
Level 2
Jan 3, 2019 12:05 PM UTC

This unfortunately just makes it possible for the default GET servlet to handle the request. However I would like my own servlet to handle the request.

Translate