Saturday, 8 August 2015

Registering a Servlet for every Page in AEM

UseCase: – I had a situation in which needed to return custom information corresponding to every page in AEM and also use it via component to display to end user .
-Then i have to invoke a Servlet on every page and with the use of selector want to return some information in JSON Format which can be used to display via Component on a Page to end user .
Solution : -For such situations we use the resourceType as cq/Page for registering Servlet , so that Servlet is registered for every Page.
– Then with the use of a particular selector we can get results like list information/required custom information for every AEM page and display either via component with its ajax request has a url of Current Page.Selector which invokes the Servlet and renders result .
Note: – Just for reference Sling resolves on basis of Primary Type example cq:Page for Page and dam:Asset for Dam in case sling:resourceType is missing .
Code Snippet :
@Component(name = "Site-Results", metatype = false
           configurationFactory = false,
           policy = ConfigurationPolicy.OPTIONAL)
    @Property(name = "sling.servlet.resourceTypes"
              value = ["cq/Page"]),
    @Property(name = "sling.servlet.selectors", value = "results"),
    @Property(name = "sling.servlet.extensions", value = ["json"]),
    @Property(name = "sling.servlet.methods", value = "GET"),
    @Property(name = "sling.servlet.description"
              value = "Gives Results for Every Page")

class ResultsServlet extends SlingSafeMethodsServlet {
    protected void doGet(SlingHttpServletRequest request, 
                         SlingHttpServletResponse response) {
     //Implement Your Logic

Hope this helps !! 

Wednesday, 6 May 2015

Generating Thumbnails For Video Uploaded in DAM

Usecase: I needed to use thumbnail for Photo and Video uploaded in DAM Admin , For Photo Thumbnails were getting created , but  faced an Issue that no thumbnail was generated for Video uploaded  in DAM .

Snapshot depicting no thumbnail rendition created for Video Uploaded .

Solution: For generating thumbnails for Video , what i did was installing ffmpeg on the Server Hosting Machine (may be Local/Dev instance for testing ,  Production instance for release ) from  and adding the ffmpeg\bin directory to the PATH variable in Environment Variables Section.

Snapshot depicting thumbnail renditions created for Video Uploaded .
Note : By Default thumbnails of particular renditions are created via DAM Update Asset workflow which is triggered on uploading Asset in DAM and using this Workflow a new workflow can be created for creating thumbnail of other rendition sizes for Photo/Video.
So , CQ DAM relies on ffmpeg plugin for creating thumbnail renditions of uploaded video and we need to install it manually on our Server(CQ Instance) and follow steps as mentioned above .
Hope this  helps..!!

Saturday, 2 May 2015

How to Change Port number of running AEM/CQ5 Instance on the Fly !!

I want to share a new trick of changing Port number of running AEM instance on the fly without renaming port number in Jar file or changing port number in debug.bat file .

Run mode of AEM instance can be anything in this case whether author , publish , sample-content or any custom like prod . Only prerequisite is AEM instance up and running .

Kindly follow Important Note section at bottom also seriously after following below mentioned steps else instance may become corrupt. 

To achieve this , Following steps needs to be followed .

1.)  Open the Configurations tab in  Apache Felix Web Console or simply open  http://<host>:<port>/system/console/configMgr      For Example: http://localhost:4502/system/console/configMgr

2.)  Search for Apache Felix Jetty Based Http Service and Open it.
      Console appears like as mentioned in screen shot.

3. As pointed Arrow Suggests HTTP Port by default is 8080 , change this port number  to  example   6502 or 9502 as per your requirements.

4.  If you changed HTTP Port to example 6502. Open   http://localhost:6502  in new tab and your AEM instance will run in new Port number i.e . 6502 .

Important Note:
  1.) Before closing your AEM instance if you are working on new port number as defined in Jetty service,  kindly again open http://<host>:<port>/system/console/configMgr , where port is your new port number example 6502 , go again to Apache Felix Jetty Based Http Service and change port number in HTTP Port to Original Port number of your  instance defined in Jar or debug.bat file example 4502 in this case which was changed to 6502 , else after closing your AEM instance with new port number and again opening AEM instance , it becomes corrupt and inaccessible.
  2.) These  changes persists as long as your AEM instance is up and running . As soon as you close your instance , next time CQ/AEM will open in port number defined in Jar file or debug.bat file after following Point 1 in Note.