The Web Services for Remote Portlets (WSRP) specification defines a web service interface for accessing and interacting with presentation-oriented web services in the form of portlets. What are presentation-oriented web services? These are web services that send user interfaces over the wire, rather than raw data like JSON objects or SOAP data envelopes. If an application is written as a portlet, this is an easy way to expose that application to end users on a completely different system, rather than sending just the data and having to craft an application to present that data. WSRP’s presentation-oriented web services allow portals to display remote portlets inside their pages, as if locally deployed, without requiring any additional programming by developers.
Here are the two main components for WSRP:
Producer: A web service that exposes one or more portlets and is described using a Web Services Description Language (WSDL) document.
Consumer: A web service client that receives the data from the Producer and presents it to the user in a portlet window.
Below, you’ll see how the components interact with each other. So without further ado, let’s explore WSRP in Liferay DXP!
Liferay DXP provides a deployable WSRP portlet that supports the 1.0 and 2.0 specifications. The portlet is available from Liferay Marketplace as a CE or EE app. Once you’ve downloaded and installed the WSRP app, you have instant access to the portlet by navigating to the Control Panel and, under Configuration, selecting WSRP Admin.
Liferay DXP can be used as a WSRP producer or consumer. As a producer, it hosts portlets that are consumed by other portal servers (Liferay or non-Liferay) acting as WSRP consumers. The image below illustrates WSRP producers and consumers and how they interact.
Let’s go through the basic process of how producers and consumers work together to bring the end user a remote portlet. First, the consumer portal server establishes a connection with its producer portal server counterpart. This connection is made possible by giving the consumer the producer web service’s URL. The consumer then uses the URL to discover the producer’s portlets and establish a connection. After the connection is made, the consumer acquires the producer’s information and creates a consumer proxy portlet. The proxy portlet acts as an intermediary, relaying requests to and from the end user and the producer’s portlet.
For example, you can compare the proxy portlet to a TV satellite box. If you want to change the channel on your TV, you (end user) send the channel number you desire to the TV’s satellite box (consumer’s proxy portlet) via your TV’s remote. When the satellite box receives the request to change the channel, it relays the request to a TV satellite (producer’s portlet) which then sends the channel information back to the satellite box. Then, the satellite box displays the new channel to you on your TV. In this simple example, you’re not directly requesting the TV satellite to change the channel, but rather, you’re communicating with the satellite box, which acts as an intermediary between you and the satellite. This example directly relates to using WSRP with Liferay. Although the end users are sending requests to the consumer portlet, they’re not receiving feedback from the consumer portlet itself, but rather its producer portlet located remotely.
Now that you know a little bit about the WSRP process, let’s begin configuring WSRP on Liferay DXP. For this demonstration, you’ll assume you have two portal servers.
To create a producer, go to the Producers tab and click the Add icon
Name your producer
Hello World Producer and choose the appropriate version of
WSRP to use. Liferay displays a list of available portlets your producer can
use. For demonstration purposes, select the Hello World portlet and click the
Save button. The portal generates a WSDL document to define your producer. You
can copy the WSDL document URL for accessing the producer in a consumer.
Now that you’ve created a producer, let’s create a consumer on your second portal server.
On your consumer portal server, navigate to the WSRP Admin page. Select the Consumers tab and click the Add icon (). Give the consumer a name and add the producer’s WSDL URL in the URL field. There are also additional fields:
Forward Cookies: Allows the WSRP consumer to forward specific cookies from the user’s browser session to the WSRP producer.
Forward Headers: Allows the WSRP consumer to forward specific HTTP headers from the user’s browser session to the WSRP producer.
Markup Character Sets: Markup character encodings supported for the consumer are shown in a comma delimited list. UTF-8 is assumed and is added automatically as a supported encoding.
Leave these additional fields blank for our demonstration. Lastly, you need to define the portlets that the end-user can use from this consumer. To do this, click the consumer’s Actions icon () and select Manage Portlets. The Manage Portlets screen appears.
The producer’s remote portlets are available to add to your consumer. To add the Hello World remote portlet, click the Add icon () The New Portlet screen appears. Select the Hello World remote portlet in the Remote Portlet field and give the consumer’s new portlet an arbitrary name. Then click Save. Now end users can “consume” or use the remote portlet just like any local portlet in the portal.
Next, you’ll learn how to create custom remote portlets.
With the demand for dynamic portlets by end users, sometimes a finite, pre-selected list of remote portlets isn’t enough. Because of this, Liferay DXP allows you to make custom developed portlets remotely accessible for WSRP.
To enable your custom portlet for WSRP, add the
tag in your portlet’s
<liferay-portlet-app> <portlet> <portlet-name>RemoteSamplePortlet</portlet-name> <remoteable>true</remoteable> ... </portlet> ... </liferay-portlet-app>
After editing your portlet’s
liferay-portlet.xml file, your custom portlet
appears in the list of portlets available to WSRP producers. Congratulations!
Now you can share all your portlets to end users using WSRP!
Next, you’ll learn how to remotely access Liferay services.