Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Sling servlet txt extension not working with OSGi DS 1.2 annotations

Avatar

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
tims19814439
Level 1

02-01-2019

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 ?

Replies

Avatar

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile
Gaurav-Behl
MVP

02-01-2019

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

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

03-01-2019

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.

Avatar

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
tims19814439
Level 1

03-01-2019

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.

Avatar

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
tims19814439
Level 1

03-01-2019

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

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,111 likes

Total Posts

3,145 posts

Correct Reply

1,072 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

03-01-2019

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.

Avatar

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
tims19814439
Level 1

03-01-2019

thanks for the tip I will change the resource type to the short one

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

03-01-2019

Hi,

You can use pattern instead

Servlet Filter for PDF

Avatar

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
tims19814439
Level 1

Likes

0 likes

Total Posts

9 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
tims19814439
Level 1

03-01-2019

Thanks for your answer Arun Patidar​. At this point I don't really want to switch the whole interface to a sling filter so I will just map to .xml and rewrite from .txt to .xml in apache.

Thanks for your help everyone!

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

03-01-2019

Ohh ok, sorry I misread , I thought you are using filter.