Wednesday 30 August 2017

Integrate AEM with React JS library

Introduction

React is a Javascript library developed solely for the purpose of UI designing. It was developed in Facebook to facilitate the implementation of reusable, interactive and stateful UI components. Facebook use this library in production. 
It carefully notes down the differences in in-memory cache and use these differences to update the DOM in browser, which is what gives him the boost. This is the Virtual DOM feature.


Wednesday 23 August 2017

Validate JWT token and Secret Key

What is JSON Web Token?

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA.

When should you use JSON Web Tokens?

Here are some scenarios where JSON Web Tokens are useful:
  • Authentication: This is the most common scenario for using JWT. Once the user is logged in, each subsequent request will include the JWT, allowing the user to access routes, services, and resources that are permitted with that token. Single Sign On is a feature that widely uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains.
  • Information Exchange: JSON Web Tokens are a good way of securely transmitting information between parties. Because JWTs can be signed—for example, using public/private key pairs—you can be sure the senders are who they say they are. Additionally, as the signature is calculated using the header and the payload, you can also verify that the content hasn't been tampered with.
Click here to learn more about JWT.

Sample Java code to validate JWT token and secret key.

Add below maven dependency to your pom.xml

Saturday 19 August 2017

Install NodeJs

What is NodeJS

  • Node.js is an open source server framework
  • Node.js is free
  • Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • Node.js uses JavaScript on the server

Click here to check Why Node.js

What is npm?

npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.
Click here to learn more on npm.

Install npm

Click here to download and install the npm on your machine.

Test if nodeJs is installed correctly, run below command.
npm -v
or 
npm --version
npm version

Start npm run start, if you get below error 
npm ERR! path C:\Users\Kishore\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Kishore\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Kishore\AppData\Roaming\npm-cache\_logs\2017-08-19T14_53_13_265Z-debug.log


You can avoid above error by following below

  • running the npm command from bin folder
  • set environment variables (~\bin)


Wednesday 16 August 2017

Troubleshooting AEM 6.1 to AEM 6.2 upgradation

When we try to upgrade website developed on AEM 6.1 to AEM 6.2 we need to consider below points.

Update uber.jar version to 6.2.0

<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <scope>provided</scope>
    <classifier>obfuscated-apis</classifier>
</dependency>

Issue 1:

When tried to build code we normally see below error message.
java.lang.NoClassDefFoundError: com/day/cq/commons/Externalizer

06.07.2017 09:55:54.242 *ERROR* [0:0:0:0:0:0:0:1 [1499331350444] GET /content/kishore/en/test.html HTTP/1.1] 
com.day.cq.wcm.core.impl.WCMDebugFilter Exception: com/day/cq/commons/Externalizer
java.lang.NoClassDefFoundError: com/day/cq/commons/Externalizer

Solution:
Fixed this issue by rebuilding the package with AEM 6.2 uber.jar

Issue 2:
Caused by: org.apache.sling.scripting.sightly.SightlyException: 
Cannot find a a file corresponding to class com.aem.kishore.HelloWorld in the repository.

Solution:

This issue is caused due to the Java version. Use the correct java version preferably Java 8.

Tuesday 15 August 2017

Sling Resource API vs JCR API - Performance

Check the article to compare the performance when using Sling Resource API and JCR API.

This article illustrates different tests performed to compare the performance of sling resource api and jcr api.

Test 1: Traversing /content/geometrixx tree
Result: JCR API is roughly twice as fast as the Sling API when traversing a tree.

Test 2: Creating simple pages (single save)
When creating a 1000 simple pages and saving them in one go, it takes respectively 0.20 and 0.26 ms for the JCR and Sling API to create a single page. Creating 1000 pages took 200 and 260 ms respectively for JCR and Sling in total.






Saturday 5 August 2017

Configuring Index Connector in Adobe Search & Promote


Why Index Connector?

Use Index Connector to define additional input sources for indexing XML pages or any kind of feed. Check how to integrate AEM with Search & Promote

You can use a data feed input source to access content that is stored in a form that is different from what is typically discovered on a website using one of the available crawl methods. However, a data feed either comes from an XML document or from a comma- or tab-delimited text file, and contains the content information to index.