Friday 4 March 2016

Debugging AEM 6.1 internals


There are times when you get an ugly error log with NPE or other exceptions coming from the internal AEM APIs and you are clueless about what could be wrong.
Well if you happen to have the jar of the related feature you can easily decompile the jar and take a look at what exactly might be causing the error or debug it.

Starting AEM 6.1 Adobe only releases uber-jar in the public repositories which contains only the signatures and empty method bodies to protect their intellectual property.
This can be very limiting to a developer as you can't understand the failures, However there is a workaround to fetch the jar directly from the deflated AEM directory.

Steps to get the Jar:

  1. Identify the OSGI bundle which contains the class by using dependency finder http://localhost:4502/system/console/depfinder e.g. if the exceptions are pointing to com.day.cq.mailer.impl.CqMailingService drop the impl part and search for the package "com.day.cq.mailer" which will result in exported by com.day.cq.cq-mailer (297). So the bundle you are looking for is "297".
  2. Now Go to <Install directory>\crx-quickstart\launchpad\felix directory here you will find all the bundles present/installed in AEM. open the directory "bundle297\version0.0" your jar will be inside this directory.

Now you can use your favorite decompiler to take a look into the code or add the jar to your project dependency and debug the required piece of code.

References: http://labs.6dglobal.com/blog/2015-09-16/decompile-aem-jar