Friday, September 28, 2018

Ajax | Provisional Headers are shown | Cookies are not sent with request

Problem:

When making ajax calls, if you see that your Ajax is not cross domain and you are getting following issues:
1. Provisional Headers are shown in browser request headers
2. Cookies are not sent with request

Solution: 

This may happen if server side you are dependent on cookie values. You need to set cache false in your Ajax call by sending following param:

cache: false

So your Ajax look like this:
$.ajax({
                    url : "/some/resource/path/server/side",
                    type : "GET",
                    async : false,
                    cache: false,
                    success : callback,
                    error: errorCallback
});

If your Ajax is cross domain then you need add this param in your Ajax:
xhrFields : {withCredentials : true}

Thursday, June 14, 2018

Adobe Search & Promote Integration

Background:

Integration of Adobe Search and Promote with AEM gives marketers extra edge to control their site search results compare to conventional OOTB Lucene or Solr searches. Marketers can control the ordering of results based on analytics performance, relevance and marketing needs. It gives capability to Inject promotional content with auto complete and type ahead features. Integrating S&P with AEM is quite simple.

Note: Adobe Search & Promote has been deprecated in AEM 6.5.

Prequisites:

1. You should have Adobe S&P license
2. S&P user account (Adobe will provide user account to manage S&P server settings once you purchase the license)

Integration Steps:

To call the Adobe Search&Promote service from your website, perform the following tasks:

1.   Specify the URL of the Cloud.
2.  Configure the connection to the Search&Promote service.
3. Configuring the Data Center
4.  Add Search&Promote components to Sidekick.
5. Use the components to author the content. (See Adding Search&Promote Features to a Web Page.)


Note:
If you are using Search&Promote with a custom proxy configuration, you need to configure both HTTP Client proxy configurations as some functionalities of AEM are using the 3.x APIs and some others the 4.x APIs:
  • 3.x is configured with http://localhost:4502/system/console/configMgr/com.day.commons.httpclient
  • 4.x is configured with http://localhost:4502/system/console/configMgr/org.apache.http.proxyconfigurator

  1. Changing the Search&Promote service URL

The default URL that is configured for the Search&Promote service is http://searchandpromote.omniture.com/px/. To use a different service, use the OSGi console to specify a different URL.

a. Open the OSGi console and click the Configuration tab. (http://localhost:4502/system/console/configMgr.)
b. Click the Day CQ Search&Promote Configuration item.
c. Enter the URL in the Remote Server URI box, and click Save.

2. Configuring the connection to Search&Promote

Configure one or more connections to Search&Promote so that your web pages can interact with the service. To connect, you need the member identification and account number of your Search&Promote account.

1.  From the Tools icon > Deployment, select Cloud Services.

This takes you to the Cloud Services Dashboard. If on a local machine, the url of the dashboard will look something like this:
http://localhost:4502/libs/cq/core/content/tools/cloudservices.html

2. In the Cloud Services page, click on the Adobe Search&Promote link or the Search&Promote icon.

If this is the first time you are configuring Adobe Search&Promote, click Configure Now to open the Create Configuration panel. Any existing Search&Promote Configuration appears below Available Configurations on the Cloud Services dashboard Adobe Search&Promote list item.

3.  Enter a Title that is recognizable to page authors, and enter a unique Name, then click Create.

The Edit Component window opens.

4. Add the following to the fields in the Edit Component dialog box.

Member ID
Account number


Note: In order to get this information yourself, first you need to log into http://searchandpromote.omniture.com/center/ using your valid Seach&Promote credentials (email/password). Then, you need to look at your url in your brouser's address bar which should look something like this:
http://searchandpromote.omniture.com/px/home/?sp_id=XXXXXXXX-spYYYYYYYY

Where:

XXXXXXXX corresponds with your Member id
spYYYYYYYY corresponds with your Account Number

5. Click Connect To Search&Promote.

When the connection success message appears, click OK.
(After connecting, the button text changes to Re-Connect To Search&Promote.)

6. Click OK.

The Search&Promote Settings page appears for the configuration that you have just created.

3.      Configuring the Data Center

If your Search&Promote account is in Asia or Europe, you need to change the default data center so it points to the right one (the default data center is for North American accounts).

To configure the data center:

1.  Navigate to the Web console at http://localhost:4502/system/console/configMgr/com.day.cq.searchpromote.impl.SearchPromoteServiceImpl

2.  Depending on the location of the server, change the URI to one of the following:

North America: https://center.atomz.com/px/
EMEA: https://center.lon5.atomz.com/px/
APAC: https://center.sin2.atomz.com/px/
3.  Click Save.

4.     Adding Search&Promote components to Sidekick

In Design mode, edit a par component to allow the Search&Promote components in Sidekick.

For information about using the components, see See Adding Search&Promote Features to a Web Page.)

5.  Binding Search&Promote account to individual sites

Configure web pages so that they use a specific Search&Promote service. Search&Promote components automatically use the service of their host page.

When you configure the Search&Promote properties for a page, all child pages inherit the settings. If required, you can configure child pages to override the inherited settings.

  1. Open the Page Properties dialog box. For example, on the Websites page, right-click the page and click Properties.
  2. Click the Cloud Services tab.
  3. To disable the inheritance of cloud services configurations from a parent page, click the padlock icon next to the inheritance path.
  4. Click Add Service, select Adobe Search&Promote, and click OK.
  5. Select the connection configuration for your Search&Promote account, and then click OK.

6. Generating a sitemap

Generate a sitemap of your web site that the Search&Promote service can read for indexing purposes. Follow Adobe documentation for more details on this.

Wednesday, March 21, 2018

Creating standard AEM project structure on latest Archetype

Objective:

Archetypes create a minimal AEM project setup which works as a starting point for any new AEM application. So when setting up codebase for your new project, DO NOT COPY it from your old codebase. Instead, the code base should be setup using latest archetype. Using archetype is very easy thing and it just need to run a single command. Even if you are migrating old code bases to new AEM version, start from creating a new code base based on recommended archetype (Refer table below) and then copy individual pieces of old code base to appropriate location as per new archetype structure. 

This article talks about maven archetypes. If you are looking for Lazybones, refer this link: https://helpx.adobe.com/experience-manager/using/aem_lazybones.html


Solution:

Based on your AEM version, choose the desired project archetype from the below table:

Archetype VersionAEM Version
76.0 or newer
86.0 or newer
96.0 or newer
106.0 or newer
116.2 or newer
126.3 or newer
136.4, 6.3 + SP2
146.4, 6.3 + SP2
156.4, 6.3 + SP2
166.4, 6.3 + SP2
176.4, 6.3 + SP2
186.5, 6.4, 6.3 + SP3
196.5, 6.4, 6.3 + SP3
206.5, 6.4, 6.3 + SP3


Follow these steps to generate standard project structure:
  1. Go to the project code folder
  2. Open command prompt
  3. Run the below command:
    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=18 -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/
    OR
    mvn archetype:generate -DarchetypeGroupId=com.adobe.granite.archetypes -DarchetypeArtifactId=aem-project-archetype -DarchetypeVersion=20

    *Change the "DarchetypeVersion" parameter depending on AEM version. Refer table above.
  4. When prompt enter additional details about groupId, artifactId etc.


References:
1. https://helpx.adobe.com/experience-manager/using/maven_arch13.html
2. https://github.com/adobe/aem-project-archetype
3. https://github.com/adobe/aem-project-archetype/blob/master/VERSIONS.md

Tuesday, March 13, 2018

QueryBuilder - Useful Queries

AEM provides useful tool to run dynamic queries on repository.

QueryBuilder Link- http://localhost:4502/libs/cq/search/content/querydebug.html

1. Find List of all templates template


Set Extract facets true (Enable checkbox)

path=/content/mysite/mypath
type=cq:Page
property=jcr:content/sling:resourceType
property.operation=exists // Check that property exists
p.hits=selective // you want only selected properties as defined by p.properties
p.properties=sling:resourceType  // What properties you want in facets, multiples separated by space

2. Find list of pages of a particular template


path=/content/mysite/mypath
type=cq:Page
property=jcr:content/sling:resourceType
property.value=my-site/components/page/somepage
p.limit=-1 //All results
p.guessTotal=true // Makes search faster

3. Check asset types in a DAM path


Set Extract facets true (Enable checkbox)

path=/content/dam/myapp
type=dam:Asset
property=jcr:content/metadata/dam:Fileformat // OR use dc:format for better results
property.operation=exists
p.hits=selective by p.properties
p.properties=jcr:content/metadata/dam:Fileformat // OR use dc:format for better results

4. Find list of all components used in site


path=/content/my-site
type=nt:unstructured
property=sling:resourceType
property.operation=exists
p.hits=selective by p.properties
p.properties=sling:resourceType

Notes-

property.operation : “equals” for exact match (default), “unequals” for unequality comparison, “like” for using the jcr:like xpath function , “not” for no match , (value param will be ignored) or “exists” for existence match .(value can be true – property must exist)

5. Property Does not Exist


type=dam:Asset
path=/content/dam/my/project
1_property=jcr:content/metadata/dc:format
1_property.value=application/zip
2_property=jcr:content/metadata/custom
2_property.value=false
2_property.operation=exists
p.limit=-1

6. Find all nodes created after a particular time or with in a specified interval


path=/content/dam/my/project
type=dam:Asset
property=jcr:content/metadata/dc:format
property.value=application/zip
daterange.property=jcr:created
daterange.lowerBound=2019-03-04T00:00:00.000+05:30

You can use upperBound if you want less than "<" restraint on this query to find items with in a specified time period.

Wednesday, November 22, 2017

Change File Upload Size

You can use the following instructions to modify the file upload size in AEM

Modify Asset Upload Size


2. Go to the below path:
/libs/dam/gui/content/assets/jcr:content/actions/secondary/create/items/fileupload.

You can change the "SizeLimit" property of the node to tweak the file upload options.

The current size limit is 2 GB default; you can increase it if application is expected to support higher file sizes.

Modify Zip Extraction Size

AEM provides "Unarchiver" workflow process to extract zip files. The extraction of zip is bound to following configurations in workflow step"

1. Number of files in a directory - 100 is default
2. Number of total files in the zip- 10,000 is default
3. Maximum size of extracted folder - 2GB is default

You can increase it from the configuration.

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...