Wednesday 10 December 2014

Default vaules with CQ5/AEM component

Attimes we come across a situation while creating Components in CQ/AEM, where we want a default value of some property to be set the moment component is dropped. This can be done via JCR API but there is an easy way that I will cover in this post.

Using cq:template node :



cq:template node

Simply create a node under component node with name "cq:template" of type "nt:unstructured". 


Now add any property on this node you want to set as default value on the component. Not only properties you can even add node under this node if you want to create a default node under the component node.


Component node hierarchy under /apps 

And Its done. Now every time you drop this component on any page, default values will be created under the component node as shown below :

Final node hierarchy under /content

Here is link to code repository for this component : https://github.com/ankit-gubrani/Codebrains/commit/eea7cc35ae9c736e7ac4d39b398a37f9e5939b88

Saturday 15 November 2014

Feed importer in Adobe CQ/AEM

AEM comes with a pre-installed feature to import feeds into CQ. Feed importer comes with capability to import RSS and Atom feeds.

Hey!! Wait before that you must be thinking, what is a feed?

Web feed is a way to provide users with updated content. Web feeds are commonly used for news updates as news are the most frequently updating data.

Feed importer is a service to fetch data from feeds or any external source of data on a periodic basis and save data fetched, in the form of CQ page.It polls the specified external data source in given interval.


Here are the steps how to create feed importer in CQ :


Firstly, create a page under which all the imported data will be saved in the form of CQ:Page. All the new pages that will be created under root page will have sling:resourceType property's value same as the root page.

Now once root page is created, create Feed importer :

Open http://<host>:<port>/etc/miscadmin and go to importers




And Open the Feed Importer page, it will open a page as shown 
below :



 Now click on the Add button and complete the dialog as shown below:



Here is link for Atom feeds of Codebrians blog :

http://codebrains.blogspot.com/feeds/posts/default

The moment OK is clicked a Polling configuration node is created, that will poll given feed URL and fetches new data back to CQ then creates pages under given hierarchy.

Here is the one of the auto-create page:























Here is the Link to Github repository of Codebrains to refer the code : 
https://github.com/ankit-gubrani/Codebrains

Wednesday 12 November 2014

Populate dropdown in CQ5 dialog using Servlet

Dropdowns in CQ5 are easy to create and use, all that needs to be done is create a node with name options and primaryType as cq:widgetcollections and sub-nodes with options.

But problems comes in when the dropdowns with dynamic data or options is to be created. So, in this blog you will see how to address the problem of populating dropdown dynamically.

Firstly, create a source from which data is to be fetched in our case we have registered a Servlet in OSGI at path "/bin/codebrains.json" which returns a JSON object as :

{"root":[{"text":"CodeBrains_Text_0","value":"CodeBrains_Value_0"},{"text":"CodeBrains_Text_1","value":"CodeBrains_Value_1"},{"text":"CodeBrains_Text_2","value":"CodeBrains_Value_2"},{"text":"CodeBrains_Text_3","value":"CodeBrains_Value_3"},{"text":"CodeBrains_Text_4","value":"CodeBrains_Value_4"}]}

Once your servlet is ready and it gives response in the desired format, now browse to Dropdown widget node and add properties that are shown below :









Add following properties on the node :
  • xtype (Required) : selection
  • type : select
  • options (Optional but required if data is to be fetched from servlet) : <path-of-the-servlet> [Value of this property should be path of servlet which will serve the JSON data to be populated in the combo-box]. In our case its value should be "/bin/codebrains.json" as it the path at which servlet is registered in OSGI. 
  • optionsRoot  (Optional):  [Name of the property that contains options array. Use "." or dot-annotation to get till the property that contains options array. ] In our case its value should be "root" as root property of JSON object contains the Array.
  • optionsTextField (Optional): [Name of the field for the options text. This property is used if options object does not contains Text property which is read by default.
  • optionsValueField (Optional) : [Name of the field for the options value. This property is used if options object does not contains Value property which is read by default. ] (Optional)
  • allowBlank  (Optional) : [This property should have boolean value and is used to make any field mandatory. If set false that widget becomes mandatory cannot be set blank. ]





























Here is the Link to Github repository of Codebrains to refer the code : 
https://github.com/ankit-gubrani/Codebrains

Sunday 9 November 2014

How to reduce file file size of a image using GIMP ?

Does bulky sized images eats up significant amount of space of your disk ? Or such big file size images becomes a barrier to share these images ?    

Here is the solution for you to reduce the file size of a image using GIMP. 

There are two ways by which size of a image can be controlled : 
  1. First by Scaling the image i.e resizing the image.
  2. Second Compressing an image i.e image compression means reducing the size of graphics file.

Resizing the Image(Solution 1) :


Open up the image you want to reduce size of. Then form Scale menu select Scale Image option to open Scale Image Dialog. Same dialog can be opened up by right clicking on the  image → image → Scale Image.


This will open the Scale Image dialog. In the width field of Scale Image dialog and hit tab height will be calculated automatically. Now this image is scaled and size of the image will be reduced on saving.  


Compressing The Image(Solution 2) :


This is a easier way to  reduce the image. All you need to do is, open any image in GIMP. Then go to file → Save As. This will open the Save image dialog

On clicking Save another dialog will  pop up that gives user an option to provide quality of the image. Higher the quality, bigger will be the size of the image.




Your comments and suggestions are welcome.


Wednesday 22 October 2014

AEM Multifield with different widgets

Multifield widget in AEM was introduced to allow authors to enter any number of values they want and multifield serves its purpose pretty well. But multifield widget out of the box provides only textbox to take input from author. And at times we are in a situation where we want multifield with different widget for eg pathfield or a textarea or datefield. 

In this article we will see how to create or use multifield with different widgets or Xtypes.


Default Multifield widget

Solution : 

Creating a multifield with custom xtype or widget is a two step process. 

Step 1 : Create a multifield widget i.e create a new widget with xtype multifield. But this will create multi-type with only text field for input as shown above. 

FieldConfig node














Step 2 : create another widget with name fieldConfig and add value of xtype property as whatever widget you want in multifield, in this example we have used pathField. 

 
Multifield with pathfield as xtype Multifield with Datefield as xtype


The values that are stored can be accessed the same ways we access in a values of default mutifield widget. 

For reference, here is the Link for the demo Multi-field component : 

https://github.com/ankit-gubrani/Codebrains/tree/master/content/src/main/content/jcr_root/apps/codebrains/components/content/multifieldDemo    

Monday 4 August 2014

AEM Project Setup using Maven

This article focuses on how to setup a AEM/CQ project using Maven and explaining the basic structure of AEM projects. 

Lets start with a brief about APACHE MAVEN :

Maven is a build automation tool that helps managing the builds of the projects and their dependencies (jar files required). It is based on the concept of POM (Project Object Model). There are numerous number of maven plugins available over the internet, each of which fulfills a different purpose.As we are here for AEM Project setup we won't cover anything more about maven here.

Now let us see the folder structure of a AEM Project which you get to see in CRXDE Lite :
  • /apps : Top level folder whatever you code will be stored in this folder.
  • /apps/[YOUR-APP-FOLDER] : Root folder of one out of many projects that you will be creating under apps folder.
  • /apps/[YOUR-APP-FOLDER]/components : Folder that contains all the components and their respective JSPs.
  • /apps/[YOUR-APP-FOLDER]/templates : Folder that contains all the templates that you will be creating, which points to respective page component.
  • /apps/[YOUR-APP-FOLDER]/install : Folder that contains bundle of your project.
  • /apps/[YOUR-APP-FOLDER]/config : Folder that stored configuration specific to this project.
  • /etc/design//[APP-DESIGN-PAGE] : Design page of your application that stores all clientlibs (JS and CSS) and other static resources as well.
  • /content/dam/[YOUR-APP-DAM-FOLDER] : Folder that contains all the assets of your site.
  • /content/[YOUR-SITE] :  Location where site is stored .

Before we move forward here are some pre-requisites that should be available on your machine (installed) for building AEM project using maven : 

  1. First and foremost would be Apache MAVEN .
  2. Adobe AEM/CQ running instance.
  3. Any IDE eg Eclipse , Idea, Netbeans etc(Here we are using Intellij Idea for this example)
Link of source code for the demo project created https://github.com/ankit-gubrani/Codebrains

Here are the steps to create AEM Project using maven :


Step 1 : Create maven project using Adobe's multimodule-content-package-archetype. Using Command prompt go to the directory where you want to create project and run following command :

mvn archetype:generate -DarchetypeRepository=http://repo.adobe.com/nexus/content/groups/public/ -DarchetypeGroupId=com.day.jcr.vault -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.2

after this maven will prompt and ask for some information(like groupid, arifactid,version etc), provide that infomation and your project will be created.This will create a multimodule maven project with 2 modules (Bundle and Content)

Step 2 : Verify the code if it works fine or not. You can check it by running command :

mvn clean install 

if it completes without any error that means project was made successfully.

Step 3 : Import the project in any IDE . Here in the example I am using IntelliJ Idea : 


Step 4 : Now that everything is set in place , import the project in CQ running instance by running command : 

mvn clean install -PautoInstallPackage 

but if you are running CQ on different port or if username and passowrd is changed used following cmmand :

mvn clean install -PautoInstallPackage -Dcrx.port=3502 -Dcrx.username=newuser -Dcrx.password=newpassword

This will install the project in CQ instance and you can see following folder structure iunder your project : 




  
And this is it we are done with creating a AEM project using maven build tool. 

Using this you will create a two module maven project. Those modules are :

  1. Content Module : This module contains all the code that will pe under apps/[YOUR-APP-PROJECT] or /etc/[DESIGN-PAGE] or /content/[ANY-PAGE] folder.
  2. Bundle Module : This module contains all the java files that will be wrapped up into a bundle and will be installed into Feilx.



Here is the source code for the demo project created https://github.com/ankit-gubrani/Codebrains


Your comments and suggestions are welcome.




Tuesday 22 July 2014

How to check whether a page is Published / Activated ?

Hi guys, at-times we come across a requirement in CQ5/AEM where we have to check if a page is published or not in Author mode programmatically . I encountered a similar situation where I had to show only those page which are published or activated. 

So, after searching the web I came across a Service that CQ/AEM provides out of the box "Replication Status (com.day.cq.replication.ReplicationStatus)". This service provides us a way to see if, resource with which it is associated is : activated or deactivated or delivered or status-queue or we can even find out last published time of the page or by whom was the particular page last published.The service can be adapted from the resource object : 

ReplicationStatus replicationStatus = resource.adaptTo(ReplicationStatus.class);

Here is the link for documentation of the ReplicationStatus Interface :

Wednesday 16 July 2014

NullPointerException while using currentDesign.getDoctype(currentStyle).toRequest(request)

All of us must have used currentDesign object (the current design object of the current page) to access the properties of design associated with the page. But once i came across a strange error while using  currentDesign object . When I tried to get currentDesign.getDoctype(currentStyle).toRequest(request);  I encountered an Null Pointer exception.
Here is the full error stack :

com.day.cq.wcm.core.impl.WCMDebugFilter Exception:  org.apache.sling.api.scripting.ScriptEvaluationException:
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:385)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:170)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:456)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:500)
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:183)
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:150)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:219)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:257)
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:297)
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:216)
at org.apache.sling.engine.impl.request.SlingRequestDispatcher.include(SlingRequestDispatcher.java:103)
at com.day.cq.wcm.core.impl.WCMComponentFilter$ForwardRequestDispatcher.include(WCMComponentFilter.java:381)
at org.apache.jsp.libs.foundation.components.primary.cq.Page.Page_jsp._jspService(Page_jsp.java:106)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:420)
at org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServletWrapperAdapter.java:59)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:233)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:85)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:453)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:358)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:170)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:456)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:500)
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:147)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:308)
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:141)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:257)
at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
at com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:106)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:296)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.ankit.utils.XSSFilter.doFilter(com.ankit.utils.XSSFilter.java:40)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.ankit.servlet.SSOFilter.doFilter(com.ankit.servlet.SSOFilter.java:80)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.ankit.servlet.PermissionFilter.doFilter(com.ankit.servlet.PermissionFilter.java:120)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:59)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:220)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.theme.impl.ThemeResolverFilter.doFilter(ThemeResolverFilter.java:76)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:117)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:89)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter.doFilter(BackgroundServletStarterFilter.java:135)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processRequest(SlingRequestProcessorImpl.java:153)
at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:206)
at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:96)
at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:79)
at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:117)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:179)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:238)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:48)
at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:39)
at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.day.j2ee.servletengine.ServletRuntimeEnvironment.service(ServletRuntimeEnvironment.java:250)
at com.day.j2ee.servletengine.RequestDispatcherImpl.doFilter(RequestDispatcherImpl.java:315)
at com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:334)
at com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:377)
at com.day.j2ee.servletengine.ServletHandlerImpl.process(ServletHandlerImpl.java:351)
at com.day.j2ee.servletengine.HttpListener$Worker.run(HttpListener.java:625)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.sling.api.SlingException:
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:563)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:499)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:451)
at org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServletWrapperAdapter.java:59)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:233)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:85)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:453)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:358)
... 99 more
Caused by: java.lang.NullPointerException
at org.apache.jsp.apps.ankit.components.page.commonPageLayout.commonPageLayout_jsp._jspService(commonPageLayout_jsp.java:148)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:420)

Solution :

After spending hours to figured out the problem and I found out that jcr:content node of my design page was missing (/etc/designs/myDesign/jcr:content node).As there was no jcr:conent node under myDesign page because of that currentDesign.getDoctype(currentStyle) was returning null and this was the main reason of the NullPointerExcpetion/NPE. So, the moment I added the jcr:content node under myDesign page, code came back to life again.

Your comments and suggestions are welcome.

Saturday 12 July 2014

Unable to start CQ instance. javax.jcr.RepositoryException while installing CQ

Couple of days back I was installing CQ5.5 back on my Linux machine. So, I started the instance from command line using command 
"java -XX:MaxPermSize=512m -Xmx1520m -XX:-UseSplitVerifier -jar cq5-author-8502.jar
and everything went fine. But when installation was completed and it came up with url in the browser that should have shown Login page instead it came with 503 ERROR : Service Unavailable. On investigating in the error logs i found the following error stack :

10.07.2014 22:02:31.526 *INFO* [FelixStartLevel] org.apache.jackrabbit.core.RepositoryImpl Shutting down repository...
10.07.2014 22:02:31.529 *INFO* [FelixStartLevel] org.apache.jackrabbit.core.RepositoryImpl Repository has been shutdown
10.07.2014 22:02:31.551 *ERROR* [FelixStartLevel] com.day.crx.sling.server [com.day.crx.sling.server.impl.jmx.ManagedRepository] The activate method has thrown an exception (javax.jcr.RepositoryException: Unable to register data store in cluster.) javax.jcr.RepositoryException: Unable to register data store in cluster.
at com.day.crx.core.data.ClusterDataStore.init(ClusterDataStore.java:183)
at com.day.crx.core.CRXRepositoryImpl.createClusterNode(CRXRepositoryImpl.java:999)
at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:294)
at com.day.crx.core.CRXRepositoryImpl.<init>(CRXRepositoryImpl.java:283)
at com.day.crx.core.CRXRepositoryImpl.create(CRXRepositoryImpl.java:258)
at com.day.crx.core.CRXRepositoryImpl.create(CRXRepositoryImpl.java:243)
at com.day.crx.sling.server.impl.jmx.ManagedRepository.activate(ManagedRepository.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:227)
at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:38)
at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:591)
at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:472)
at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:146)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createImplementationObject(ImmediateComponentManager.java:226)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createComponent(ImmediateComponentManager.java:118)
at org.apache.felix.scr.impl.manager.DelayedComponentManager.createRealComponent(DelayedComponentManager.java:95)
at org.apache.felix.scr.impl.manager.AbstractComponentManager$Registered.getService(AbstractComponentManager.java:1296)
at org.apache.felix.scr.impl.manager.DelayedComponentManager.getService(DelayedComponentManager.java:88)
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:310)
at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:221)
at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:292)
at org.apache.felix.framework.Felix.getService(Felix.java:3010)
at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:329)
at org.osgi.util.tracker.ServiceTracker.addingService(ServiceTracker.java:442)
at org.apache.aries.jmx.whiteboard.Activator$MBeanTracker.addingService(Activator.java:101)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:896)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:840)
at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:871)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:733)
at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:662)
at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:3765)
at org.apache.felix.framework.Felix.registerService(Felix.java:2877)
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:251)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:456)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerComponentService(AbstractComponentManager.java:508)
at org.apache.felix.scr.impl.manager.AbstractComponentManager$Unsatisfied.activate(AbstractComponentManager.java:1157)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:334)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:158)
at org.apache.felix.scr.impl.config.ImmediateComponentHolder.enableComponents(ImmediateComponentHolder.java:313)
at org.apache.felix.scr.impl.BundleComponentActivator.loadDescriptor(BundleComponentActivator.java:241)
at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:147)
at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:111)
at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:274)
at org.apache.felix.scr.impl.Activator.bundleChanged(Activator.java:192)
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:807)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:729)
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3754)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1780)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1156)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:266)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: AnkitGubrani: AnkitGubrani: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at com.day.crx.core.cluster.ClusterMaster$3.execute(ClusterMaster.java:385)
at com.day.crx.core.cluster.ClusterController.attempt(ClusterController.java:1385)
at com.day.crx.core.cluster.ClusterMaster.listen(ClusterMaster.java:383)
at com.day.crx.core.cluster.ClusterMaster.startListener(ClusterMaster.java:196)
at com.day.crx.core.cluster.ClusterController.startMasterListener(ClusterController.java:840)
at com.day.crx.core.cluster.ClusterController.start(ClusterController.java:684)
at com.day.crx.core.cluster.ClusterController.register(ClusterController.java:919)
at com.day.crx.core.data.ClusterDataStoreSkeleton.init(ClusterDataStoreSkeleton.java:94)
at com.day.crx.core.data.ClusterDataStore.init(ClusterDataStore.java:177)
... 56 more
Caused by: java.net.UnknownHostException: AnkitGubrani: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
... 72 more
10.07.2014 22:02:31.552 *ERROR* [FelixStartLevel] com.day.crx.sling.server [com.day.crx.sling.server.impl.jmx.ManagedRepository] Failed creating the component instance; see log for reason
10.07.2014 22:02:31.554 *ERROR* [FelixStartLevel] org.apache.aries.jmx.whiteboard.JmxWhiteboardSupport registerMBean: Cannot register MBean service null with MBean servers: Not an instanceof DynamicMBean or not MBean spec compliant standard MBean
10.07.2014 22:02:31.555 *INFO* [FelixStartLevel] com.day.crx.sling.server Service [com.day.crx.sling.server.impl.jmx.ManagedRepository,74] ServiceEvent REGISTERED
10.07.2014 22:02:31.554 *ERROR* [FelixDispatchQueue] com.day.crx.sling.server FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null.) org.osgi.framework.ServiceException: Service factory returned null.
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:343)
at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:221)
at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:292)
at org.apache.felix.framework.Felix.getService(Felix.java:3010)
at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:329)
at org.osgi.util.tracker.ServiceTracker.addingService(ServiceTracker.java:442)
at org.apache.aries.jmx.whiteboard.Activator$MBeanTracker.addingService(Activator.java:101)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:896)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:840)
at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:871)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:733)
at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:662)
at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:3765)
at org.apache.felix.framework.Felix.registerService(Felix.java:2877)
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:251)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:456)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerComponentService(AbstractComponentManager.java:508)
at org.apache.felix.scr.impl.manager.AbstractComponentManager$Unsatisfied.activate(AbstractComponentManager.java:1157)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:334)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:158)
at org.apache.felix.scr.impl.config.ImmediateComponentHolder.enableComponents(ImmediateComponentHolder.java:313)
at org.apache.felix.scr.impl.BundleComponentActivator.loadDescriptor(BundleComponentActivator.java:241)
at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:147)
at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:111)
at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:274)
at org.apache.felix.scr.impl.Activator.bundleChanged(Activator.java:192)
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:807)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:729)
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3754)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1780)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1156)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:266)
at java.lang.Thread.run(Thread.java:745)







Solution:

On investing I found that CQ was trying to resolve to a server named as AnkitGubrani which was the hostname of my machine (i.e name in /etc/hostname file). So adding this entry in the /etc/hosts file resolved the problem. Following entry resolved the problem :

127.0.0.1   localhost AnkitGubrani

After adding above line /etc/hosts file should be saved and apache2 service should be restarted. 

And if everything went fine following command should give name of the host : hostname -f

In my case it returned localhost after adding entry into /etc/hosts while earlier it returned AnkitGubrani: Name or service not known.

Your comments and suggestions are welcome.