Tuesday, 27 June 2017

AEM Components not loading in touch ui

I am facing below issues when working on touch UI
  1. I don't see the components on the left rail though I have added the components from design mode. I am dragging and dropping the component from classic ui. I found in forum that there is cache issue in touch ui. Cannot find my components in touch ui sideline. I could see this error on page load /libs/wcm/core/content/components.1498484847911.html?_=1498484940719 500 (Server Error)
  2. When I tried to author the touch ui dialog and click on save, I don't see page is refreshed and authoring changes are not reflected. I see below JS error in browser console.
Error 1:

Error 2:
Uncaught TypeError: Cannot read property 'componentConfig' of undefined
    at f (editor.min.js:4355)
    at Object.<anonymous> (editor.min.js:4578)
    at i (jquery.min.js:784)
    at Object.fireWith [as resolveWith] (jquery.min.js:820)
    at cf (jquery.min.js:2421)
    at XMLHttpRequest.i (jquery.min.js:2519)

Error 3:

Uncaught Error: Components could not be loaded.

Error 4:
GET https://localhost:5433/libs/wcm/core/content/components.1537887896814.html 500 (Server Error)

Root Cause:
when I hit url [1], am getting below exception.
org.apache.sling.api.request.TooManyCallsException:
/libs/cq/gui/components/authoring/componentbrowser/component/component.jsp
It seems that total number of components in AEM instance is more than the default number i.e 1500 (AEM 6.1) or 1000 (AEM 6.2). So the new components are not displayed in side rail and not able to edit the existing components.

Solution: 
We need to increase the "sling.max.calls" property value of "Apache Sling Main Servlet" OSGI config. My total component count was 1602, I have increased to 2000 and solved above 2 issues

Wednesday, 21 June 2017

Bundle is not uploading after maven build

Check first if bundle is installed in /system/console/bundles. check if jar files is present in /apps/app-name/install folder. If bundle is not present then change the filter.xml as shown below.

Under the path definition /apps/<appname>, define the following include and exclude rules
  • include pattern="/apps/<appname>(/.*)?"
  • exclude pattern="/apps/<appname>/install(/.*)?"
Note: these rules ensure that your bundle will be reinstalled upon every reinstall of the package.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/app-name">
<include pattern="/apps/app-name(/.*)?" />
<exclude pattern="/apps/app-name/install(/.*)?" />
</filter>
<filter root="/etc/designs/app-name">
</filter>
<filter root="/apps/sling/servlet/errorhandler/500.jsp" />
</workspaceFilter>

Tuesday, 20 June 2017

Create openssl certificate with SHA256 signature

1) Download OpenSSL  for windows 
2) Add  Bin  path to system path also copy openssl.conf file to c:/OpenSSL/  
3) run OpenSSL.exe file  
4) Run following command to run to create SHA256 with RSA encryption certificate 
A.      Generate SSL key file 
genrsa -out key_name.key 2048  ----  here 2048 is bit length for key 
** Please note that both these examples will not add a password to the key file. To do that you will need to add -des3 to the command. 
B.      Create a Certificate Signing Request (CSR) 
req -out Cert_file_name.csr -key key_name.key -new –sha256 
 i) You can check that your Certificate Signing Request (CSR) has the correct signature by running the following. 
req -in Cert_file_name.csr -noout –text 
It should display the following if the signature is correct. 
Signature Algorithm: sha256WithRSAEncryption 

Saturday, 17 June 2017

Changing a .content.xml file locally is not reflecting in CRX after maven build

If .content.xml file is changed locally and changes are not reflecting in crx then check maven-resources-plugin.

Add below plugin in pom.xml of UI module.(aem-sample/aem-content-ui/pom.xml).

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-content-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/vault-work</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/content</directory>
                                    <filtering>true</filtering>
                                    <excludes>
                                        <exclude>**/.svn</exclude>
                                        <exclude>**/.vlt</exclude>
                                        <exclude>**/.vltignore</exclude>
                                        <exclude>**/.DS_Store</exclude>
                                        <exclude>/etc/designs/${project.parent.artifactId}/jcr:content(/.*)?</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

For maven-resources-plugin check that its copying your .content.xml to target folder and for content-package-maven-plugin check that correct filter values are set.
We can also verify by extracting the generated package and check if it has the changes or not or look at a vault-work directory in target and get to the directory in which you have changed the .content.xml, verify if it has changes. If your changes are there in vault-works then the maven-resources-plugin is working absolutely fine and the issue may be with the content-package-maven-plugin.

If bundle is not installed check this post.


Saturday, 10 June 2017

Remove duplicate user defined objects from an ArrayList

To remove duplicate user defined objects we need to override hashCode() and equals() methods and update the comparison logic accordingly.

I had a scenario where I had a list of objects, I need to remove duplicates from the list. I have overrided hashcode() and equals() method. When the duplicate object is encountered, the hashcode value will be same, then equals method is executed. If both objects are equal then it returns true and object will not be added to HashSet.

package com.kishore.samples;

import java.util.ArrayList;
import java.util.HashSet;

public class RemoveDuplicates {

    public static void main(String a[]) {

        ArrayList<Price> listOfBlogs = new ArrayList<>();
        listOfBlogs.add(new Price("aaa", 20));
        listOfBlogs.add(new Price("22", 40));
        listOfBlogs.add(new Price("333", 30));
        listOfBlogs.add(new Price("aaa", 200));

        HashSet<Price> set = new HashSet(listOfBlogs);
        for (Price pr : set) {
            System.out.println(pr);
        }

    }
}

class Price {

    private String item;
    private int price;

    public Price(String itm, int pr) {
        this.item = itm;
        this.price = pr;
    }

    public int hashCode() {
        System.out.println("In hashcode");
        int hashcode = 0;

        hashcode = item.hashCode();
        hashcode += item.hashCode();
        System.out.println("hash code value for " + item + " is " + hashcode);
        return hashcode;
    }

    public boolean equals(Object obj) {
        System.out.println("In equals");
        if (obj instanceof Price) {
            Price pp = (Price) obj;
            return (pp.item.equals(this.item));
        } else {
            return false;
        }
    }

    public String getItem() {
        return item;
    }

    public void setItem(String item) {
        this.item = item;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String toString() {
        return "item: " + item + "  price: " + price;
    }
}

Output:

In hashcode
hash code value for aaa is 192642
In hashcode
hash code value for 22 is 3200
In hashcode
hash code value for 333 is 101286
In hashcode
hash code value for aaa is 192642
In equals
item: aaa  price: 20
item: 22  price: 40
item: 333  price: 30

Adobe Analytics vs Google Analytics

Google Analytics and Adobe Analytics both are web analytics services used in the measurement, collection, analysis and reporting of web data for purposes of understanding and optimising web usage. However, Web analytics is not just a process for measuring web traffic, but can be used as a tool for business and market research, and to assess and improve the effectiveness of a website.



Read More

Friday, 2 June 2017

Sling Models in AEM

We used to develop back-end login to components either by using WCMUse or WCMUsePojo or even JSP. With the release of AEM 6.3 and AEM Core WCM Components, we see that using Sling Models have been advocated by Adobe as the best practice. Now let’s take a look how we can use Sling Models.


You can work with Sling Models when developing with Adobe Experience Manager (AEM). That is, when developing an AEM project, you can define a model object (a Java object) and map that object to Sling resources. For more information, see Sling Models.
A Sling Model is implemented as an OSGi bundle. A Java class located in the OSGi bundle is annotated with @Model and the adaptable class (for example, @Model(adaptables = Resource.class). The data members (Fields) use @Inject annotations. These data members map to node properties.