08 December, 2017

Create Servlet Project as Module

You would have seen that many times we are writing out own servlet in Liferay portal to achieve some specific use case.
In DXP, You can still cont. with such implementation and here you will see how you can write your servlet application as module.

Create liferay module type of API using developer studio or blade ci.

In bnd file:

 Bundle-Name: test-servlet
Bundle-SymbolicName: TestServlet
Bundle-Version: 1.0.0

Web-ContextPath: /test

In build.gradle:

 dependencies {
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"

In component class,

immediate = true,
property = {
service = Servlet.class)
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);

Just deploy the module and acces through URL : http://localhost:8080/o/test/my-servlet

Liferay DXP clustering

Hello Friends,

I am sure you would be looking for simple steps for DXP clustering.

Note:Liferay 7 clustering you can visit https://community.liferay.com/news/new-clustering-code-for-liferay-portal-community/ 

Image result for server clustering liferay

Steps for Liferay DXP clustering :

Liferay Setup:

- Setup liferay DXP in 2 separate servers which can be accesses using separate IP
- Both servers should be accessible to each other
- Here we are not going to setup 2 DXP instances in single server as it's not good for architectural perspective for production. 
- Setup first instance and populate DB data with single instance
- when you setup another DXP instance then point the same DB which you used for first instance. We are not going to use separate read write DB server here and will use single DB for read and write for both the instances. For production setup, you can think to create separate DB server for read and write operation.

Liferay Configurations for clustering 

Portal-ext Configuration for Node-1 and Node-2



# For clustering settings

In above property file, IP address would be your server IP address and TCP.xml we will see below.

TCP.xml configuration Node-1 and Node-2

- You can get this file from Liferay foundation.lpkg file
- extract lpkg and extract com.liferay.portal.cluster.multiple-1.0.11.jar where you can see tcp.xml
- copy tcp.xml file in local and update as per below settings which are highlighted. Here we are using TCPPING. You can use JDPCPing and other methods which liferay supports.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
    <TCP bind_port="7800"




 <TCPPING async_discovery="true"
    <MERGE3  min_interval="10000"
    <FD timeout="3000" max_tries="3" />
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK2 use_mcast_xmit="false"
    <UNICAST3 />
    <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
    <pbcast.GMS print_local_addr="true" join_timeout="2000"
    <MFC max_credits="2M"
    <FRAG2 frag_size="60K"  />
    <!--RSVP resend_interval="2000" timeout="10000"/-->

- Put this tcp.xml file in classpath of server and restart both the servers (nodes).

Setup shared Elastic server

You can refer https://customer.liferay.com/documentation/7.0/deploy/-/official_documentation/deployment/configuring-elasticsearch-for-liferay-0 for setting up elastic search server and point this server to both nodes so that both nodes keep common index records.

How to verify

- Look server log for both nodes where you will be able to see logs which tells you that both nodes listening each other.
- You can also create web content/Document in one node and check in another node. it should reflect without re-indexing and removing database cache.

- Liferay DXP Clustering
- How to Install Liferay DXP in a Clustered Environment
- Managing Liferay DXP's Distributed Cache

07 December, 2017

Liferay DXP setup with Weblogic

Download latest DXP version

  1. For Enterprise Edition, we need to download Liferay DXP 
  2. For Community Edition, we need to download Liferay Portal

As we are using (EE ) Enterprise Edition, we will download Liferay DXP.

Note:Download latest DXP server from Liferay customer portal, using the credentials provided by Liferay as part of licensing agreement. Download Liferay DXP’s WAR file and dependencies from the Customer Portal
Go to Products>>Liferay DXP click on Downloads

You’ll need the following files:
· liferay-dxp-digital-enterprise-[version].war: Liferay DXP WAR file
· liferay-dxp-digital-enterprise-dependencies-[version].zip: Liferay DXP dependencies

· liferay-dxp-digital-enterprise-osgi-[version].zip: Liferay DXP OSGi dependencies

Configuring Web Logic’s Node Manager

WebLogic requires a Node Manager to start and stop managed servers. Before installing Liferay DXP, you must configure the Node Manager included with your WebLogic installation. You’ll do this via the domains/your_domain_name/nodemanager/nodemanager.properties file. Open this file, and set the SecureListener property to false:

we have below path for setup :

If you’re running WebLogic on Mac or Linux, you may also need to set the nativeVersionEnabled property to false.

Also note that with SecureListener set to true, you must configure your machine in the Admin Server’s console to accept unencrypted connections from the Node Manager. To do this, first log in to your Admin Server and select Environment → Machines from the Domain Structure box on the left. Click your machine in the table and then select the Configuration → Node Manager tab. In the Type field, select Plain from the selector menu, and then click Save. You must restart your Admin Server for this change to take effect. 

Configuring Weblogic

Next, you must set some variables in two WebLogic startup scripts. These variables and scripts are as follows. Be sure to use set instead of export if you’re on Windows. 
1. your-domain/startWebLogic.[cmd|sh]This is the Admin Server’s startup script.
2. your-domain/bin/startWebLogic.[cmd|sh]This is the startup script for Managed Servers. 
Sample path for above files would be :

Add the following variables to both startWebLogic.[cmd|sh] scripts:
export DERBY_FLAG="false"
export JAVA_OPTIONS="${JAVA_OPTIONS} -Dfile.encoding=UTF-8 -da:org.apache.lucene... -da:org.aspectj..."
export MW_HOME="u01/app1/oracle/product/fmw12C/wlserver"
export USER_MEM_ARGS="-Xmx1024m -XX:MetaspaceSize=512m"

Also make sure to set MW_HOME to the directory containing your WebLogic server on your machine. For example: (leave it as is as $MW_HOME)
You must also ensure that the Node Manager sets Liferay DXP’s memory requirements when starting the Managed Server. In the Admin Server’s console UI, navigate to the Managed Server you want to deploy Liferay DXP to and select the Server Start tab. Enter the following into the Arguments field: 
-Xmx2048m -XX:MaxMetaspaceSize=512m
Click Save when you’re finished. 

Setting Liferay DXP Properties

Before installing Liferay DXP, you must need to set the Liferay Home folder’s location via the liferay.home property in a portal-ext.properties file. You can also use this file to override other Liferay DXP properties that you may need. 

1. First, decide which directory you want to serve as Liferay Home. In WebLogic, your domain’s folder is generally Liferay Home, but you can choose any folder on your machine. Then create your portal-ext.properties file and add the liferay.home property: 


Also keep one version of Portal-ext.properties file will be save in above path which will be useful to override properties in future and make sure just keep liferay.home in portal-ext.properties .This can be override anytime once liferay home path set in portal-ext which we will keep in war file of liferay DXP.

How to put portal-ext.properties in DXP war file

Now, we have to extract War file (for e.g liferay-dxp-digital-enterprise-7.0-sp6-20171010144253003.war) and in that WEB-INF/classes folder we have to place portal-ext.properties and re-war it again.

Take backup of that DXP war file at same path and rename it as backup
Copy the original war file to tmp folder and follow below steps to extract from war and re-war.

cp warfile.war /tmp
cd /tmp
unzip warfile.war
cd classes

Go to the path where your portal-ext.properties file is saved , Go to domain path: /u01/app/oracle/product/fmw1/user_projects/domains
cp portal-ext.properties  /u01/app/oracle/product/fmw1/user_projects/domains/base_domain/tmp/WEB-INF/classes

cd ...
cd ..
zip -r -u warfile.war WEB-INF
zip –r –u warfile.war dtd
zip –r –u warfile.war errors
zip –r –u warfile.war html
zip –r –u warfile.war index.jsp
zip –r –u warfile.war layouttpl

By this way again in tmp folder that war file will be ready. Copy that war file outside that temp folder at below path:

Now in future if you want to modify portal-ext, then you don't need to touch properties which we kept inside war file. you can just go to liferay home path which you set earlier and can override portal-ext.properties.

Installing Liferay DXP dependencies

1. unzip zip file (liferay-dxp-digital-enterprise-dependencies-)at below folder and place 7 files including ojdbc.jar file


2.liferay-dxp-digital-enterprise-osgi-[version].zipUnzip this file and place its contents in the Liferay_Home/osgi folder (/u01/app/oracle/product/fmw12C/user_projects/domains/osgi) If file not there so please create it

3. Copy ojdbc .jar file in /u01/app/oracle/product/fmw12C/user_projects/domains/base_domain/lib folder

Security Configuration

You must have to enable Java Security on your WebLogic server and specify a security policy to grant Liferay DXP access to your server. 
First, you’ll grant Liferay DXP access to your server. This configuration opens all permissions–you can fine-tune your policy’s permissions later. If it doesn’t already exist, create a policy file named weblogic.policy in your $WL_HOME/server/lib folder. 
/u01/app/oracle/product/fmw/ wlserver_10.3 /server/lib
Replace its contents with the following: 
grant {
    permission java.security.AllPermission;

To enable security on your WebLogic server and direct the server to your policy file, 
open the setDomainEnv.[cmd|sh] file in your domain’s bin folder. 
Then set the -Djava.security.manager Java option and set the property 
-Djava.security.policy to your weblogic.policy file. You can specify both settings on the same line like this:
Path to go is = /u01/app/oracle/product/fmw1/user_projects/domains/base_domain/bin
-Djava.security.manager -Djava.security.policy==$WL_HOME/server/lib/weblogic.policy

The double equals sign tells the app server to use only this policy file. Any other security policies are ignored.

In Weblogic console >> <Your-Managed-Server> , Go to Server_stat tab and add “-Xmx2048m -XX:MaxMetaspaceSize=512m” in Arguments box

Deploying Liferay DXP

Note:Before you start DXP deployment, just restart weblogic server so that dependencies which you kept in weblogic classpath will get loaded.

As mentioned earlier, although you can deploy Liferay DXP to a WebLogic Admin Server, you should instead deploy it to a WebLogic Managed Server. Dedicating the Admin Server to managing other servers that run your apps is a best practice. 
Follow these steps to deploy Liferay DXP to a Managed Server: 

1. Make sure the Managed Server you want to deploy Liferay DXP to, is shut down.

2.In your Admin Server’s console UI, select Deployments from the Domain Structure box on the left hand side. Then click Install to start a new deployment. 

3.Select the Liferay DXP WAR file or its expanded contents on your file system. It will take your domain patch already. Alternatively, you can upload the WAR file by clicking the Upload your file(s) link. Click Next

4.Select Install this deployment as an application and click Next.

5.Select the Managed Server you want to deploy Liferay DXP to, and click Next

6.If the default name is appropriate for your installation, keep it. Otherwise, give it a name of your choosing and click Next

7.Click Finish. After the deployment finishes, click Save if you want to save the configuration. 
8.Start the Managed Server you deployed Liferay DXP to. Liferay DXP precompiles all the JSPs, and then launches. 

When you will start managed server and if you you will get error for boot.properties, so again enter below details in booth.properties.
Username=weblogic username
For changing details in boot.properties, path is: 
Once it will show server is up. Liferay should also up. You can check from the below url that Lifray is also running

04 December, 2017

Login Authentication Solutions

Hello Friends,

This article will be helpful to you when you choose to customize login with various Liferay DXP supported authentication mechanism.
And this is almost common requirement for each implementations so I will provide all possible ways to customize login functionality based on my knowledge and provide solution.

1) Liferay OOB Login Customization
  • Custom Module implementation
2) Custom Authentication
  • Auto Login Basic Auth Header
  • Auto Login Request Header
  • Token Based SSO
  • Auto Login Request Parameter
3) SSO Login by Liferay supported SSO provider
  • Liferay + OpenSSO
  • Liferay + CAS
  • Liferay + NTLM
  • Liferay + LDAP
  • Liferay + OpenId
  • Liferay + Facebook (Facebook Connect)
  • Liferay + Google  (Google Authorization)
4) SAML Based SSO Login

19 July, 2017

REST Client OSGi Bundle

Hello Friends,

If you are planing to create HTTP REST client using OSGi, Just follow the steps.

1) Create bundle project of type API using IDE
2) Write one Class called RestClient.java
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
//import org.apache.commons.logging.LogFactory;

 * This example demonstrates how to create HTTP client for secure connection
 * context.
 * @author jignesh.vachhani
public class CustomHTTPClient {
private static final String username = "test";
private static final String password = "test";
private static final String host = "my.host.name";
private static final int port = 443;
private static final String protocol = "https";
static CloseableHttpClient httpclient = null;
static HttpHost targetHost = new HttpHost(host, port, protocol);

static HttpClientContext context = HttpClientContext.create();

public CustomHTTPClient() {
// Setting Credentials
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC),
new UsernamePasswordCredentials(username, password));

// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);

// Add AuthCache to the execution context
context = HttpClientContext.create();

httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();

static {
new CustomHTTPClient();

public final static void main(String[] args) throws Exception {
try {

boolean post = true;
boolean get = true;
if (post) {
HttpPost httpPost = new HttpPost(
String json = "{\r\n  \"email\": \"jigs.vachhani@gmail.com\"\r\n}";
StringEntity entity = new StringEntity(json);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");

CloseableHttpResponse response = httpclient.execute(httpPost);
try {

} finally {
if (get) {
HttpGet httpget = new HttpGet(
CloseableHttpResponse response = httpclient.execute(targetHost, httpget, context);
try {
HttpEntity entity = response.getEntity();

} finally {
} finally {


3) define below dependencies in build.gradle
dependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compileOnly group: "jstl", name: "jstl", version: "1.2"
    compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
    compile group: 'commons-codec', name: 'commons-codec', version: '1.9'
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.1'

4) In bnd.bnd
Bundle-Name: sample-rest-client
Bundle-SymbolicName: sample.rest.client
Bundle-Version: 1.0.0
Export-Package: \

Note : Below dependencies required in class path :

Just compile or deploy and you are done. Its simple  interesting isn't it ?

13 June, 2017

Captcha & reCaptcha with Liferay 7

If you are planning to integrate captcha in you liferay custom portlet then use below stuff

<%@taglib uri="http://liferay.com/tld/captcha" prefix="liferay-captcha" %>
<portlet:resourceURL id="/login/captcha" var="captchaURL"/>
<liferay-captcha:captcha url="<%=captchaURL%>" />

Write CaptchaMVCResourceCommand.java :

    property = {
    service = MVCResourceCommand.class
public class CaptchaMVCResourceCommand extends BaseMVCResourceCommand {

    public boolean serveResource(
        ResourceRequest resourceRequest, ResourceResponse resourceResponse) {

        try {
            CaptchaUtil.serveImage(resourceRequest, resourceResponse);
            return false;
        catch (Exception e) {
            _log.error(e, e);

            return true;

And you are done...

Make sure you use <liferay-captcha:captcha url="<%=captchaURL%>" />  instead of <liferay-ui:captcha url="<%=captchaURL%>" /> as its not support in custom module somehow.

23 November, 2016

Spring MVC Portlet Migration - DXP


Do you want to migrate your Spring MVC portlet into DXP ? yooo here are the steps you will have to follow to get it migrate.

Before we jump into steps, let me light up regarding spring mvc. Actually Spring MVC is purely used for web project architect and there is no any specific intention to get it convert into OSGi module jar. So here we may not be able to convert it into module jar but  such kind of portlets will get deployed as a war file only and Liferay container will convert into OSGi compatible WAB (Web Application Bundle) project by  Liferay WAB Generator.

Follow below steps to get it convert

22 November, 2016

Custom portlet configuration - DXP

Hello Folks,

Here I have tried to put all the possible steps which we would required to introduce custom portlet configuration.

1) Create new Liferay module using mvcportlet template
2) Define below highlighted property in your controller class:
        immediate = true,
        property = {

        service = Portlet.class
public class SamplePortletextends MVCPortlet {

3) Introduce custom interface for models with unique id as highlighted

            id = "com.sample.action.SamplePortletConfig "        )
        public interface SamplePortletConfig {
        deflt = "blue",
        required = false
    public String favoriteColor();

       deflt = "red|green|blue",
       required = false
    public String[] validLanguages();

    @Meta.AD(required = false)
    public int itemsPerPage();

Note :
  1. Meta.OCD: Registers this class as a configuration with a specific id. You can choose any string you want, but make sure it’s unique. A common pattern is to use the fully qualified class name.
  2. Meta.AD: Specifies the default value of a configuration field as well as whether it’s required or not. Note that if you set a field as required and don’t specify a default value, the system administrator must specify a value in order for your application to work properly. Use the deflt property to specify a default value.

4) Create custom config action class

        configurationPid = "com.sample.action.SamplePortletConfig",
        configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true,
        property = {
        service = ConfigurationAction.class
public class SamplePortletConfigAction extends DefaultConfigurationAction {

// processaction,render and include methods

5) Add below property in module bnd file
-metatype: *
 6) Introduce config.jsp with all possible fields which you want to configure

 Now check your configuration icon and see if custom configuration is available or not for that specific portlet.

Interesting right !!!!!!!  Enjoy Learning Osgi :)

Overriding classes and properties using OSGi - DXP

Hello Friends,

Here i have published all possible ways to override Liferay classes and properties for which we were using hook in older Liferay version.


1) Create Custom portlet data handler

        property = {
        service = PortletDataHandler.class
public class SamplePortletDataHandler extends BasePortletDataHandler
// Override methods which you required to override

2) Create Custom Model Listner

        immediate = true,
        service = ModelListener.class
public class LayoutModelListener extends BaseModelListener<Layout>
 // Override methods which you required

3) Create Custom workflow handler

        property = {"model.class.name=com.sample.model.SampleEntity"},
        service = WorkflowHandler.class
public abstract class SampleWorkflowHandler extends BaseWorkflowHandler
 // Override methods which you required

4) Custom Action

        property = {
            "javax.portlet.name=" + PollsPortletKeys.POLLS,
            "javax.portlet.name=" + PollsPortletKeys.POLLS_DISPLAY,
        service = MVCActionCommand.class
public class CustomMVCActionCommand  extends BaseMVCActionCommand
 // Override methods which you required

5) Custom Render

        property = {
            "javax.portlet.name=" + PollsPortletKeys.POLLS_DISPLAY,
        service = MVCRenderCommand.class
public class CustomActionMVCRenderCommand implements MVCRenderCommand
 // Override methods which you required

6) Override Liferay Language Properties

        property = { "language.id=en_US" },
        service = ResourceBundle.class
public class ENResourceBundleComponent  extends ResourceBundle {

    protected Object handleGetObject(String key) {
        return _resourceBundle.getObject(key);

    public Enumeration<String> getKeys() {
        return _resourceBundle.getKeys();

    private final ResourceBundle _resourceBundle = ResourceBundle.getBundle(
        "content.Language", UTF8Control.INSTANCE);

7) Override Liferay Module Language Properties

    immediate = true,
    property = {
public class ResourceBundleLoaderComponent  implements ResourceBundleLoader {

    public ResourceBundle loadResourceBundle(String languageId) {
        return _resourceBundleLoader.loadResourceBundle(languageId);

    @Reference(target = "(bundle.symbolic.name=com.liferay.polls.web)")
    public void setResourceBundleLoader(
        ResourceBundleLoader resourceBundleLoader) {

        _resourceBundleLoader = new AggregateResourceBundleLoader(
            new CacheResourceBundleLoader(
                new ClassResourceBundleLoader(

    private AggregateResourceBundleLoader _resourceBundleLoader;


8) Override Liferay services

@Component(service = ServiceWrapper.class)
public class CustomUserLocalService extends UserLocalServiceWrapper {
// Override methods which you require   

Portal-ext.prioperties cannot be override through OSGi and you will have to manually update portal-ext.properties which we are keeping inside WEB-INF/classes

Liferay MVC Portlet with Service Builder - DXP


Here you will see how you can create Liferay MVC portlet with best practice.

If you remember, we were creating portlets in 6.X by selecting specific portlet type from IDE and choosing weather we have to use service builder or not. So there it was creating only one single portlet including service layer.

Now in DXP, you will have to separately create service layer and web portlet layer .
Now here we will have to keep 2 things in our mind.
1) Portlet specific service layer
2) Generic service layer (Which can be used across all the modules)

Identically both are same and the way of accessing the service also would be the same only difference is, if service is portlet specific then you can keep service and web layer altogether in single module project which will help for CI and build whole project.

1) Now here first step would be create new Liferay module by selecting servicebuilder as template and create.

You can also create this portlet using blade-cli tool as well.
You can use below command to create if you have install blade-cli in your local.

11 November, 2016

Issues During 6.X to DXP migration

There are couple of common problem which we might facing during migration or upgration from 6.X to Liferay DXP.

We will discuss all possible items over here.

Create Servlet Project as Module

You would have seen that many times we are writing out own servlet in Liferay portal to achieve some specific use case. In DXP, You can st...