i trying access following sling servlet using http://localhost:4502/sling/test-services/planet.html
but, giving 404 error, not sure doing wrong here.
@component @service(value=javax.servlet.servlet.class) @properties({ @property(name="service.description", value="html renderer planet resources"), @property(name="service.vendor", value="the apache software foundation"), @property(name="sling.servlet.resourcetypes", value="sling/test-services/planet"), @property(name="sling.servlet.extensions", value="html"), @property(name="sling.servlet.methods", value="get") }) @suppresswarnings("serial") public class planetresourcerenderingservlet extends slingsafemethodsservlet { @override protected void doget(slinghttpservletrequest request, slinghttpservletresponse response) throws servletexception, ioexception { response.setcontenttype("text/html"); response.setcharacterencoding("utf-8"); final valuemap properties = request.getresource().adaptto(valuemap.class); // todo should escape output - enough our tests final printwriter pw = response.getwriter(); pw.println(string.format("<html><head><title>planet @ %s</title></head><body>", request.getresource().getpath())); pw.println(string.format("<p>name: %s</p>", properties.get("name"))); pw.println(string.format("<p>distance: %s</p>", properties.get("distance"))); pw.println("</body></html>"); pw.flush(); } }
is possible, access servlet service without ".html" extension, if remove extension property?
i appreciate help.
thank you!
when want access servlet through url need set sling.servlet.paths
instead of sling.servlet.resourcetypes
. similar issue has been answered here.
if setting sling.servlet.resourcetypes
property, need access resource sling:resourcetype
sling/test-services/planet
.
your annotations should
@component @service(value=javax.servlet.servlet.class) @properties({ @property(name="service.description", value="html renderer planet resources"), @property(name="service.vendor", value="the apache software foundation"), @property(name="sling.servlet.paths", value="/sling/test-services/planet"), @property(name="sling.servlet.extensions", value="html"), @property(name="sling.servlet.methods", value="get") })
or can further simplified using @slingservlet
annotation shown below
@slingservlet(paths="/sling/test-services/planet", methods="get", extensions="html")
make sure allow following path allowed in apache sling servlet/script resolver , error handler
configuration available in osgi console.
Comments
Post a Comment