0

I just created a Sling servlet through maven.packaging as - "bundle", then I installed it inside system console of CQ5.

My bundle shows me Active state and all the required packages ..exported successfully.

but I when I call this bundle to use the servlet... nothing happened. It doesn't give me response. Is there a better way..to create a sling servlet and create a OSGI bundle,so that I can install it as a bundle in CQ5 to call the servlet from the component.

vedmtripathi
  • 11
  • 2
  • 6

2 Answers2

0

You can create SlingSerlvet like this.

@SlingServlet(
        paths={"/services/myapp/LoginController/validateUser","/services/myapp/LoginController/logout"})
        @Properties({
            @Property(name="service.pid", value="com.xxx.xxx.controller.LoginController",propertyPrivate=false),
            @Property(name="service.description",value="Validates the user", propertyPrivate=false),
            @Property(name="service.vendor",value="xxx Tech", propertyPrivate=false)
        })

        public class LoginController extends SlingAllMethodsServlet{


    private static final long serialVersionUID = 1L;

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



    }

    @Override
    protected void doGet(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServletException,
            IOException {




    }
}

To Call this servlet in browser just type the URLS "/services/myapp/LoginController/validateUser" And "/services/myapp/LoginController/logout" As you may already know that a serlvet can have multiple URLS.

This is a working piece of Code. Make sure that your URL Mappings i.e paths(in Sling/CQ5) starts with /services

also you can also create bundle using a dedicated Eclipse for CQ5 CRXDE Eclipse instead of Maven bundle. It's much easier to use but it is a bit slow. Download Here

Oliver
  • 6,152
  • 2
  • 42
  • 75
  • thanks Oliver. It partially works for me,but still getting problem while calling the servlet.but I got a very nice tut that works 100% and is similar to your steps. and thanks again for the support :) – vedmtripathi Oct 24 '14 at 09:54
0

Bingo.. finally I am able to call a sling sevlet bundled as OSGI bundle and deployed in CQ's system console. later I called this OSGI bundle fire a post request and this time able to get the response. here is a very nice and very explanatory tutorial from Scott that explain every and each steps of my problem.

http://scottsdigitalcommunity.blogspot.in/2013/06/posting-form-data-to-adobe-cq-using.html

and the sample code or sample application link can be found from here -

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

follow the above link step by step and you end up with the victory. I followed each steps and successfully called OSGI bundle's servlet through component inside CRXDE. and finally not to forget to thanks Scott.... thanks Scott for the explanation !!!

vedmtripathi
  • 11
  • 2
  • 6