Expand my Community achievements bar.

SOLVED

AEM Cloud sdk servlet issue

Avatar

Level 1

Hi All,

I have created the sling servlet in AMS Cloud Version SDK, For that i am facing servlet hit issue as it is in satisfied state and not getting into Active state.

I've checked following basic steps for servlet properly registered or not.
-Bundle is active.
-Servlet is registered i.e, i am able to see at system/console/components

I've seen some fixes for it as below but still the issue is not resolved
-I was trying to resolve the path at /system/console/servletresolver. Even /bin also not resolved.
-I was trying a bunch of different paths like /bin, /bin/test , /bin/groupServlet and those paths are already whitelisted at Apache Sling Servlet/Script Resolver and Error Handler.
-I have tried with resource base servlet and facing same issue not resolved error.
- tried with empty servlet as well with only sysout message post removing service reference.

Does anyone have any ideas or other things I can check for as to why this would not work?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

I tried with your servlet, It works for me.

I changed method from Post to Get, just for testing

https://github.com/arunpatidar02/aemaacs-aemlab/blob/feature/standard-and-dynamic-dropdown/core/src/...

 

Screenshot 2021-12-11 at 17.10.54.png

 



Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @merajsid 

 

Here is the way you can debug more:

  1. Can you please confirm if it is in satisfied or un satisfied state?
  2. As you have mentioned that you have tried registering with paths and resourcetypes then there should be some issue with the REFERENCES mentioned in the servlet which are not getting satisfied
  3. Check if you are calling the same method that is declared (like GET should be called if GET is declared in servlet, POST wont work)
  4. Also check if /bin path is allowed in the below configuration

Kiran_Vedantam_0-1639059770106.png

 

Hope this helps.

Thanks,

Kiran Vedantam.

Avatar

Community Advisor

Hi,

Could you please share the servlets skelton code?
Without seeing code, it is hard to tell what could be the potential issue. Most of the time it is related to code.



Arun Patidar

Avatar

Level 1

Hi Arun, 

Please see below code - we have removed logic part and trying with this blank servlet first. Also renamed project folder with "abc" rest other parts are same. Where "abc" is project folder and there is common folder using core components.

 

package com.ace.core.product.search.servlets;

import java.io.IOException;

import javax.servlet.Servlet;

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.SlingAllMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.propertytypes.ServiceDescription;


@component(service = { Servlet.class }, immediate = true)
@SlingServletResourceTypes(
resourceTypes="abc/components/page",
methods=HttpConstants.METHOD_POST,
selectors = "productSearch")
@ServiceDescription("Product Search Servlet")
public class ProductSearchServlet extends SlingAllMethodsServlet {

private static final long serialVersionUID = 1L;

@activate
public void activate(){
}

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
response.getWriter().println("Hello");
}

}

Avatar

Community Advisor

Hi @merajsid,

If "abc/components/page" is the resourceType of your site content page say, /content/abc/us/en (jcr:content of the page has the resourceType), then accessing like http://localhost:4502/content/abc/us/en/jcr:content.productSearch.html will execute the servlet doPost per your servlet registration. 

Vijayalakshmi_S_0-1639149617447.png

Avatar

Correct answer by
Community Advisor

Hi,

I tried with your servlet, It works for me.

I changed method from Post to Get, just for testing

https://github.com/arunpatidar02/aemaacs-aemlab/blob/feature/standard-and-dynamic-dropdown/core/src/...

 

Screenshot 2021-12-11 at 17.10.54.png

 



Arun Patidar