Thursday, July 4, 2019

How to design the AEM website using Editable Template and Layout Container

How to design the AEM website using Editable Template and Layout Container

This video explains How to design the AEM website using Editable Template and Layout Container




Tuesday, June 25, 2019

How to add a custom thumbnail to AEM(Adobe Experience Manager) content packages?

This post explains the steps to add a custom thumbnail to AEM(Adobe Experience Manager) content packages.

Create an image named thumbnail.png -the recommended dimensions are 64 x 64 pixels.

Create a new folder named definition under: <ui.apps or ui.content>/src/main/content/META-INF/vault/definition

Add the thumbnail to the definition folder.

Inside the definition folder, add a file named .content.xml. Populate it with the following:

 <?xml version="1.0" encoding="UTF-8"?>
 <jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
     <thumbnail.png/>
 </jcr:root>

Custom-thumbnail-aem-content-packages

 Build&deploy the package - mvn clean install -PautoInstallPackage

 Verify the custom thumbnail from package manager.

Custom-thumbnail-aem-content-packages



Saturday, June 1, 2019

java.lang.NoClassDefFoundError: javax/net/ssl/TrustManager - Issue while connecting to database through JDBC Connection Pool in AEM

java.lang.NoClassDefFoundError: javax/net/ssl/TrustManager - Issue while connecting to database through Connection Pool in AEM 


I was getting the below exception while trying to connect to MySQL database through JDBC connection pool in AEM 6.4 with Java 1.8

Exception:
java.lang.NoClassDefFoundError: javax/net/ssl/TrustManager
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:334)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1452)
at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at aemmysql.core.servlets.FirstServletSelector1.doGet(FirstServletSelector1.java:32)


Configured the Data source as below:

AEM-datasourcepool-mysql

Code:

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.sql.*; 
import com.day.commons.datasource.poolservice.DataSourcePool;
import javax.sql.DataSource;
import org.osgi.service.component.annotations.Reference; 

@Component(service=Servlet.class,
           property={
                   Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",
                   "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                   "sling.servlet.paths="+ "/bin/servlet/mysqldata"                   
           })
public class FirstServletSelector1 extends SlingAllMethodsServlet {
 @Reference
 private DataSourcePool dataSourceService;
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
    throws ServletException, IOException {         
     try{  
Connection con=((DataSource) dataSourceService.getDataSource("SampleOracleDS")).getConnection();;  
Statement stmt=con.createStatement();  
ResultSet rs=stmt.executeQuery("select * from sample");  
while(rs.next())  
System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
con.close();
}catch(Exception e){
System.out.println(e);
}        
    }
}

Configured the Import-Package in the core bundle pom.xml with com.mysql.cj.jdbc

<Import-Package>com.mysql.cj.jdbc,javax.inject;version=0.0.0,*</Import-Package>

Downloaded the connector jar from the following location and installed JAR to AEM server by converting to OSGI bundle


The same exception was displayed even after adding the javax.net.ssl package as part of the Import-Package in MySQL connector OSGI bundle.

After little struggle  i found that the package javax.net.ssl should be added to org.osgi.framework.bootdelegation property in crx-quickstart\conf\sling.properties

org.osgi.framework.bootdelegation=javax.net.ssl,com.yourkit.*, ${org.apache.sling.launcher.bootdelegation}

After restarting the server started getting the below exception

Exception:
java.lang.NoClassDefFoundError: javax/crypto/NoSuchPaddingException
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:334)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1452)
at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at aemmysql.core.servlets.FirstServletSelector1.doGet(FirstServletSelector1.java:32)

Additional to javax.net.ssl, the package javax.crypto should be added to org.osgi.framework.bootdelegation property in crx-quickstart\conf\sling.properties

org.osgi.framework.bootdelegation=javax.net.ssl,javax.crypto,com.yourkit.*, ${org.apache.sling.launcher.bootdelegation}

After restarting the server started getting another error

Exception:
java.lang.NoClassDefFoundError: javax/naming/InvalidNameException
at com.mysql.cj.protocol.ExportControlled.getSSLContext(ExportControlled.java:530)
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:302)
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1452)
at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at aemmysql.core.servlets.FirstServletSelector1.doGet(FirstServletSelector1.java:32)

Additional to javax.net.ssl and javax.crypto, the package javax.naming should be added to org.osgi.framework.bootdelegation property in crx-quickstart\conf\sling.properties

org.osgi.framework.bootdelegation=javax.net.ssl,javax.crypto,javax.naming,com.yourkit.*, ${org.apache.sling.launcher.bootdelegation}

The database connectivity is successful after restarting the server.

Refer https://www.albinsblog.com/2015/03/how-to-connect-to-oracle-database-using.html#.XPLN8YhKjIU for complete details on connecting to database through JDBC connection pool.


Wednesday, May 29, 2019

How to enable merge mode for the packages in Adobe Experience Manager(AEM)

How to enable merge mode for the packages in Adobe Experience Manager(AEM)


By default the packages build in AEM package manager is enabled with mode "overwrite", this will overwrite the target folder upon installing the package - the local changes under that folder will be lost.

This post explains the approach to enable the merge mode for the packages, this will help us to merge the package content with the repository content.

Create the package with required path and download to local file system

aem-package-merge-mode


Unzip the package zip file on your computer - jar -xvf test_mode-1.0.zip META-INF/vault/filter.xml

Open the file META-INF/vault/filter.xml in a text editor.

Add mode="merge" to the <filter ...> tag, the merge mode should be added to all the filters defined for example:

 <?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="xxxxx" mode="merge" >
<exclude pattern="xxxxx" />
</filter>
<filter root="xxxx" mode="merge"/>
 </workspaceFilter>

 e.g

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/content/we-retail/us/en/products/women" mode="merge" />
</workspaceFilter>

Available Filter Modes:


"replace" - This is the normal behavior. Existing content is replaced completely by the imported content, i.e. is overridden or deleted accordingly.

"merge" - Existing content is not modified, i.e. only new content is added and none is deleted or modified.

"update" - Existing content is updated, new content is added and none is deleted.

The default filter mode is "replace"

Re-zip the modified package contents so it includes the change - jar -uvf  test_mode-1.0.zip META-INF/vault/filter.xml
aem-package-merge-mode

Upload the modified package to target server - this will make sure the target server changes are not overwritten.


Friday, April 12, 2019

Not Found (404) - The requested URL /siteadmin resulted in an error in org.apache.sling.servlets.get.DefaultGetServlet.

Not Found (404) - The requested URL /siteadmin resulted in an error in org.apache.sling.servlets.get.DefaultGetServlet.


In one of our AEM(Adobe Experience Manager) environment recently we were facing 404 issue for all standard URL's like siteadmin, useradmin, welcome.html etc and for the custom content URLs.

The below message has been displayed in the browser while accessing the pages.

Not Found (404)
The requested URL /siteadmin resulted in an error in org.apache.sling.servlets.get.DefaultGetServlet.

Request Progress:
      0 TIMER_START{Request Processing}
      0 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>
      3 LOG Method=GET, PathInfo=null
      4 TIMER_START{handleSecurity}
   3166 TIMER_END{3160,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@1444cb1f returns true
   3344 TIMER_START{ResourceResolution}
   3438 TIMER_END{93,ResourceResolution} URI=/siteadmin resolves to Resource=JcrNodeResource, type=cq/ui/components/widget, superType=null, path=/apps/wcm/core/content/siteadmin
   3443 LOG Resource Path Info: SlingRequestPathInfo: path='/apps/wcm/core/content/siteadmin', selectorString='null', extension='html', suffix='null'
   3443 TIMER_START{ServletResolution}
   3446 TIMER_START{resolveServlet(/apps/wcm/core/content/siteadmin)}
   3455 TIMER_END{8,resolveServlet(/apps/wcm/core/content/siteadmin)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet
   3457 TIMER_END{14,ServletResolution} URI=/siteadmin handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet
   3459 LOG Applying Requestfilters
   3463 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl
   3469 LOG Calling filter: org.apache.sling.security.impl.ContentDispositionFilter
   3472 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
   3476 LOG Calling filter: com.adobe.granite.httpcache.impl.InnerCacheFilter
   3481 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
   3484 LOG Calling filter: com.adobe.cq.mcm.campaign.servlets.CampaignCopyTracker
   3486 LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
   3489 LOG Calling filter: com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet
   3491 LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter
   3496 LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
   3498 LOG Calling filter: com.adobe.cq.social.commons.cors.CORSAuthenticationFilter
   3500 LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
   3513 LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
   3515 LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl
   3518 LOG Calling filter: com.adobe.granite.csrf.impl.CSRFFilter
   3522 LOG Calling filter: com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter
   3525 LOG Calling filter: com.adobe.granite.requests.logging.impl.RequestLoggerImpl
   3528 LOG Calling filter: com.adobe.granite.rest.impl.servlet.ApiResourceFilter
   3822 LOG Calling filter: com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet
   3826 LOG Calling filter: com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler
   3831 LOG Calling filter: com.day.cq.dam.core.impl.servlet.ActivityRecordHandler
   3839 LOG Applying Componentfilters
   3841 LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter
   3844 LOG Calling filter: com.day.cq.wcm.core.impl.PageLockFilter
   3846 LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
   3958 LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
   3962 TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0}
   3966 LOG No renderer for extension html
   3970 LOG Applying Error filters
   3970 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
   3971 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
   3973 TIMER_START{handleError:status=404}
   4138 TIMER_END{163,handleError:status=404} Using handler org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet
   5244 LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html], order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobile: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=mobiledebug, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobiledebug: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=contentsync, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-contentsync: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), serializer=Config(type=htmlwriter, config={}))}
   5340 TIMER_END{5339,Request Processing} Dumping SlingRequestProgressTracker Entries
 
The trace says org.apache.sling.servlets.get.DefaultGetServlet is used to render the response instead of specific one in this case it should heave been /libs/cq/ui/components/widget/html.jsp - this was the case for all the pages, default servlet were used for rendering the response.

  3455 TIMER_END{8,resolveServlet(/apps/wcm/core/content/siteadmin)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet

  Based on the analysis

  •   All the bundles were active
  •   CRXDE and system console were accessible with out any issue
  •   There was no recent configuration changes or code deployment
  •   All the standard configurations were looking fine  

  Unfortunately we were not able to identify the root cause, it looks to be the server was not started completely last time.  The issue got resolved after restarting the server.