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.

upgrading-portlets-sample-servlet-json-initial-view.png

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 Portal CE 7.0’s API

  2. Resolve dependencies

The Code Upgrade Tool 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 Portal exports are found here. Liferay Portal CE 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 Portal’s OSGi runtime and is available to users.

upgrading-portlets-sample-servlet-json.png

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 Portal CE 7.0.

Related Topics

Migrating Plugins SDK Projects to Workspace and Gradle

Using Dependency Management Tools

Using the WAB Generator

Migrating Data Upgrade Processes

0 (0 Votes)
Upgrading a GenericPortlet Previous