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 22, 2019

Error extracting plugin descriptor: 'Goal: * already exists in the plugin descriptor for prefix: *

 Error extracting plugin descriptor: 'Goal: validate already exists in the plugin descriptor for prefix: test

I was getting the below error while installing the Maven plugin - mvn clean install

maven-plugin-error

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project test: Error extracting plugin descriptor: 'Goal: validate already exists in the plugin descriptor for prefix: test
Existing implementation is: test.MyMojo
Conflicting implementation is: test.MyMojo'
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)

The configurations are below

MyMojo.java

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * Goal which validate the content.
 * @goal validate
 * @phase VERIFY
 */

@Mojo (name="validate", defaultPhase=LifecyclePhase.VERIFY, requiresProject=false )
public class MyMojo extends AbstractMojo
{
    @Parameter (property="message", defaultValue="Default Message")
    private String message;

    public void execute() throws MojoExecutionException
    {
        System.console().writer().println(message);
    }
}

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <packaging>maven-plugin</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>test Maven Mojo</name>
  <url>http://maven.apache.org</url>
  
    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>3.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>3.2.5</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

After analysis, the root cause is @goal validate in the Java annotation and the @Mojo setting (name="validate") generating the same goal - validate and failing with the duplicate exception.

/**
 * Goal which validate the content.
 * @goal validate
 * @phase VERIFY
 */

@Mojo (name="validate", defaultPhase=LifecyclePhase.VERIFY, requiresProject=false )

The deployment is success after removing the @goal validate from the java annotation.

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * Goal which validate the content.
 * @phase VERIFY
 */

@Mojo (name="validate", defaultPhase=LifecyclePhase.VERIFY, requiresProject=false )
public class MyMojo extends AbstractMojo
{
    @Parameter (property="message", defaultValue="Default Message")
    private String message;

    public void execute() throws MojoExecutionException
    {
        System.console().writer().println(message);
    }
}



Friday, June 21, 2019

How to expose Restful Services through JAX-RS(Jersey) in AEM

How to expose Restful Services through JAX-RS(Jersey) in AEM

This video explains How to expose Restful Services through JAX-RS(Jersey) in AEM




Saturday, June 15, 2019

AEM OAuth Server Functionalities - Deep Dive

AEM OAuth Server Functionalities - Deep Dive

This video explains how to use Adobe Granite OAuth Server functionalities to grant the resource access to external clients





Saturday, June 8, 2019

How to Setup Job Offloading in AEM Author Instance - Asset Process Offloading?

How to Setup Job Offloading in AEM Author Instance - Asset Process Offloading?


This video explains how to Setup Job Offloading in AEM Author Instance - Asset Process Offloading





Wednesday, June 5, 2019

How to migrate the existing AEM instance to cloud storage – S3 bucket?

How to migrate the existing AEM instance to cloud storage – S3 bucket?

This video explains how to migrate the existing AEM instance to cloud storage – S3 bucket




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.