Upgrading a Servlet-based Portlet

Servlet-based portlets have little overhead and are easy to upgrade. This tutorial shows you how to upgrade them and refers to code from before and after upgrading a sample servlet-based portlet called Sample JSON (project sample-json-portlet). The portlet shows a Click me link. When users click the link, the Liferay logo appears.

Figure 1: The Sample JSON portlet displays text stating Click me that you can click to initiate an action.

Figure 1: The Sample JSON portlet displays text stating *Click me* that you can click to initiate an action.

To get the most from this tutorial, you can download and refer to the original sample portlet source code and the upgraded source code.

Here are the sample portlet’s characteristics:

  • Processes requests using a servlet that extends javax.servlet.HttpServlet
  • View layer implemented by JSPs
  • Processes data using JSON objects
  • Relies on manual dependency management
  • Depends on third-party libraries that Liferay Portal 6.2 provides
  • Embeds additional dependencies in its WEB-INF/lib folder
  • Developed in a Liferay Plugins SDK 6.2

Follow these steps to upgrade a servlet-based portlet:

  1. Adapt the code to Liferay DXP 7.0’s API

  2. Resolve dependencies

The Upgrade Planner makes adapting a portlet’s code straightforward, and it automates much of the process.

The sample portlet relied on Liferay Portal to provide several dependency JAR files. Here’s the portal-dependency-jars property from the portlet’s liferay-plugin-package.properties file:

portal-dependency-jars=\
    dom4j.jar,\
    jabsorb.jar,\
    json-java.jar

Instructions for using packages that Liferay DXP exports are found here. Liferay DXP 7.0’s core system exports the package this portlet needs from each of the above dependency JARs.

The upgraded sample portlet continues to specify these JARs in the portal-dependency-jars property. They’re made available to the portlet at compile time. But to avoid packages from compile time conflicting with the core system’s exported packages, the Liferay Plugins SDK 7.0 excludes the JARs from the plugin WAR.

Next, deploy your portlet as you always have.

The server prints messages that indicate the following portlet status:

  • WAR processing
  • WAB startup
  • Availability to users

The portlet is installed to Liferay DXP’s OSGi runtime and is available to users.

Figure 2: Clicking on the sample portlets Click me link shows the Liferay logo.

Figure 2: Clicking on the sample portlet's *Click me* link shows the Liferay logo.

Congratulations! You’ve upgraded and deployed your servlet-based portlet to Liferay DXP 7.0.

Related Topics

Migrating Plugins SDK Projects to Workspace and Gradle

Using Dependency Management Tools

Using the WAB Generator

Migrating Data Upgrade Processes

« Upgrading a GenericPortletUpgrading a Liferay MVC Portlet »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています