Showing posts with label CQ5. Show all posts
Showing posts with label CQ5. Show all posts

Sunday, March 8, 2015

How to connect to oracle database using datasource pool from OSGI- Adobe Experience Manager(AEM)

How to connect to oracle database using datasource pool from OSGI- Adobe Experience Manager(AEM)

This post will explain how to connect to oracle database using datasource pool from Adobe Experience Manager(AEM)

Convert the JDBC driver to OSGI bundle:

In eclipse - File-->New-->Plug-in Development-->Plug-in from Existing JAR Archives
Click on Add External and Select the JDBC jar file

osgi_bundle

Click Next and enter the required details

Project name - OracleDriver
Plug-in ID - com.jdbc.oracle
Plug-in vendor - Oracle
Select the Execute Environment
Select an OSGi framework and select standard
Un-Select Unzip the JAR archives into the project and select Update references to the JAR files.

Tuesday, March 3, 2015

How to Customize/Configure the 404 error handler for multi sites in AEM/Adobe CQ5?

How to Customize/Configure the 404 error handler for multi sites in AEM/Adobe CQ5?

This post will explain how to configure the 404 error handler in multi site scenario for Adobe Experience Manager(AEM) - This will configure different 404 pages for different sites..

If the error handler is configured for first time then copy /libs/sling/servlet/errorhandler to /apps/sling/servlet (create the folder structure before copying )

Modify /apps/sling/servlet/errorhandler/404.jsp file to modify the 404 error handling rules.

<%  
//setting response code as 404
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
try {
    String uri = request.getRequestURI();
         
    if(uri.matches("(/content/Sample/en/)(.*)"))
    {
        pageContext.include("/content/Sample/en/404.html");
    } else if(uri.matches("(/content/Sample/es/)(.*)"))
    {
        pageContext.include("/content/Sample/es/404.html");
    } else if(uri.matches("(/en/)(.*)"))
    {
        pageContext.include("/content/Sample/en/404.html");
    }
    else if(uri.matches("(/es/)(.*)"))
    {
        pageContext.include("/content/Sample/es/404.html");
    } else
    {
        pageContext.include("/content/Sample/en/404.html");
    }

} catch (Exception e) {

%>
        Page Not Found
<%
}

%>

The conditions can be added to handle different sites, if the sites are running on different virtual host names then get the server name from the request
(request.getServerName()) and add the condition based on the server name.

This will redirect the user to site specific 404 pages.

Sunday, March 1, 2015

How to get the child Pages of a root Page through Java API -AEM/ Adobe CQ5

How to get the child Pages of a root Page through Java API - AEM/Adobe CQ5

This post will explain how to get the child Pages of a root Page through Java API in Adobe Experience Manager(AEM)

public static PageFilter getPageFilter() {
PageFilter pf = new PageFilter();
return pf;
}

public static Iterator<Page> getPageIterator(Page page){
Iterator<Page> children = page. listChildren(getPageFilter());
return children;
}

Filter can be changed to restrict child pages e.g Get the child pages created only with the template "/apps/sample/templates/samplePage"

public static PageFilter getPageFilter() {
PageFilter pf = new PageFilter() {
public boolean includes(Page p) {
ValueMap props = p.getProperties();
String templatePath = props.get("cq:template",String.class);
if("/apps/sample/templates/samplePage".equals(templatePath))
{
return true;
} else
{
return false;
}
}
};
return pf;
}

How to find a Page has child Pages thorough Java API - AEM/Adobe CQ5

How to find a Page has child Pages thorough Java API - AEM/Adobe CQ5

This post will explain how to find a Page has child Pages thorough Java API in Adobe Experience Manager(AEM)

public static boolean hasPageChildren(Page rootPage) {
          boolean isTrue = false;
          if (rootPage != null&& rootPage.listChildren(getPageFilter()).hasNext()) {
       isTrue = true;
          }
        return isTrue;
}

public static PageFilter getPageFilter() {
PageFilter pf = new PageFilter();
return pf;
}

How to get the published date of a page through Java API - Adobe Experience Manager(AEM)

How to get the published date of a page through Java API - Adobe Experience Manager(AEM)

This post will explain how to get the published date of a page through Java API in Adobe Experience Manager(AEM)

public static Date getPublishDate(Page page) {
Date newDate = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd", Locale.getDefault());
if (page != null) {
String publishedDate =  page.getProperties().get("publisheddate", "");
if(!"".equals(publishedDate)){
try {
newDate = sdf.parse(publishedDate);
} catch (ParseException e) {

}
}
}
return newDate;
}

Thursday, February 19, 2015

How to check the replication status through java API in AEM/Adobe CQ5

How to check the replication status through java API in AEM/Adobe CQ5

This post will explain how to check the replication status through java API in Adobe Experiance Manager(AEM)/Adobe CQ5

Maven dependency:

Add the following dependency to the pom.xml

<dependency>
<groupId>com.adobe.granite</groupId>
<artifactId>com.adobe.granite.replication.core</artifactId>
<version>5.12.2</version>
<scope>provided</scope>
</dependency>

API's:

@Reference
Replicator replicator;

@Reference
SlingRepository repository;

Session  session = repository.loginAdministrative(null);
ReplicationStatus status=replicator.getReplicationStatus(session, “nodepath”);

status.isDelivered();//Checks if the content is delivered

Other methods to get the different status

isActivated()
isDeactivated
isPending()

Wednesday, February 18, 2015

How to execute the Quartz scheduler job only in master author node - AEM/Adobe CQ5

How to execute the Quartz scheduler job only in master author node -  AEM/Adobe CQ5

While we are deploying the scheduler in Adobe Experience Manager(AEM), the scheduler will be active in master/slave author nodes and all the publish nodes(based on our deployment configuration).

But sometimes there will be scenario the scheduled job should be only executed in master author node.

The below code snippet can be used to restrict the job getting executed only in master author node.

@Reference
SlingRepository repository;
private void sampleScheduledJob() {
       if(isRunMode("author") && isMasterRepository()){
            //execute the job functionality here
       }
}

private Boolean isRunMode(String mode) {
        Set<String> runModes = slingSettings.getRunModes();
        for (String runMode : runModes) {
                if (runMode.equalsIgnoreCase(mode)) {
                         log.debug("Current Runmode is : " + runMode);
                         return true;
                 }
        }
        return false;
}
               
public boolean isMasterRepository(){
          final String isMaster = repository.getDescriptor("crx.cluster.master");
          log.debug("isMaster.."+isMaster);
          return StringUtils.isNotBlank(isMaster) && Boolean.parseBoolean(isMaster);
}
               


  

Sunday, February 15, 2015

org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet - Adobe Experience Manager(AEM)

org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet - Adobe Experience Manager(AEM)

I was getting the below exception while invoking the servlet from Adobe Experience Manager(AEM) bundle.

15.02.2015 20:58:11.615 *ERROR* [FelixDispatchQueue] FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet) org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:332)
at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:219)
at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:320)
at org.apache.felix.framework.Felix.getService(Felix.java:3556)
at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:468)

 The root cause of the problem is different versions of servlet API classes are loaded by two different class-loaders.

To fix the issue make sure <scope>provided</scope> is added for the Servlet API dependency in POM.xml

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
</dependency>




Saturday, February 14, 2015

com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle - Adobe Experience Manager(AEM)

com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle - Adobe Experience Manager(AEM)

I was able compile and  deploy the bundle successfully with gson dependency but the bundle is not getting started with the error "com.google.gson,version=[2.2,3) -- Cannot be resolved in bundle" in Adobe Experience Manager(AEM)

The root cause of the problem is the gson jar is not available in the server for bundle access.

This issue can be resolved  by following any of the below approach.

1. Export the gson  package - com.google.gson.*

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>com.sample.activator.Activator</Bundle-Activator>
<Import-Package>*,com.sample.*</Import-Package>
<Export-Package>com.sample.*,com.google.gson.*</Export-Package>
<Bundle-SymbolicName>com.sample</Bundle-SymbolicName>
<Bundle-Vendor>Sample</Bundle-Vendor>
<Bundle-Category>Sample</Bundle-Category>
<Embed-Directory>dependencies</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

2. Add the gson jar in the bundle class path

Specify the gson dependency scpes as compile or runtime(compile is the default scope)

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>compile</scope>
</dependency

The gson jar will be included in the bundle classpath.

The dependencies with what are all the scopes are included in the bundle classpath is configured in maven-bundle-plugin

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

Saturday, February 7, 2015

How to retrieve the pages created with particular template using Query Builder API - AEM/Adobe CQ5

How to retrieve the pages created with particular template using Query Builder API - AEM/Adobe CQ5

This post will explain how to retrieve the pages created with particular template using Query Builder API in Adobe Experience Manager(AEM)/Adobe CQ5

API Reference:

@Reference
QueryBuilder queryBuilder;

Session session = repository.loginAdministrative(null);

String resourcePath="/content/sample/site-demo/en";

Map<String, String> searchMap = new HashMap<String, String>();
searchMap.put("type", "cq:Page");
searchMap.put("path", resourcePath);
searchMap.put("property", "jcr:content/cq:template");
searchMap.put("property.value", "/apps/common/templates/sampleview");
searchMap.put("p.limit", "-1");

Query query = queryBuilder.createQuery(PredicateGroup.create(searchMap),session);

SearchResult result = query.getResult();
for(Hit hit:result.getHits()) {

    String pagePath = hit.getPath();
    Node pageNode = hit.getNode
}

Sunday, February 1, 2015

Changing the log level for a package - Adobe Experience Manager(AEM)

Changing the log level for a package - Adobe Experience Manager(AEM)

This post explains the steps required to change the log level for a package in Adobe Experience Manager(AEM)(the version referred here is 5.6.1)

We can enable the log level of a package in two level - Global level, Package level.

Global level:

Login to /system/console/configMgr and go to OSGI -->Configuration
Search for "Apache Sling Logging Configuration"
Change the log level accordingly


Save the configuration

Package level:

Login to /system/console/configMgr and go to OSGI -->Configuration
Search for "Apache Sling Logging Logger Configuration" and click on "+" to add new configuration.


Wednesday, January 28, 2015

checkout: com.day.jcr.vault.vlt.VltException: Unable to mount filesystem -Adobe Experience Manager(AEM)

Checkout: com.day.jcr.vault.vlt.VltException: Unable to mount filesystem - Adobe Experience Manager(AEM)

Sometimes you may receive the following exception while exporting the  repository content to eclipse through vault.

Jcr File Vault [version 2.4.34] Copyright 2011 by Adobe Systems Incorporated
[ERROR] checkout: com.day.jcr.vault.vlt.VltException: Unable to mount filesystem
caused by: javax.jcr.RepositoryException: URL scheme http not supported. only

For me the issue got fixed after clearing the temp folder contents.


Sunday, January 25, 2015

How to Modify the Node permissions through Java - Adobe Experience Manager(AEM)

How to Modify the Node permissions through Java - Adobe Experience Manager(AEM)

This post will explain how  to Modify the Node permissions through Java in Adobe Experience Manager(AEM)

Java API:

import java.util.NoSuchElementException;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.security.AccessControlEntry;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.AccessControlPolicyIterator;
import javax.jcr.security.Privilege;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(label = "ModifyNodePermissions", metatype = false, immediate = true)
@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION, value = "ModifyNodePermissions") })
@Service(value = ModifyNodePermissions.class)
public class ModifyNodePermissions {

private static final Logger log = LoggerFactory.getLogger(ModifyNodePermissions.class);
@Reference
private SlingRepository repository;

public void modifyNodePermissions(String nodePath,String groupName)
{
Session session = null;
try {

session = repository.loginAdministrative(null);

UserManager userMgr = ((org.apache.jackrabbit.api.JackrabbitSession) session).getUserManager();
AccessControlManager accessControlManager = session.getAccessControlManager();
Authorizable authorizable  = userMgr.getAuthorizable(groupName);
AccessControlPolicyIterator policyIterator = accessControlManager.getApplicablePolicies(nodePath);

org.apache.jackrabbit.api.security.JackrabbitAccessControlList acl = null;

try {
acl = (JackrabbitAccessControlList) policyIterator.nextAccessControlPolicy();              

} catch (NoSuchElementException nse) {
acl = (JackrabbitAccessControlList) accessControlManager.getPolicies(nodePath)[0];
}

//Remove the Access Control Entry
 /*for (AccessControlEntry e : acl.getAccessControlEntries()) {
  if (e.getPrincipal().equals(authorizable.getPrincipal()))
 {
      acl.removeAccessControlEntry(e);
 }
                }*/

//Allow
/*Privilege[] allowPrivileges = {accessControlManager.privilegeFromName(Privilege.JCR_REMOVE_NODE),
accessControlManager.privilegeFromName(Privilege.JCR_REMOVE_CHILD_NODES) };

acl.addEntry(authorizable.getPrincipal(), allowPrivileges, true);
  */
//Deny
Privilege[] denyPrivileges = {accessControlManager.privilegeFromName(Privilege.JCR_REMOVE_NODE),
accessControlManager.privilegeFromName(Privilege.JCR_REMOVE_CHILD_NODES) };

acl.addEntry(authorizable.getPrincipal(), denyPrivileges, false);

//Add Policy
accessControlManager.setPolicy(nodePath, acl);
//Remove Policy
//accessControlManager.removePolicy(nodePath, acl);
session.save();

} catch (RepositoryException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null)
session.logout();
}
}
}


Saturday, January 24, 2015

How to Retrieve/Update the configuration details through Configuration Admin Service - Adobe Experience Manager(AEM)

How to Retrieve/Update the configuration details through Configuration Admin Service  - Adobe Experience Manager(AEM)

This post will explain how to Retrieve/Update the configuration details through Configuration Admin Service  in Adobe Experience Manager(AEM)

Java API

//Add the reference
@Reference
org.osgi.service.cm.ConfigurationAdmin configAdmin;

//Reterive/Update the configration

org.osgi.service.cm.Configuration config = configAdmin.getConfiguration("com.day.cq.mailer.DefaultMailService");
Dictionary d = config.getProperties();
String fromAddress=(String)d.get("from.address");
d.put("from.address", "albin.issac1@gmail.com");
config.update(d);

Saturday, January 17, 2015

Configuring proxy server details for HttpClient communication in Adobe Experience Manager(AEM)

Configuring proxy server details for HttpClient communication in Adobe Experience Manager(AEM)

This post will explain how to configure proxy server details for HttpClient communication in Adobe Experience Manager(AEM)

Go to config manager - http://localhot:4502/system/console/configMgr
Open Day Commons HTTP Client 3.1 and provide the proxy server details.


Check "Enable HTTP Proxy" and provide the HTTP Proxy Host and Port details.
If authentication required provide the proxy server user name and password.

Provide the host name and ip address for which the proxy is not required.

This proxy details will be used for all the communication happens via Apache HTTP commons. Client
This details will be used upon replication, if the proxy is not required to connect to publisher then add the publisher host name to No Proxy For list.

This proxy details will not be used if we are using HttpURLConnection for http communication.

Saturday, December 20, 2014

Encrypting/Decrypting data in Adobe Experience Manager(AEM)

Encrypting/Decrypting data in Adobe Experience Manager

com.adobe.granite.crypto.CryptoSupport service can be used to encrypt/decrypt the data in Adobe Experience Manager(AEM).

Maven Dependency:

<dependency>
  <groupId>com.adobe.granite</groupId>
        <artifactId>com.adobe.granite.crypto</artifactId>
         <version>0.0.18</version>
         <scope>provided</scope>
 </dependency>

Service to encrypt/decrypt the message:

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.CryptoSupport;

@Component(immediate = true, metatype = true)
@Service(value = EncrypionService.class)
public class EncrypionService {
@Reference
private CryptoSupport cryptoSupport;

public String encrypt(String plainText) throws Exception
{
try {
return cryptoSupport.protect(plainText);
} catch (CryptoException e) {
throw e;
}
}

public String decrypt(String encryptedText) throws Exception
{
try {
return cryptoSupport.unprotect(encryptedText);
} catch (CryptoException e) {
throw e;
}
}
}

org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.LinkageError: loader constraint violation - Adobe Experience Manager(AEM)

org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.LinkageError: loader constraint violation - Adobe Experience Manager(AEM)

Sometimes we may receive the following exception while invoking the Adobe Experience Manager(AEM) services.

20.12.2014 11:15:31.816 *ERROR* [0:0:0:0:0:0:0:1 [1419054331815] GET /services/EmailServlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.LinkageError: loader consaint violation: when resolving interface method "com..commerce.connector.CommerceService.getSession(Ljavax/servlet/http/HttpServleequest;Ljavax/servlet/http/HttpServleesponse;)Lcom//commerce/connector/session/CommerceSession;" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, com///servlet/EmailServlet, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for resolved class, com//commerce/connector/CommerceService, have different Class objects for the type connector.CommerceService.getSession(Ljavax/servlet/http/HttpServleequest;Ljavax/servlet/http/HttpServleesponse;)Lcom//commerce/connector/session/CommerceSession; used in the signature
at com...servlet.EmailServlet.doPost(EmailServlet.java:67)
at com...servlet.EmailServlet.doGet(EmailServlet.java:56)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:268)
at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:139)

This error will be thrown while invoking the service of one bundle from another bundle.

To fix this issue, make sure the required packages from the target bundle is imported to the source bundle.


Thursday, December 18, 2014

org.apache.sling.security.impl.ReferrerFilter Rejected empty referrer header for POST request -Adobe Experience Manager(AEM)

org.apache.sling.security.impl.ReferrerFilter Rejected empty referrer header for POST request - Adobe Experience Manager(AEM)

We will receive the following exception while testing the Adobe Experience Manager(AEM) POST Servlets from Rest client.


15.12.2014 22:55:01.434 *INFO* [0:0:0:0:0:0:0:1 [1418664301434] POST /services/EmailServlet HTTP/1.1] org.apache.sling.security.impl.ReferrerFilter Rejected empty 
referrer header for POST request to /services/EmailServlet

This error is is due to the Apache Sling Referrer Filter will not allow empty Referer address by default.

For testing purpose, we can allow empty referrer by changing the Apache Sling Referrer Filter.

Apache Sling Referrer Filter configuration

Go to the Felix Console - http://localhost:4502/system/console/configMgr
Search for "Apache Sling Referrer Filter"
Select "Allow Empty"

This should be only enabled for testing purpose in dev environment.

Wednesday, December 17, 2014

Sending mail through Java API with Gmail server – Adobe Experience Manager(AEM)

Sending mail through Java API with Gmail server – Adobe Experience Manager(AEM)

This post will explain the steps required to send mail in Adobe Experience Manager(AEM) through Java API with Gmail server.

Configure mail service:

Go to the Felix Console - http://localhost:4502/system/console/configMgr
Search for Day CQ Mail Service
Enter the Gmail server details as shown below and Save the data.

SMTP Server Host   - smtp.gmail.com
SMTP Server Port    - 465
SMTP User              - your gmail username
SMTP Password      - your password
From Address          - your email
SMTP Use SSL      - true


You may need to enable the access for less secure apps in google account - https://www.google.com/settings/security/lesssecureapps

Email Template:

Create the email template as text file and store it in repository - /etc/email/template/emailTemplate.txt (change the path accordingly)


Sunday, December 14, 2014

how to create the page through Java API in Adobe Experience Manager(AEM)

how to create the page through Java API in Adobe Experience Manager(AEM)

This post will explain how to create a page through Java API in Adobe Experience Manager(AEM)

Create the API service

This service create a sample page in Adobe Experience Manager(AEM).

import javax.jcr.Node;
import javax.jcr.Session;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.ComponentContext;

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;

@Component(immediate = true, label = "Create Page Service", description = "Create Sample Page", metatype = true)
@Service(value = CreateSamplePage.class )
public class CreateSamplePage   {

@Reference
private ResourceResolverFactory resolverFactory;
private ResourceResolver resourceResolver;
 
private void createPage() throws Exception {
String path="/content/poc";
String pageName="samplePage";
String pageTitle="Sample Page";
String template="/apps/geometrixx/templates/homepage";
String renderer="geometrixx/components/homepage";

this.resourceResolver = this.resolverFactory.getAdministrativeResourceResolver(null);
    Page prodPage = null;
    Session session = this.resourceResolver.adaptTo(Session.class);
    try {
    if (session != null) {

    // Create Page    
    PageManager pageManager = this.resourceResolver.adaptTo(PageManager.class);
    prodPage = pageManager.create(path, pageName, template, pageTitle);
    Node pageNode = prodPage.adaptTo(Node.class);

Node jcrNode = null;
if (prodPage.hasContent()) {
jcrNode = prodPage.getContentResource().adaptTo(Node.class);
} else {                
jcrNode = pageNode.addNode("jcr:content", "cq:PageContent");
}
          jcrNode.setProperty("sling:resourceType", renderer);
     
     
         Node parNode = jcrNode.addNode("par");
         parNode.setProperty("sling:resourceType", "foundation/components/parsys");

 Node textNode = parNode.addNode("text");
 textNode.setProperty("sling:resourceType", "foundation/components/text");
 textNode.setProperty("textIsRich", "true");
 textNode.setProperty("text", "Test page");

session.save();
        session.refresh(true);
 }
       
} catch (Exception e) {
throw e;

   }    
}