We want to build a single proxy servlet which will serve a number of different paths, such as
/api/register
/api/player/1234/
/api/player/12312/transactions
Basically, any and every path below /api/
Currently we are using this pattern, which only allows a single or list of fixed paths:
@SlingServletPaths(value="/bin/somepath")
private class MyServlet extends SlingAllMethodsServlet
Any suggestions on how to handle variable paths?
I found a potential solution here using a custom ResourceResolver, but it wont compile unfortunately (the annotations and imports etc are no longer available in AEM 6.5):
You cannot do this with Sling-Servlets. BUT you could have an OSGi Whiteboard-Pattern Servlet next to the Sling MainServlet. The simplest for your case is to use the same context-name as Sling (because Sling registered already the entire URL-space)
For details refer to: https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html
I also like to use a proxy servlets for some external services (e.g. Solr, Commerce-System, ...). For development it is much simpler, than setting up extra infrastructure on every developer machine.
BUT:
PS: scope=PROTOTYPE is important for the HttpWhiteboard service.
Here is a working ServletFilter, what you asked for (for more information refer to https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html):