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 fixed path:
@Slf4j
@Component(service = { Servlet.class })
@SlingServletPaths(value="/bin/somepath")
private class MyServlet extends SlingAllMethodsServlet
Any suggestions on how to do this?
We are using AEM cloud, so try to avoid anything which would require CRXDE
I found a potential solution here, but it wont compile unfortunately (the annotations etc are no longer available):
https://stackoverflow.com/a/41990177/1072187
Views
Replies
Total Likes
you can put comma separated path (make sure, its absolute path) there as it process as string array.
Thanks for the reply, but there are random IDs in the URLs, so its not possible to list them all out.
@TB3dock we cannot register a servlet using pattern. It accepts String or Array of Strings or Vector of Strings.
you can refer to this documentation https://sling.apache.org/documentation/the-sling-engine/servlets.html#servlet-registration
If you want multiple paths to be registered try to make use of selectors and extensions while registering servlet.
Hope this helps,
Krishna
In Sling servlets cannot accept the patterns. It is not similar to Spring boot APIs, Here we need to have single or multiple paths and utilize the selectors and suffixes
Please find the official documentation on sling and the properties that can be used while registering servlet.
https://sling.apache.org/documentation/the-sling-engine/servlets.html
So it looks like AEM doesnt have a way to support a servlet which can handle URLs with IDs in them, a very common pattern for REST APIs. we cant change the API, its used from a 3rd party.
We can think of one workaround this limitation, by using apache rewrite rules to take the api we need to honour, and rewriting it with a dummy extension.
So /api/3435534/player becomes /api/3435534/player.apihack, then we can create a servlet which uses .apihack as an extension.
There doesn't seem to be an annotation for this:
@SlingServletSelectors("apihack") nor
@SlingServletExtensions("apihack")
seem to exist?
As already mentioned, Sling Servlets are mounted to a single path, and even that does not fit into the "resource first" approach of Sling.
But you can register your servlet to /api and then read the remaining "parameters" via suffixes. Check the documentation at https://sling.apache.org/documentation/the-sling-engine/url-decomposition.html
Thanks Jorg. "you can register your servlet to /api"
are you saying we can use
@SlingServletPaths(value="/api")
And this will match /api/123/something/345345 ? I.e. its actually matching "/api.*"?
If so, problem solved!
I dont need selectors, I just need to take the entire URL and pass it on as a proxy, using filters to modify the request/response as needed.
Thinking of using a semaphore to limit number of active requests in case of DDoS. Usually, we would use a proper WAF like DataDome, but unfortunately AEM cloud does not allow this to be used.
Yes, in that case it is sufficient.
Regarding WAF: You can use Data Dome as bring-your-own-cdn solution, see https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/conten...
Hmm, this doesnt seem to work.
MyProxy.java
(service = {Servlet.class})
@SlingServletPaths(value = "/bin/myProxy")
public class MyProxy extends SlingAllMethodsServlet {
filters.any
/0200 { /type "allow" /url "/bin/myProxy/*"}
URL
GET http://localhost:4503/bin/myProxy/core/connect/tokenvalidation?token=xx
response:
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies