servlet only working on cloud author, not publish instance? | Community
Skip to main content
Level 8
May 10, 2021

servlet only working on cloud author, not publish instance?

  • May 10, 2021
  • 3 replies
  • 5812 views

We created a simple servlet with a fixed path of /bin/demo/querybuilder.

 

 

 

 

 

(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=Query Builder servlet", "sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.paths=" + "/bin/demo/querybuilder" }) public class SimonServlet extends SlingSafeMethodsServlet {

 

 

 

 

 

This works great on local sdk, and works hitting the cloud author instance.  However, when we hit the corresponding publish instance, we get:

 

 

 

 

 

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>404 Not Found</title> </head> <body> <h1>Not Found</h1> <p>The requested URL was not found on this server.</p> </body> </html>

 

 

 

 

 

Any ideas how we get them onto publish? Our content gets pushed onto the publish instance automatically.   A servlet which can't be published is of no use.

 

Update:

added the following line:

 

 

/005 { /type "allow" /url "/bin/myapi/*" }

 

 

to 

 

 

myapp.dispatcher.cloud/src/conf.dispatcher.d/filters/filters.any

 

 

and deployed to dev cloud instance.  This seems to work, EXCEPT its stripping all the request headers. even things like X-Correlation-Token. 

 

How to get AEM to not remove the request headers for serlvets?

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

3 replies

Asutosh_Jena_
Community Advisor
Community Advisor
May 10, 2021

Hi @tb3dock 

 

You are trying to access the end user URL which is behind the dispatcher and in dispatcher /bin/*

/bin/demo/querybuilder

the above path will be blocked.

 

You need to allow the above path in filter section in dispatcher config and it will allow you to access the servlet.

 

You can look for ams_publish_filters.any file in your code base under dispatcher folder.

 

# allow non-public content directories if this isn't a production environment by uncommenting the next few lines
# /005 { /type "allow" /url "/bin/*" } # allow bin path access

 

Thanks!

TB3dockAuthor
Level 8
May 10, 2021
Thanks for the helpful reply. Where is the dispatcher folder? We dont see it in ui.config for core?
Peter_Puzanovs
Community Advisor
Community Advisor
May 10, 2021

Hey TB3dock,

 

Are you sure, you have allowed your url in the AEM as a Cloud Dispatcher, so that you're not blocked there?

 

Regards,

Peter

TB3dockAuthor
Level 8
May 11, 2021

I have tried adding /005 { /type "allow" /url "/bin/myapi/*" } to myapp.dispatcher.cloud/src/conf.dispatcher.d/filters/filters.any and it does help, although now AEM is removing all the request headers, so is not working. Locally, it doesnt do this.

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 10, 2021

Hi @tb3dock ,

 

Steps given by @asutosh_jena_  should resolve your issue. Also, please consider using resource type based servlets, they are

 

1. More secure

2. You get ACLs with the resource node assigned

3. Avoids the headache of adding custom paths to dispatcher.

TB3dockAuthor
Level 8
May 11, 2021

resource types have some advantages, but they are much more complex to setup, and looking at the source code, devs wont know what path to use.  We have not found any end to end tutorials, and expect that trying to get these working first locally, then on the cloud instance, could also take days or weeks.