Hi,
We have a business requirement to host static webpages from AEM. Our AEM version is the latest AEM as a Cloud Service - 6.5.
for that i have created a sling servelt but when i am clicking on below url:
http://localhost:4502/content/dam/html-content/test.html (which i get when i click on html file , the url:
http://localhost:4502/assetdetails.html/content/dam/html-content/test.html ) the servelt code is unreachable it is not calling the servelt code Can someone help me ?
Below is my servelt code:
Solved! Go to Solution.
Views
Replies
Total Likes
@tatrived, Please make sure that the path which you are using to hit the servlet should be part of the allowed paths in "Apache Sling Servlet Configuration".
As per the best practices please try to create the servlets using resource types. Refer to this for more information about Servlet using resourceType vs path based https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-servlet-path-vs-reso...
As per your code, your servlet path is '/content/dam/html-content' with an extension of 'html'. But you are trying to call the servlet in the child resource. Can you please try hitting http://localhost:4502/content/dam/html-content.html and see if your servlet is getting invoked or not?
Hi sravs
Thanks for the reply but it seems it is still not working with this URL http://localhost:4502/content/dam/html-content.html
@tatrived, Please make sure that the path which you are using to hit the servlet should be part of the allowed paths in "Apache Sling Servlet Configuration".
As per the best practices please try to create the servlets using resource types. Refer to this for more information about Servlet using resourceType vs path based https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-servlet-path-vs-reso...
Your servlet is not correctly registered that's why you cannot invoke it. You cannot combine a servlet registered by path and try to use an extension. Please see this thread, which has some good examples of how to properly register a servlet: link.
If you want to host simple HTML files, you can just upload them into the DAM and make sure to adjust the "Content-Disposition" header through the OSGI config. You can take a look at these threads for more information:
https://experienceleague.adobe.com/docs/experience-manager-65/administering/security/content-disposi...
http://www.sgaemsolutions.com/2019/10/aempdf-is-getting-downloded-instead-of.html
Hope this helps.
below is my servelt but when i am using http://localhost:4502/content/dam/html-content/test.html this url it is not calling servelt i have added the path "/content/dam/html-content" in Apache Sling Servlet Configuration
I did try
1. Unchecked "Enable For All Resource Paths" option in the Apache Sling Content
Disposition Filter;
2. Removed the blacklisted "text/html" configuration and unchecked Allow unknown mime types from SafeBinaryGetServlet(DamContentDispositionFilter)
but nothing worked.
let me know if you have better solution
@tatrived can you try below code in a AEM instance and then update logic accordingly
package com.example.core.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.service.component.annotations.Component;
@Component(
service = {javax.servlet.Servlet.class},
property = {
"sling.servlet.methods=GET",
"sling.servlet.paths=/content/dam/html-content",
"sling.servlet.extensions=html",
"sling.servlet.selectors=test"
}
)
public class MyCustomServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
// Your servlet logic goes here
response.getWriter().write("Hello, this is MyCustomServlet for /content/dam/html-content/test.html!");
}
}
With these properties, the servlet will respond to GET requests with the URL pattern http://localhost:4502/content/dam/html-content/test.html
Wondering why you need a servlet for that?
you can simply create a rewrite rule at dispatcher (apache httpd) to server static html file from a desired dam location.
From the URLs seems you are trying to access "static" html files at author instance, right?
Do you want to edit those files at author instance?
Can you elobrate on the approach?
@tatrived Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes