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

Saturday, 28 December 2019

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, 8 April 2017

Salesforce REST API implementation - JAVA

This post demonstrates the following basic use cases for the REST API:
- authentication with OAuth 2.0 (This is for development purposes only. Not a real implementation.)
- querying (using account records)
- inserting (using a contact record related to one of the retrieved account records)
- updating (updates contact record added in previous step)


import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;

import org.json.JSONException;
import org.json.JSONObject;

Friday, 17 February 2017

Uncaught ReferenceError: CQ is not defined

To avoid this error add init.jsp or init.html in your code.
<sly data-sly-include="/libs/wcm/core/components/init/init.jsp" data-sly-unwrap/>

Decompile AEM: How to get a jar from AEM

AEM development is sometimes difficult to get started due to limited documentation. By having some code examples or a clearer understanding of what is under the hood, this could be the difference from good code to great code. Having the ability to decompile a jar can be very helpful in the development process. Decompiling the jar is the easy part. Finding and getting the jar in AEM can be more difficult. There are two ways that this can be accomplished in AEM, with Vault or without Vault.
Check it out!

With Vault (vlt)

  1. Search for webservice, click Day Communique 5 WCM Webservice Support
  2. Notice Bundle Location copy the path after jcrinstall: (If you don't see jcrinstall, go to without vlt section)
  3. Open CRXDE Lite and add the copied path. You should see the name of the jar inside that path
  4. Now that the location is confirmed. Go to terminal and vlt down the jar. In my case this is what I used:

Thursday, 24 November 2016

Adobe AEM - Cross Domain AJAX Request

A common problem for developers is a browser to refuse access to a remote resource. Usually, this happens when you execute AJAX cross domain request using jQuery or plain XMLHttpRequest. As result is that the AJAX request is not performed and data are not retrieved.

jquery ajax cross domain
Figure 1. The same-origin policy restriction in effect


XMLHttpRequest cannot load http://remote-domain/url. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:5433' is therefore not allowed access


This is a security policy who defines the rules of how a web page can access an external resource (e.g. fonts, AJAX requests). Under the same-origin policy, web browsers do not permit a web page to access resources who origin differ than that of the current page. The origin is considered to be different when the scheme, hostname or port of the resource do not match that of the page. Overcoming the limitations of same-origin security policy is possible using a technique called Cross-origin resource sharing or simply CORS.

Saturday, 2 July 2016

Access local AEM on https

Enabling HTTP Over SSL

Generate Key Store
  • Create a directory named ssl in the directory where the quickstart JAR file is located.
  • In the command prompt, type the following command to create the credential and keystore:
    • keytool -genkeypair -keyalg RSA -validity 3650 -alias cqse -keystore [quickstart_dir]/ssl/keystorename.keystore  -keypass key_password -storepass  storepassword -dname "CN=Host Name, OU=Group Name, O=Company Name,L=City Name, S=State, C=Country_ Code"
  • The following example generates a private/public key pair with the following properties:
    • alias: cqse
    • keystore file: cqkeystore.keystore
    • key password: password
    • keystore password: password
Read More

Thursday, 23 June 2016

AEM 6.1 Downgrade of a Java version and quickstart shows UnsupportedClassVersionError major.minor version 52.0

Sometimes we get below error  when accessing any AEM pages.

Caused by: java.lang.UnsupportedClassVersionError: org/apache/jsp/apps/sling/servlet/errorhandler/_404_jsp : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method) 

NOTE: Please backup your AEM instance before doing this
  • Go to localhost:4502/system/console/configMgr
  • If the page opens, login as "admin"
    • Go to Menu > OSGI > Bundles [http://localhost:4502/system/console/bundles]
    • Find this "Apache Sling Commons FileSystem ClassLoader (" and note the BundleID (it is 218 for me)
    • STOP AEM
    • On Windows Explorer go to this path where your AEM is installed.. $path\aem-61-author\crx-quickstart\launchpad\felix\bundle218\data
    • Delete the classes folder under it.
    • Restart AEM.. this should fix the issue.
  • If the page above does not open,
    • (assuming the bundle-id is 218)
    • STOP AEM
    • On Windows Explorer go to this path where your AEM is installed.. __ $path\aem-61-author\crx-quickstart\launchpad\felix\bundle218\data __
    • Delete the classes folder under it.
    • Restart AEM.. this should fix the issue.

Sunday, 28 February 2016

Useful AEM articles

These are some of the useful kb articles of AEM
AEM 6.x
  1. AEM_6_TarMK_Online_Compaction : If you are seeing rapid repository growth on an AEM 6.x instance
  2. aem6-available-hotfixes : Adobe Experience Manager 6.0 hot fixes
  3. aem61-available-hotfixes : Adobe Experience Manager 6.1 hot fixes
  4. DisableLineChecker : Disable the CQ5 Link Checker
AEM 5.x
  1. AnalyzeMemoryProblems :  AEM over a period of time may become slower and finally runsout of memory or you see an error in the logs or in the console output OutOfMemoryError
  2. AnalyzePersistenceProblems : If CRX doesn’t start, or if there are exceptions and stack traces in the log file that are related to persistence (such as TarPersistenceManager or FileDataStore)
  3. AnalyzeSlowAndBlockedProcesses : CRX/CQ process uses 100% of the CPU, the system doesn’t respond, or the system is slow
  4. AnalyzeUnclossedSession : In AEM application, developer has to ensure the proper closure of the JCR sessions. If not, such sessions will not be subject of garbage collection and thus will stay in memory, causing out of memory issue or system slowness. Each CRX Session creates and maintains its own set of caches which adds to the overall resource consumption.
  5. AnalyzeUsingBuiltInProfiler : Sometimes the application will be running fine but only few of the process will be really slow
6. cacheentrycollector-cache-size-is-too-small : If permissions / ACLs in AEM or CRX is used extensively, then it can affect the search         performance in the repository because when search results are being retrieved they must be filtered against the permissions in the CRX repository.
7. CloneInstance : Cloning an existing instance
8. crx-disk-and-memory-monitoring-shutdown-too-aggressively : CRX automatically shuts downthe repository due to a monitoring feature
9. DataStoreGarbageCollection :  to remove any unused files in the Data Store, use Garbage collection.
10. datastore-inconsistency-record-not-found : If you are facing Datastore inconsistency and seeing ‘FileNotFoundException’

Monday, 11 January 2016

Implement Use-Interface using Sightly in AEM 6.x

Implementing sightly can be basically done with two important APIs (although few others are also available). In my other article I have cover up how you can  Access OSGI ser­vice from the WCMUse-class in Sightlyhere we are going to cover next important one which shows how you can implements the Use-interface in Java and combine your business logic with component file. 
Let’s see Use interface first, later we will jump to code. 
All you need to make sure is to implement public void init(javax.script.Bindings bindings) The initmethod will be called on initialization of the class with a Bindings object that holds all the context objects and any parameters passed into the use-class. Business logic will be present in this method, although you are free to create custom method which will be called from init().
Binding object is an mapping of key/value pairs, all of whose keys are Strings.

Sunday, 10 January 2016

Create a OSGI Configuration Listener in AEM 6.1

Following article demonstrate business scenario where you need to execute a job, call a method or simply log when there in change in XYZ OSGI configuration. Taking forward the OSGI Configuration Management and Reading of OSGI Configuration, I will show you how you can create a OSGI Configuration listener. Before that’s take a look at below…
ConfigurationListener[Interface] objects are registered with the Framework service registry and are notified with a ConfigurationEvent object when an event is fired. ConfigurationListenerobjects can inspect the received ConfigurationEvent object to determine its type, the pid of theConfiguration object with which it is associated, and the Configuration Admin service that fired the event.
I have used service but you can use any service based on your requirements and will read property email.from when their is a change. Let’s get started..
1. Create a Service which Implement ConfigurationListener interface

Indexing Properties and Nodes for AEM 6.0 and 6.1

To index a particular property, create a node directly under your oak:index of type oak:QueryIndexDefinition with the following properties:
name = propertyNames, type String[], value is the name of the property(ies) you want to index
name = type, type String, value = property
name = reindex, type Boolean, value = true
To index entire nodes so that you don’t have to list all their property names (for example, if they are coming from an outside source and you don’t know them all ahead of time), you have to do different things depending on if you are on 6.0 or 6.1. The following steps concern indexing nodes (and their properties) in the DAM, but they should work for general cases:
For 6.1:
  1. In CRXDE Lite, navigate to this path: /oak:index/damAssetLucene/aggregates/dam:Asset. You should see a list of nodes with names that start with “include” and then a number.
  2. To this list, add a new node of type nt:unstructured that follows the same naming convention and a new number one higher than the current highest (for example, if “include7” is the highest number with 7 then make a node with the name “include8”). The name probably doesn’t matter but we don’t tempt fate around here.
  3. Add a property to this node with the name “path” with a String value set to “”, for example: “jcr:content/metadata”.
  4. Click Save All.
  5. Navigate up the tree to /oak:index/damAssetLucene.
  6. Change the value of the “reindex” property on this node to “true”. This should perform a reindex on the repository.
For 6.0:
  1. In CRXDE Lite, find the node /oak:index.
  2. Under the oak:index node, create a new node of type oak:QueryIndexDefinition with the name “damAssetLucene”.
  3. Set the following properties on this new node:
    1. Name: async, type: String, Value: async
    2. Name: compatVersion, type: Long, Value: 1
    3. Name: evaluatePathRestrictions, type: Boolean, Value: true
    4. Name: reindex, type: Boolean, Value: false (you don’t want to trigger a reindex yet!)
    5. Name: type, type: String, Value: lucene
  4. Click Save All.
  5. Under the damAssetLucene node you just created, create a new node of type nt:unstructured with the name “aggregates”.
  6. Click Save All.
  7. Under the aggregates node you just created, create a new node of type nt:unstructured with the name “dam:Asset”.
  8. Click Save All.
  9. Under the dam:Asset node you just created, create a new node of type nt:unstructured with the name “include0”.
  10. Add a property to the include0 node with the name “path” with a String value set to “”, for example: “jcr:content/metadata”.
  11. Click Save All.
  12. Navigate back up the tree to the damAssetLucene node you created earlier.
  13. Change the value of the “reindex” property on this node to “true”. This should perform a reindex on the repository.
The key thing to note here is that you are replicating some of the same node structure on 6.0 that already exists by default on 6.1, but the compatVersion property is set to 2 in 6.1 and must be set to 1 on 6.0.
With the transition to Jackrabbit Oak, a lot of people are still working out what the best practice is for indexing Oak nodes; this may not be the definitive way to do indexing for properties and nodes in AEM, but it is one way we have found that seems to work well.

Installing Bundles by Runmode

If I had a dollar for every bundle configuration I've looked at where there was a little checkbox titled "Enabled", I'd have, like, maybe $31 dollars and I could afford a new Indie Steam game or perhaps 12 of them if I waited for the summer or holiday sales... In reality, I've been on countless projects where the prevailing approach for ensuring a bundle only runs for a specific runmode is to make it configurable via the aformentioned checkbox. While this approach certainly works, there's a much easier and, in my opinion, cleaner and better way to handle this that I think gets overlooked
For starters, consider that you can provide runmode-specific configurations for your bundles via simple naming convention. I'd cover this myself, but Krtisian Wright does an excellent job of doing so here. In short, you'll typically see structures along the following lines:
  • /apps/skynet/
  • /apps/skynet/config.publish
  • /apps/skynet/config.<some-other-runmode>
And, yes, Skynet is being built on top of AEM. You heard it here first... Back on topic, the same naming conventions apply for installation of bundles as well. For example
  • /apps/skynet/install.publish
will have any bundles therein installed only if the current runmode is publish. Also, for what it's worth, you can even chain runmodes together for both the configuration and installation of bundles. For example
  • /apps/skynet/install.publish.staging
will install any bundles underneath so long as the instance's runmode is both publish and staging. For the unaware, yes, you can have as many runmodes as you want for any particular instance. This allows you to set up environment-specific configurations. Further, note that the runmodes "author" and "publish" are just two default runmodes for AEM that have a bunch of predefined configuration set up for you. In fairness, one advantage to using the "Enabled" checkbox approach is that you could then test your bundle on any instance by configuring it. However, configuring bundles directly through Felix instead of doing so via sling:OsgiConfig nodes can open up its own can of worms in the generation of an nt:file and actually overwriting your sling:OsgiConfig with this nt:file if it exists :(. So, for future projects, I highly recommend setting up runmodes for your specific environments and building out your configurations and bundle installation for each exactly as you want them using the above approach.

Chrome Console Magic

Chrome Console Magic
Chrome has many timesaving and neat tools built into it, many of these tools are not necessarily obvious on the surface. This post is a deeper dive into what is available. If you are not familiar with Chrome Dev Tools at all, this post is probably not for you.

$ selectors

Chrome has built-in selectors much like jquery.
On this page you will see 3 divs, two with a selector-test class and one with selector-test id.
There are 4 useful types of $ selectors in Chrome.


$() selects the first matching element. (If jquery is active on the page, it will select all matching elements). It will match classes prefaced with ‘.’, IDs prefaced with ‘#’, or regular elements such as ‘p’, 'div', etc.
Example 1 (in the console type):
Chrome returns:
  <div class="selector-test">Test selector content (.selector-test)</div>
Example 2:
Chrome returns:
  <div class="selector-test">Test selector content (.selector-test)</div>
The same div is selected in both examples as both the first item with class "selector-test" and the first div on the page.

Saturday, 12 December 2015

Asset Grabber – oEmbed a complete asset embed solution

If you are an AEM/CQ developer and had worked on multiple projects, then you might be very well familiar with how exasperating is to create components for embedding assets in for web page. Here’s how actually it goes from development perspective.
Things starts with video component. Now create a component for YouTube, let’s assume you created. Next day client knock’s your door and say’s, “We are now planning to embed Vimeo also, please add this into your requirement and start working“. Somehow you managed to create a Vimeo component. After 2 days, client again shoots a missile, “We had an internal discussion and now we are planning to feature Ted videos as well, please get started“. At this point what development team and with  how much anger they get into you will be aware, But before leaving for the day you run this command: “project XYZ: Completed Ted Video module“. It means you have completed this as well.
When it comes to assets, it’s very strenuous to take care of all scenarios. Let me introduce youoEmbed, we call it as “Assets Grabber”. Yes, you heard right, it’s having secret magnetic attraction power to pull things from other sites and show in yours. That’s so called secret magnetic attraction is it’s ability to handle and support huge amount of sites starting from VimeoYouTube for videos to Flickr for images to Infogram for charts to Slideshare for slide to Meetup for meetings.

Sunday, 6 December 2015

Query Builder

Search is always the backbone of many functionalities in an AEM application . It becomes quite critical in Business scenarios to implement the most Optimized Query which fetches the best possible result. To perform search in AEM , Query Builder is highly recommended over simple SQL / XPATH query statements. The Query Builder , if used correctly, will solve all your query implementations and would be a handy way to Optimize your queries for better performance of the page. Through this Blogpost , I would explain the basics of Query builder and then would go to advanced concepts , focusing at each point how you may create any search scenario to Query Builder Predicate form. I hope this post will solve all your Search performances related hurdles in AEM.

What is Query Builder?

Query Builder is an API which can be used to create Search queries in JAVA content repository. It is extensible tool by which you may add/remove various predicates in a query using this API. The best way to create predicates is using the Query Builder Debugging Tool : /libs/cq/search/content/querydebug.html . Try to implement your Business use case in the Predicate form using this debugger, Optimize the query and then implement it in the code.

Creating Adobe CQ OSGi bundles that use the Query Builder API

Discusses how to create an OSGi bundle that contains the AEM Query Builder API. This OSGi operation contains application logic to search the AEM repository. This article also discusses how to create a web page that invokes an operation exposed by the OSGi bundle and display the results in a grid control.    
This article uses an Adobe Maven Archetype project to build an OSGi bundle. If you are not familiar with an Adobe Maven Archetype project, it is recommended that you read the following article: Creating your first AEM Service using an Adobe Maven Archetype project.
This article has been updated to replace the use of a SlingRepository instance with a ResourceResolverFactory instance. TheResourceResolverFactory is used to create a Session instance that is required to use the AEM Query Builder API. Now a Session instance is created by using the adaptTo method:
This article has been updated to use this Maven command to build the OSGi bundle:
mvn archetype:generate -DarchetypeRepository= -DarchetypeArtifactId=multimodule-content-package-archetype -DarchetypeVersion=1.0.2 -DgroupId=custom.querybuilder -DartifactId=querybuilder -Dversion=1.0-SNAPSHOT -Dpackage=custom.querybuilder -DappsFolderName=myproject -DartifactName="My Project" -DcqVersion="5.6.1" -DpackageGroup="My Company"



Content Finder - Query Builder

Use QueryBuilder HTTP API syntax to drive ContentFinder queries instead of more restrictive GQL.
How to Use
  • Install the ACS AEM Commons package
  • Create a new Content Finder Tab JS file
  • Update the contentfindertab config JS object to include:
    • url: “/bin/wcm/contentfinder/qb/view.json”
    • baseParams: { .. }
      • JS object representing the QueryBuilder API key/value pairs used to drive all of the ContentFinder Tab’s queries
      • If no baseParams are set then the suggestField will populate the query param
    • getParams: { .. }
      • JS object representing the dynamic QueryBuilder API key/value pairs used to drive all of the ContentFinder Tab’s queries (baseParams will be used in conjunction with these)

Query Builder samples

AEM comes with a Query Debugger tool at:
You can execute search queries on the JCR (Java Content Repository) using this tool.  For example, to search for all DAM assets in /content/dam/geometrixx, execute the following query:
See screenshot below:
Running this search query should produce a result such as follows:
You can execute more complicated search queries as well.  For example, to search for all DAM assets in /content/dam/geometrixx with the string “.png” in the node name and to to sort the results in the descending order of when the node was last modified, execute the following query:
[email protected]:content/jcr:lastModified
More information here.  Excellent blog entry by Thomas Joseph on Oak indexes here.
Other examples:
How many audit events have accumulated:
How many unique users have logged in to AEM in the past 12 hours?
A user who has logged in from three different IP addresses (home office, work, mobile phone) will be counted three times.
How many web pages are in the AEM system?
How many tags have been defined?
How many total users are defined in the AEM system?
How many user groups are defined?
How many Client Libraries?

Read More