3 changed files with 53 additions and 5 deletions
@ -0,0 +1,49 @@
|
||||
|
||||
package com.mcaps.core.servlets; |
||||
|
||||
import com.day.cq.commons.jcr.JcrConstants; |
||||
|
||||
import org.apache.commons.io.IOUtils; |
||||
import org.apache.sling.api.SlingHttpServletRequest; |
||||
import org.apache.sling.api.SlingHttpServletResponse; |
||||
import org.apache.sling.api.resource.Resource; |
||||
import org.apache.sling.api.servlets.HttpConstants; |
||||
import org.apache.sling.api.servlets.SlingAllMethodsServlet; |
||||
import org.apache.sling.api.servlets.SlingSafeMethodsServlet; |
||||
import org.apache.sling.servlets.annotations.SlingServletResourceTypes; |
||||
import org.osgi.service.component.annotations.Component; |
||||
import org.osgi.service.component.propertytypes.ServiceDescription; |
||||
|
||||
import javax.servlet.Servlet; |
||||
import javax.servlet.ServletException; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
|
||||
/** |
||||
* Servlet that writes some sample content into the response. It is mounted for |
||||
* all resources of a specific Sling resource type. The |
||||
* {@link SlingSafeMethodsServlet} shall be used for HTTP methods that are |
||||
* idempotent. For write operations use the {@link SlingAllMethodsServlet}. |
||||
*/ |
||||
@Component(service = { Servlet.class },property = { |
||||
"sling.servlet.paths=/content/dam/ms-mcaps" , |
||||
"sling.servlet.methods=GET", |
||||
"sling.servlet.extensions=html" |
||||
}) |
||||
|
||||
public class HtmlServlet extends SlingSafeMethodsServlet { |
||||
@Override |
||||
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { |
||||
// Get the path of the requested HTML file
|
||||
String path = request.getRequestPathInfo().getResourcePath(); |
||||
|
||||
// Read the content of the HTML file from DAM
|
||||
InputStream htmlStream = request.getResource().adaptTo(InputStream.class); |
||||
|
||||
// Set the content type
|
||||
response.setContentType("text/html"); |
||||
|
||||
// Copy the content to the response
|
||||
IOUtils.copy(htmlStream, response.getOutputStream()); |
||||
} |
||||
} |
Loading…
Reference in new issue