is it possible to register a servlet with SuperSlingResourceType? How?
Solved! Go to Solution.
Hi @AEMWizard,
Yes this is possible to register servlet for sling resource super type. There is dedicated property that have to be used sling.servlet.resourceSuperType. Please be aware that it requires sling.servlet.resourceTypes property as well.
More details you can find under Apache Sling documentation:
Here are also few code examples:
package com.mysite.core.servlets;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.osgi.service.component.annotations.Component;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
@Component(service = { Servlet.class })
@SlingServletResourceTypes(
resourceTypes = "base/resource/type",
resourceSuperType = "super/resource/type",
methods = HttpConstants.METHOD_GET,
extensions = "html",
selectors = "customSelector"
)
public class ResourceBaseServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
// place for your code
}
}
package com.mysite.core.servlets;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.ServletResolverConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.service.component.annotations.Component;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
@Component(service = Servlet.class, property = {
ServletResolverConstants.SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_GET,
ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES + "=base/resource/type",
ServletResolverConstants.SLING_SERVLET_RESOURCE_SUPER_TYPE + "=super/resource/type",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=html",
ServletResolverConstants.SLING_SERVLET_SELECTORS + "=customSelector"})
public class ResourceBaseServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
// place for your code
}
}
Hi @AEMWizard,
Yes this is possible to register servlet for sling resource super type. There is dedicated property that have to be used sling.servlet.resourceSuperType. Please be aware that it requires sling.servlet.resourceTypes property as well.
More details you can find under Apache Sling documentation:
Here are also few code examples:
package com.mysite.core.servlets;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.osgi.service.component.annotations.Component;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
@Component(service = { Servlet.class })
@SlingServletResourceTypes(
resourceTypes = "base/resource/type",
resourceSuperType = "super/resource/type",
methods = HttpConstants.METHOD_GET,
extensions = "html",
selectors = "customSelector"
)
public class ResourceBaseServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
// place for your code
}
}
package com.mysite.core.servlets;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.ServletResolverConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.service.component.annotations.Component;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
@Component(service = Servlet.class, property = {
ServletResolverConstants.SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_GET,
ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES + "=base/resource/type",
ServletResolverConstants.SLING_SERVLET_RESOURCE_SUPER_TYPE + "=super/resource/type",
ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=html",
ServletResolverConstants.SLING_SERVLET_SELECTORS + "=customSelector"})
public class ResourceBaseServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
// place for your code
}
}
Views
Likes
Replies