How can I set sling.servlet.resourceTypes in Sling serlvet to a path relative to itself (to the serlvet resource)?

If I asked the question incorrectly, I will first tell you what I want to achieve:

I have the following component structure in CQ5: / apps / TEST / components / DatabaseConnection (DatabaseConnection is the component name) / apps / TEST / components / DatabaseConnection / src / ServletDatabaseConnection (This is my serlvet for handling POST requests from TEST / components / DatabaseConnection ...

In my servlet sling.servlet.resourceTypes is set to TEST / components / DatabaseConnection)

So I have set the relative path to sling.servlet.resourceTypes and serlvet will look for resourceType in / apps / TEST / components / DatabaseConnection and under / libs / TEST / components / DatabaseConnection /

But I want my DatabaseConnection component to move to any other folder and not change anything in either the servlet or the application. But if i do it now i have to change sling.servlet.resourceTypes to new resourceType

Whereas everything in Sling is a resource than my servlet is a resource too, right? So, perhaps one could set sling.servlet.resourceTypes relative to the servlet's resourceType?

So, can I set sling.servlet.resourceTypes relative to this servlet resource type? If not, are there other ways to make my component "nimble" so that I don't have to change anything in the servlet?

I found these two resources very useful: http://www.pro-vision.de/content/medialib/pro-vision/production/adaptto/2012/adaptto2012-apache-sling-basic-concepts-rainer-bartl-peter- manne / _jcr_content / renditions / rendition.file / adaptto2012-apache-sling-basic-concepts-rainer-bartl-peter-mannel.pdf http://sling.apache.org/site/resources.html But I still can't find a solution

+3


source to share


2 answers


It took 7 months and I found out how to achieve what I was trying to achieve by looking at my colleague's code :)

So, I wanted to make the component movable along with my servlet.

We don't need to use resourceType for this, but we need to use sling.servlet.paths. http://sling.apache.org/documentation/the-sling-engine/servlets.html

To do this, we need to do three things.

1) In the form we want to send to the servlet, set some action. Example:



<form name="name" id="id" action="/someaction/dothis" method="POST">
<button name="submit"> Submit </button>
</form>

      

2) Install sling.servlet.paths in the servlet. In our case:

@Component(immediate = true)
@Service(value=javax.servlet.Servlet.class)
@Properties(value = {
@Property(name="sling.servlet.methods", value={ "POST" }),
//
@Property(name="sling.servlet.paths", value={"/someaction/dothis"})
})
public class ServletEvaluation extends SlingAllMethodsServlet {
...
}

      

3) In the OSGi / system / console / configMgr console, configure the Apache Sling servlet / resource receiver: Add sling.servlet.path to the execution path. In our case, set the execution path to / someaction

+1


source


Have you tried setting the absolute path instead of the resourceType? For example, if you set the path to / bin / TEST / DatabaseConnection, it doesn't matter what the resource type is.



0


source







All Articles