I have cq dialog field mapped to a servlet using resourceType to populate data source.
How can I get component resource object in aem servlet. request.getResource() returning the dialog field resource. I would like to get the component resource of dialog field, so I could use it to get component policy values.
String pagePath = request.getRequestURI();
Resource pageRes = request.getResourceResolver().resolve(pagePath);
//Once we get page resource find the desired resource node below that with resourcetype needed
For datasource there are examples of using Model classes too In the datasource node we point the sling:resourceType property to a sighly html file that does a <sly data-sly-use.model="com.myproject.MyModel"> The MyModel class will contain the logic needed I think I have seen similar implementation by @Arun_Patidar unable to find the example using Model class. But this https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DatasourceJson.java seems to be using a servlet.
If its resource based servlet then you can access component policy configuration by passing current resource to getPolicy(). in below example component policy configuration has title field & same configured value is retrieved using ContentPolicyManager.