Tuesday, December 30, 2014

Building a executable JAR file with external libraries through JDeveloper

Building a executable JAR file with external libraries through JDeveloper

This post explain the different approaches to build the executable JAR file with external libraries through JDeveloper.

Referring the external libraries from JAR:

Right Click project and select properties
Click on Deployment and create new JAR deployment profile.
Select "Include Manifest File" option.
Select the main class.



Create a manifest file(any location) and add the required jar files to the Class-Path header

Class-Path.mf

Class-Path: json.jar log4j.jar

 End the Class-Path.mf file by a carriage return.


Add the Class-Path.mf file to Additional Manifest Files to Merge into Manifest.mf




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)