Monday, May 29, 2017

How to expose Regex based rest service in AEM

How to expose Regex based rest service in AEM

This post will explain the approach to expose the regex based rest service in AEM. By default OSGI will not support exposing regex based rest services and it will only support the services based on the specified Path or Resource Type.

Install OSGI JAX-RS connector:

Install(/system/console/bundles) jersey-all, publisher, provider-security and other required bundles e.g. provider-gson for JSON support and make sure the bundles are in Active state.

The bundles can be downloaded from following URL -

Develop the Servlet with required path mapping:

package com.albinsblog.samples.core;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component(metatype = false)
@Path("/{catagroy}/{title}/p/{code : \\d{5}}")
public class RegexServlet {

public String getProductDetails(@Context HttpServletRequest request, @Context HttpServletResponse response,@PathParam("catagroy") String catagroy,@PathParam("title") String title,@PathParam("code") String code) {

  return "code="+code+";catagroy="+catagroy+";title="+title;


Add the following dependency in POM.xml


The servlet will accept the request with matching pattern - the Servlet path should be starting with /services

The Path Regex pattern specified in the Servlet will match for the following URL  - localhost:4502/services/categoryTest/Sampletitle/p/12345 (Code should be 5 digit)

Friday, May 19, 2017

Java PayPal API integration through proxy server

Java PayPal API integration through proxy server

Getting the below exception while integrating PayPal API with Java, based on the analysis the direct communication to the API is not enabled from the server and the communication should be directed via Proxy server.

09:10:50.525 [main] ERROR com.paypal.base.HttpConnection -  Retry  No : 1...
09:11:54.577 [main] ERROR com.paypal.base.HttpConnection - Caught exception while handling error response Connection timed out
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_67]

Setting the proxy server in the API:

 HashMap<String,String> config=new HashMap<String,String>();
config.put("http.UseProxy", "true");
config.put("http.ProxyPort", "80");
config.put("http.ProxyHost", "");
config.put("http.ProxyUserName", null);
config.put("http.ProxyPassword", null);

APIContext context = new APIContext(clientId, clientSecret, "sandbox",config);

Change the values of  ProxyHost,  ProxyPort, ProxyUserName and ProxyPassword accordingly.

The communication will be success after this.

Monday, May 8, 2017

Issue with AEM DTM Integration while connecting via proxy

Issue with AEM DTM Integration while connecting via proxy

The below exception is thrown while integrating AEM with DTM

08.05.2017 14:06:35.894 *ERROR* [ [1494270332788] POST /etc/cloudservices/dynamictagmanagement/test/jcr:content.companies.json HTTP/1.1] com.adobe.cq.dtm.impl.util.DTMConfigurationUtil Failed to obtain a response from the DTM API Server.
org.apache.http.conn.ConnectTimeoutException: Connect to [] failed: Connection timed out
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(
        at org.apache.http.impl.execchain.MainClientExec.execute(
        at org.apache.http.impl.execchain.ProtocolExec.execute(
        at org.apache.http.impl.execchain.RetryExec.execute(
        at org.apache.http.impl.execchain.RedirectExec.execute(
        at org.apache.http.impl.client.InternalHttpClient.doExecute(
        at org.apache.http.impl.client.CloseableHttpClient.execute(
        at org.apache.http.impl.client.CloseableHttpClient.execute(
        at com.adobe.cq.dtm.impl.util.DTMConfigurationUtil.callDTMApi(
        at com.adobe.cq.dtm.impl.servlets.DTMCompaniesServlet.doPost(

Caused by: Connection timed out
        at Method)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(
        ... 138 common frames omitted

Based on the analysis the DTM cloud connector is not using the the proxy server details configured to establish the connection.
This is the defect with the connector, raise a ticket with Adobe support team to  receive the fix.

As a temporary fix update in bundle - /libs/cq/cloudservices/install/cq-dtm-0.1.8.jar to support proxy server while establishing the connectivity. - callDTMApi

 HttpHost proxy = new HttpHost("",80);
 RequestConfig config = RequestConfig.custom().setProxy(proxy).build();   

Refer the following post for updating the java class in a bundle -

This post is written based on the AEM version AEM 6.1 SP1.

Sunday, May 7, 2017

How to get the basic profile details of a user in external clients through OAuth - AEM

How to get the basic profile details of a user in external clients through OAuth - AEM

This post will explain the approach to get the basic profile details of a user through OAuth - AEM/Adobe CQ5

Configure the OAuth client - AEM:
Login to AEM through Admin credential
Access - http://localhost:4502/libs/granite/oauth/content/clients.html and click on "Create a new app" or "Add New Client"

Enter Client ID and "Redirect URI" - The URL to which the user will be redirected after successful authorization(external client URL)

Friday, May 5, 2017

How to display the git tags based on the environment in Jenkins parameter

How to get the basic profile details of a user in external clients through OAuth - AEM

This post will explain how to display the git tags based on the environment in Jenkins parameter - Displaying the dynamic list with tag names filtering the tags with environment name e.g. QA, UAT, PROD(the environment name should be included in the tag while creating)

Select "This build is parameterized" in Jenkins job configuration
Add new parameter of type Extensible Choice
Enter the name "Tag" and select the Choice Provider as "System Groovy Choice Parameter"
Enter the below script in "Groovy System Script"

def gettags = "git ls-remote -t https://username:[email protected]/project/repo.git".execute()
def tags = []
def t1 = []
gettags.text.eachLine {tags.add(it)}
for(i in tags)
   def tagName=i.split()[1].replaceAll('\\^\\{\\}', '').replaceAll('refs/tags/', '')
t1 = t1.unique()
return t1

Change the git repository details and the string based on that the tags should be filtered e.g QA, UAT, PROD

Click on "Run the script now" to test the script - this will displayed the filtered tags.
Save the configurations finally