Unable to deploy SlingServlet in CQ

荒凉一梦 提交于 2019-11-28 14:01:16

You have got your properties wrong. Kindly refer to the sling docs to know what each property that you have set does.

The property sling.servlet.paths should be used instead of sling.servlet.resourceTypes to provide the path under which the servlet is accessible as a Resource.

Thus for your requirement, the following annotations would suffice.

sling.servlet.methods - For the request methods supported by the servlet.

sling.servlet.paths - For the request path that is handled by this servlet.

@Component(immediate = true, metatype = false, label = "feedServlet")
@Service(Servlet.class)
@Properties(value = {
    @org.apache.felix.scr.annotations.Property(name = "sling.servlet.methods", value = "POST"),
    @org.apache.felix.scr.annotations.Property(name = "sling.servlet.paths", value ="/bin/feedServlet"))
})
public class FeedServlet extends SlingAllMethodsServlet {

    private static final long serialVersionUID = -2139716879248038562L;

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException,
            IOException {

        String feed = "test test test";

        response.getWriter().write(feed);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!