Expand my Community achievements bar.

SOLVED

Sling Servlet Resolver has issue with Post method

Avatar

Level 1

[img]PostMethod.png[/img]

Hi , I have written a custom servlet which  extend SlingAllMethodsServlet. Post request did not resolve by CQ5 server , as we can see in attached  image.

My code in servelet class .   I am using CQ5.6.1 .

@SlingServlet(
        resourceTypes = {"sling/servlet/default"},
        methods =  {"GET", "POST"},
        selectors = {"UserQueryHandlerServlet"},
        extensions = {"json"}
    )

public class UserQueryHandlerServlet extends SlingAllMethodsServlet {

    @Override
    protected void doGet(SlingHttpServletRequest request,SlingHttpServletResponse response) throws ServletException,
            IOException {
        
            String responseString = processRequest(request,response);
            response.getWriter().write(responseString);
    }

        
       
    @Override
    protected void doPost(SlingHttpServletRequest request,SlingHttpServletResponse response) throws IOException {
        String responseString = processRequest(request,response);
        response.getWriter().write(responseString);        
    }

}

  

For the doGet() I am getting my Servlet in  Adobe Experience Manager Web Console Sling Servlet Resolver  but for doPost() getting   --com.day.cq.commons.servlets.NonExistingDispatcherServlet (OptingServlet).

And I followed the below mention URL

1- http://sling.apache.org/documentation/the-sling-engine/servlets.html

2-http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

3-http://labs.sixdimensions.com/blog/dan-klco/2012-12-01/gotcha-sling-servlet-requires-name

4-http://blogs.adobe.com/aaa/tag/sling

 

Basically my issue doPost() method did not call. I am getting 500 error for doPost method.

I go through all above links. But my problem did not resolve. Please help me please.

 

  

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,
It looks like you missed something from link #3 there about having set name attributes etc for your servlet
which would lead to something in the lines of:

 

@SlingServlet( label = "User Query Handler Servlet", metatype = true, methods = { "POST", "GET" }, selectors = "UserQueryHandlerServlet", extensions = {"json"}, name="com.myco.UserQueryHandlerServlet") @Properties({ @Property(name = "service.vendor", value = "My Company"), @Property(name = "service.description", value = "Servlet testing user stuff") }) public class UserQueryHandlerServlet extends SlingAllMethodsServlet { }

/Johan

View solution in original post

4 Replies

Avatar

Correct answer by
Level 7

Hi,
It looks like you missed something from link #3 there about having set name attributes etc for your servlet
which would lead to something in the lines of:

 

@SlingServlet( label = "User Query Handler Servlet", metatype = true, methods = { "POST", "GET" }, selectors = "UserQueryHandlerServlet", extensions = {"json"}, name="com.myco.UserQueryHandlerServlet") @Properties({ @Property(name = "service.vendor", value = "My Company"), @Property(name = "service.description", value = "Servlet testing user stuff") }) public class UserQueryHandlerServlet extends SlingAllMethodsServlet { }

/Johan

Avatar

Level 1

Hi Ojjis,   Thanks for reply.  But my problem didn't resolve.  Still my facing same issue , doPost() didn't call in my servlet.

 this time i did ... 


@SlingServlet(
             label = "UserQueryHandlerServlet", 
             metatype = true,
             resourceTypes = {"sling/servlet/default"},
             methods =  {"GET", "POST"},
             selectors = {"UserQueryHandlerServlet"},
             extensions = {"json"},
             name="com.cq.pns.servlet.UserQueryHandlerServlet"
    )
@Properties({
    @Property(name = "service.vendor", value = "UserQueryPostForm"),
    @Property(name = "service.description", value = "Servlet testing Sling")
    })
public class UserQueryHandlerServlet extends SlingAllMethodsServlet {

   @Override

    protected void doPost(SlingHttpServletRequest request,SlingHttpServletResponse response) throws IOException {
        String responseString = processRequest(request,response);
        response.getWriter().write(responseString);        
    }

}

Avatar

Level 1

Hi Ojjis,

  This issue has been resolved. I just rename the Servlet name :) . I donot know what was the issue, but that has been resolved. 

Avatar

Level 7

Ah thats nice to hear, probably just something that was not updated correctly :)