Showing posts with label AEM. Show all posts
Showing posts with label AEM. Show all posts

List of deprecated Java packages in AEM 6.2


Here is a list of deprecated packages in AEM 6.2 that you should keep handy for your reference.
If you are not sure the new package/API you just Googled out is deprecated or not, then just
do a quick search here.

If it is there in the list , it shouldn't be there in your code!!



com.adobe.aem.formsndocuments.listeners
com.adobe.cq.creativecloud.cloudims
com.adobe.cq.creativecloud.filesync
com.adobe.cq.creativecloud.home
com.adobe.cq.dms.tagmanager
com.adobe.cq.mcm.silverpop
com.adobe.cq.social.blog
com.adobe.cq.social.blog.antispam
com.adobe.cq.social.blog.antispam.process
com.adobe.cq.social.blog.search
com.adobe.cq.social.blog.search.process
com.adobe.cq.social.blog.trackback
com.adobe.cq.social.blueprint.endpoints
com.adobe.cq.social.sc.lucene
com.adobe.cq.social.scoring.util
com.adobe.granite.ocs.api
com.adobe.granite.ocs.api.goals
com.adobe.granite.ocs.api.provider
com.adobe.livecycle.formsmanagement.api
com.adobe.livecycle.formsmanagement.exception
com.day.cq.activitystreams.api
com.day.cq.auth.pin
com.day.cq.dam.html
com.day.cq.jobs.core
com.day.cq.searchpromote.feed
com.day.cq.searchpromote.feed.api
com.day.crx.sc.api
com.day.crx.sc.osgi
com.day.crx.sc.qom
org.apache.aries.subsystem
org.apache.commons.imaging.formats.bmp.pixelparsers
org.apache.commons.imaging.formats.bmp.writers
org.apache.commons.imaging.formats.tga
org.apache.felix.prefs
org.apache.felix.scr
org.apache.jackrabbit.mk.api
org.apache.jackrabbit.oak.commons.mk
org.apache.jackrabbit.oak.kernel
org.apache.jackrabbit.oak.security.authentication.ldap
org.apache.sling.event
org.apache.sling.jcr.compiler
org.eclipse.equinox.region
org.joda.time.tz.data
org.joda.time.tz.data.Africa
org.joda.time.tz.data.America
org.joda.time.tz.data.America.Argentina
org.joda.time.tz.data.America.Indiana
org.joda.time.tz.data.America.Kentucky
org.joda.time.tz.data.America.North_Dakota
org.joda.time.tz.data.Antarctica
org.joda.time.tz.data.Asia
org.joda.time.tz.data.Atlantic
org.joda.time.tz.data.Australia
org.joda.time.tz.data.Etc
org.joda.time.tz.data.Europe
org.joda.time.tz.data.Indian
org.joda.time.tz.data.Pacific
org.osgi.service.prefs
org.osgi.service.repository
org.osgi.service.subsystem

Let me know about any issues. Suggestions are always welcome....


A solution for javax.jcr.lock.LockException

In one of my previous posts I showed how to connect to JCR using a simple
main() method , Java program
.
This is a simple program and should work fine in most of the cases.
But for some people it might throw a javax.jcr.lock.LockException.

Solution:

While connecting to the JCR we may use something like below.

 Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
This statement may sometimes lead to an error in applications like AEM.
To avoid this we need to mention the default environemnt we are logging into.

So we should USE THIS INSTEAD.

Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()),"crx.default");



I would be happy to hear back from you. Please leave your suggestions in the comment section below. Cheers!!



[FIX]:  javax.inject,version=[0.0,1) -- Cannot be resolved

The Scene:

So on a Saturday afernoon I was working on some AEM backend services and I came
across this issue which I have never faced before. It was something to do with the
javax.inject package that is used when we are using the @Inject annotations
in our classes.

The Problem:

So like a normal developer bloke I Googled around a bit and came to know that this was some
kind of dependency issue. But I was surprised that even though we can find the dependency using
depfinder --> http://localhost:4502/system/console/depfinder it was not resolved.


Finally the SOLUTION:

So I tried adding the javax.inject dependencies to my project POM file (i was using Maven)
and it WORKED!!!

    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-atinject_1.0_spec</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>


The Cause:

Though I am not quite sure about the cause for this issue but I believe
this is a problem persistent in AEM version 6.2 (AEM 6.2 javax.inject dependency problem)
as I have executed the same code in AEM 6.1 without issues.

Please let me know in the comments below if you have the reason or additional info.

System Bundles going to Installed State | AEM Bundles not Starting

Many a times while working with AEM we find various errors related to bundles.Bundles or JAR files forms the backbone of AEM. When these bundles goes o installed state they give rise to
issues like 403 forbidden errors, 500 internal server errors or sometimes errorsrelated and not
limited to ACS Commons or DAM.


Sometimes it is very dificult to find as to why AEM bundles are going to installed state.
The reason being that various operations can cause your bundles to go to installed state.


Adobe has given us a HOTFIX for this issue.
"AEM bundles going to installed sate" HOTFIX comes in the form of a small JAR file.
he AEM bundle hotfix comes in the form of org.eclipse.equinox.region jar file.

Ok enough TALKING... Gimme the SOLUTION Please..!!!!

Solution 1:

If you have tried other ways and just couldn't get it working and still see various AEM system
bundles in installed state then try to install this JAR into your Felix console /system/console/bundles.


JAR Download : https://drive.google.com/open?id=0B3gwHkSOERmZRlZNQzZUMEFoUzQ

This is a good fix which works most of the time. Also trying this solution will not hurt.You can
always delete the bundle if it didn't do the job.

NOTE:
AEM will refresh all the bundles. So please wait 5 minutes after installing the Equinox HOTFIX.


Solution 2:

For AEM version 6.1 only.

If the above method didn't resolve your problem then try to remove equinox related JAR file.
Look for a bundle with this name "Region Digraph(org.eclipse.equinox.region)"

Now remove this bundle. Also remove the bundle you installed in Solution 1 if necessary.
Long story short, there should not be any equinox jars installed.



Why this Happens?

According to Adobe the equinox eclipse bundle has some dependency with eclipse and should not be in AEM6.1, it was meant for AEM version 6.2. But this bundle got introduced in this version.

Other Version of Jar file:
1. http://www.java2s.com/Code/Jar/o/Downloadorgeclipseequinoxregion110v201205221841jar.htm



How to get the device type (User Agent) in AEM

Sometimes when developing multiple platform websites we need to know the device type the user is logged in from.

This can be easily achieved by using the HttpServletRequest from the component JSP.
This can be done using request object,the HttpServletRequest implicit object in JSP


request.getHeader("user-agent");


The HttpServletRequest.getHeader() methods returns the headers of the request.
 java.lang.StringgetHeader(java.lang.String name)
Returns the value of the specified request header as a String.

"user-agent" is the property which contains the type of device from which the request is made from.

From a component JSP this can be done using the following code.

<%@include file="/libs/foundation/global.jsp"%>
<%@page session="false" %>

<% 
    String deviceType=request.getHeader("user-agent");
 out.println(deviceType);
%>



OUTPUT for various devices:

Windows/Chrome:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36

Windows/IE v11.0
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

Android/Nexus 5X:
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36

Android/Galaxy S5:
Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36

IOS/Iphone 6:
Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1


How to convert a AEM Node into JSON representation


WE can easily convert an AEM node to its JSON representation by using the
org.apache.sling.commons.json.jcr.JsonItemWriter class.
This can be any type of Node like JCR node, AEM page, sling resource, cq:Page.. etc.

The simple code for doing this is


 StringWriter stringWriter = new StringWriter();
 JsonItemWriter jsonWriter = new JsonItemWriter(null);
 jsonWriter.dump(node, stringWriter, -1, true);
 String json = stringWriter.toString();



EXAMPLE:

1. Lets suppose we have the following node "/apps/geometrixx-gov/components/logo" that we need to convert to JSON.





2. Now we want to convert it into it's JSON representation.

3. Lets write a main method to do so.


package codermag.net;
import java.io.StringWriter;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.core.TransientRepository;
import org.apache.sling.commons.json.jcr.JsonItemWriter;

public class test {
 public static void main(String[] args) throws Exception {
  Repository repository = new TransientRepository();
  repository = JcrUtils.getRepository("http://localhost:4502/crx/server");
  Session session = repository.login(new SimpleCredentials("admin","admin".toCharArray()));

  // Getting a particular node
  Node root = session.getRootNode();
  Node subContent = root.getNode("apps/geometrixx-gov/components/logo");

  
  // Iterating over the nodes and printing their names
  StringWriter stringWriter = new StringWriter();
  JsonItemWriter jsonWriter = new JsonItemWriter(null);
  jsonWriter.dump(subContent, stringWriter, -1, true);
  String json = stringWriter.toString();
  
  
  
  System.out.println(json);
 }
}


NOTE:  To run the program download the Jack Rabbit Jar File form
http://www.apache.org/dyn/closer.cgi/jackrabbit/2.8.1/jackrabbit-standalone-2.8.1.jar and place it in your project build path.


5. This code will connect to the AEM JCR and get the node.Then it will convert it to JSON.

OUTPUT:


{
  "jcr:title": "Logo",
  "jcr:created": "Wed Aug 05 2015 07:33:54 GMT+0530",
  "jcr:createdBy": "admin",
  "jcr:primaryType": "cq:Component",
  "sling:resourceSuperType": "foundation/components/logo",
  "componentGroup": ".hidden",
  "logo.jsp": {
    "jcr:created": "Wed Aug 05 2015 07:33:54 GMT+0530",
    "jcr:createdBy": "admin",
    "jcr:primaryType": "nt:file",
    "jcr:content": {
      "jcr:lastModifiedBy": "admin",
      ":jcr:data": 2185,
      "jcr:lastModified": "Wed Aug 05 2015 07:33:54 GMT+0530",
      "jcr:primaryType": "nt:resource",
      "jcr:mimeType": "text/plain",
      "jcr:uuid": "b8261ccb-ecd4-4c01-bbe1-fb1371a8c910"
    }
  }
}




Please go through the JSON data and the screenshot of the LOGO Node to understand better.


AEM Project Structure in Eclipse

AEM Project Structure in Eclipse


We have learnt how to create the AEM project (Maven) structure using AEM archetype in our
previous post here.How to Build AEM project in Eclipse using AEM Archetype.

Now we will see how to use this structure to create AEM applications.

So we have a project structure as follows.
AEM Project Structure in Eclipse


The PARENT Project

The project selected is our parent project and have all the modules.
The main modules are:

1. The CORE Project.
2. The UI APPS Project.
3. The CONTENT Project
AEM Project Structure in Eclipse


The core project

1. This project will contain all the Java code for our application.It can be referred to the backend OSGI bundle for our application.

AEM Project Structure in Eclipse


2. You can make new packages inside src/main/java or delete/edit/modify the existing packages at your free will.

3. You can run a maven "clean install"build on the pom.xml.This will create a OSGI JAR.

AEM Project Structure in Eclipse


4. After the build is successful the OSGI jar can be found inside the target folder of the core project.

AEM Project Structure in Eclipse


5. Now you can upload this JAR seperately in AEM Felix console (/system/console/bundles) and your Java classes will be accessible from our AEM JSPs.



The AEM UI APPS Project

1. This project has the structure of AEM Apps folder.See image below for explanation.

AEM Project Structure in Eclipse


There is also the /etc folder which corresponds to the AEM /etc folder.



2. So this means the apps and etc folder is similar to the /apps and /etc folder in AEM respectively.
Your files should sync from this apps folder to AEM /apps folder to and fro, same for the etc folder as well.


3. If you develop your components in eclipse then running a build and installing the package in AEM will essentially copy the same things under the AEM /apps folder.


4. So after you Maven build the UI APPS project you will end up with a ZIP file (NOT A JAR)

AEM Project Structure in Eclipse


5. Go to the AEM Package Manager to install this.You will see that whatever you have developed under
the /apps folder will be copied under the AEM /apps folder. Under filters you can see the packages that will get installed.



4. The reverse is also true. You can develop your components in AEM and bring them to Eclipse doing the reverse process.




The AEM Content Project

1. The content project corresponds to the /content folder in AEM.

AEM Project Structure in Eclipse


2. If you want to push any media,images (Digital Assets) then the same can be placed under the /dam folder.

3. After building the project if we install the package in AEM the contents we placed under /dam
wii get copied under AEM /content/dam.





How to Build AEM project in Eclipse using AEM Archetype

How to build AEM project in Eclipse using AEM Archetype


To build a AEM structured project in eclipse please follow the following steps.

Step 1: Configure the AEM Archetype in Eclipse.

Before we begin our development, we need to first configure the AEM Archetype so that we can use it for building AEM related Maven Projects in Eclipse.

1. Open Eclipse.

2. Go to Window --> Preferences

3. From the left side window, expand the Maven option.

4. Click on Archetypes.
How to Build AEM project in Eclipse using AEM Archetype

5. Click on Add Remote Catalog.

6. In the Catalog File text box enter the URL : https://repo.adobe.com/nexus/content/groups/public/archetype-catalog.xml

7. In the Description text box enter "AEM".

How to Build AEM project in Eclipse using AEM Archetype

8. Click OK. Click Apply. Click OK.
How to Build AEM project in Eclipse using AEM Archetype



Step 2: Creating a new AEM Maven Project

Now that we have configured the AEM Archetype, we need to proceed creating a AEM project in Eclipse.
Lets proceed:


1. In Eclipse goto File--> New --> Other

2. Browse and Select Maven --> Maven Project --> Next.

How to Build AEM project in Eclipse using AEM Archetype


3. Click Next again.


How to Build AEM project in Eclipse using AEM Archetype




4. Choose the "AEM" Archetype from the Catalog dropdown.

5. Choose the "aem-project-archetype" from the list of options.


How to Build AEM project in Eclipse using AEM Archetype

6. Click Next. It will download some required artifacts.


How to Build AEM project in Eclipse using AEM Archetype



7. Now enter the required details as shown below.


How to Build AEM project in Eclipse using AEM Archetype


8. Now click Finish.
9. You will now have a project Structure like this.


How to Build AEM project in Eclipse using AEM Archetype

10. Please DO NOT worry if you see red marked errors in the project.After a build it will disappear.



Step 3: Building the AEM Maven Project

Now after we have created the basic project structure we nee to build our project.

1. Right click on the parent project "newProject".

2. Go to Run As. Click the second option 2 Maven Build.

How to Build AEM project in Eclipse using AEM Archetype


3. Type in clean install in the Goals text box.
How to Build AEM project in Eclipse using AEM Archetype


NOTE:If you are using any External API Jars then please add the depenencies in your pom.xml before building. Else the build will fail.


4. It will start the build and download many resources.

How to Build AEM project in Eclipse using AEM Archetype
5. Downloading may take upto 30 Minutes. So please be patient.

6. After the Build we will see how we can use our project to build AEM Applications.


THE NEXT PART...

AEM Project Structure in Eclipse