Return to Navigation

Sample Servlets

This section provides information about the sample servlets shipped with Online Marketing Extensions:

The HelloWorld servlet is a small extension you can use to test custom content extensions. The SampleLiveExtension servlet is designed to show some possibilities of the Online Marketing Extension architecture. Both are described in detail in this section.

The EXStockQuotes servlet, also included, is described briefly on page 94.

For all of the sample servlets, the class files are provided and are packaged in the jar file com.peoplesoft.crm.omk.examples.jar.

where selected_path is the pathname where you chose to install the files.

Note: The files exist on machines where Online Marketing Dialog Server or Mailcaster is installed.

The test Java servlet named HelloWorld can be used to test custom content extensions. The following shows the source for this servlet.

//******************************************************************/
//        Confidentiality Information:                              /
//                                                                  /
// This module contains confidential and proprietary information    /
// of PeopleSoft, Inc.; it is not to be copied, reproduced, or      /
// transmitted in any form, by any means, in whole or in part,      /
// nor is it to be used for any purpose other than that for         /
// which it is expressly provided under the applicable license      /
// agreement.                                                       /
//                                                                  /
// Copyright (c) 2000-2002 PeopleSoft, Inc. All Rights Reserved.    /
//******************************************************************/
/*--- formatted by Jindent 2.1, (www.c-lab.de/~jindent) ---*/

package com.peoplesoft.crm.omk.external;
import java.io.PrintWriter;

/**
* HelloWorld servlet simply outputs the string "Hello World!"
*/
public class HelloWorld extends GenericAnnuncioServlet
{
		/**
		* HelloWorld constructor.
		*/
		public HelloWorld()
		{
			super();
		}
		/**
		* Retrieves the servlet info string
		* @return String the servlet info string
		*/
			public String getServletInfo()
		{
			return ("HelloWorld, Annuncio Software, 4/2000");
		}
		/**
		* service method.
		*/
		public void service(javax.servlet.ServletRequest req, 	
		javax.servlet.ServletResponse res) 
				throws javax.servlet.ServletException, java.io.IOException
{
		PrintWriter out = res.getWriter();
		if (out != null)
	{
			out.print("Hello World!");
		}
		else
		{
			System.err.println("Can't get a PrintWriter.");
		}
	}
}
/*--- formatting done in "Annuncio Convention" style on 06-20-2000 ---*/

The SampleLiveExtension servlet is a custom content extension that builds HTML on a web page based on a content’s profile information. It shows how to achieve the following operations:

  • Pass parameters, including profile information, to a Online Marketing Extension

  • Retrieve external data to be merged into a document

  • Manage a cache to improve performance while ensuring thread safety:

    • Refresh mechanism

    • Access synchronization

  • Log error messages to the Online Marketing log files

This section is divided into the following subsections:

  • Audience: who should use this Online Marketing Extension?

  • Functionality: What the Online Marketing Extension does

  • Content storage: How the extension stores the content in files

  • Cache mechanism: Which rules determine the reloading of the content

  • Registering the extension: How to register the extension with the Online Marketing Dialog Server

  • Using the extension: How to build a simple dialog using this extension

Audience

The audience for this extension consists of users who want to understand Online Marketing Extensions and those who want to write them.

Warning! This extension is provided as an example only; it should never be used in a production dialog.

Functionality

The SampleLiveExtension servlet expects the following parameters:

Name

Description

path

The path where the files containing the content are stored. This parameter should be set in the Extension Registration's parameter list but can be overridden at the moment of the call.

firstName

The first name of the contact. This parameter should be merge content.

state

The state where the contact lives. This parameter should be merge content.

refresh

(Optional) Set this parameter to true if you want to force the data to be reloaded from the file and not read from cache. This parameter should be set in the Extension Registration's parameter list.

refreshTime

The content to display is refreshed every day at this time. If not specified or invalid, the default time used is midnight. This parameter must be defined in the Extension Registration's parameter list and cannot be overridden when you call the function. The allowed formats are HH:MM (24 hour format) or HH:MM AM|PM (12 hour format).

The servlet displays the following message:

  • A welcome message:

    • “Welcome!” if the first name of the contact is unspecified

    • “Welcome, <First Name>!” if the first name of the contact is known.

  • Data about the state given as a parameter:

    • If no state is specified, a detailed error message is displayed

    • If no data is available for that state, a detailed error message is displayed

    • If some data is available for that state, it is retrieved and displayed.

Content Storage

The servlet expects that the content is stored in files. The path of the files must be specified in the path parameter. File names should be in the following format:

<path_value>\<state_abbreviation>.txt

For example, if the path is equal to C:\states\ and the state is California, the data would be searched in the following file:

C:\states\CA.txt

The content of each state data file is expected to be a list of key/value pairs. The following keys are searched and merged into the document:

  • Population

  • Area

  • Senators

A valid file would look similar to this:

Population=33,145,121 inhabitants
Area=158,869 square miles
Senators=Barbara Boxer, Dianne Feinstein

All information available in the file will be displayed on the web page.

Cache Mechanism

To limit the number of disk accesses, the content of each file is kept in memory after being read. However, two mechanisms are implemented to allow the update of the data:

  • If the refresh parameter is set to true, any data in the cache is removed. The data to display will be automatically reloaded from the file and not pulled from the cache.

  • If the refreshTime has been crossed since the last loading of the data, the content is automatically refreshed from the file.

Note: The use of the refresh parameter only refreshes the cache on the Online Marketing component where the servlet is executed—this can be the Online Marketing Dialog Server (for web page content) or a Mailcaster (for email content).

Registering the Extension

Before you can use the SampleLiveExtension servlet, you must register it.

Note: The design of the SampleLiveExtension servlet is more appropriate for usage as a custom content extension within a web page. However, it can also be used as a custom content extension within an email. The following registration instructions allow the registration of the servlet on the Online Marketing Dialog Execution Server, which is used to display web page content. If you want to use the extension with email, you must register the function on all the Mailcasters. (In this case, Step 1 in the following instructions must be done only once in Extension Registration, but Steps 2 and 3 must be done for each component that will call the extension.)

Follow these instructions to register the servlet:

  1. Navigate to the Extension Registration Page for Java servlets and add the servlet SampleLiveExtension. Set the following parameter values within it:

    Name

    Value

    Servlet Class Name

    com.peoplesoft.crm.omk.external.CFlibrary.SampleLiveExtension

    path

    The path where you will store the files containing the content. You must include a final backslash (\) for Windows or slash (/) for Solaris, for example:

    C:\states\ 
    

    or

    /usr/foo/states/

    refreshTime

    The time when you want the content to be refreshed each day.

  2. Change the status to Active and save the changes.

  3. After you have finished, restart the Dialog Execution Server.

  4. If you are calling the extension from an email, restart the Mailcasters that will call this extension.

See Register the Extension in Online Marketing.

Using the Extension

One of the simplest dialogs that allows you to use the SampleLiveExtension servlet is composed of the following:

  • One landing page where the contact can submit personal information, including at least:

    • First name

    • Email address

    • State of residence

  • A final page containing a call to the Online Marketing Extension that will generate the whole content.

  • A web link to the landing page.

The call to the Online Marketing Extension would look like this:

<pstag:extension name="SampleLiveExtension"
 id="">

You can use the previous example as a model.

Hint: You can associate the refresh parameter with the value of a Yes/No document field on the landing field so you can easily see its effects.

After the files with the content have been created, you can set the dialog to Live (or In Test), generate a link report, and try out the functionality of the Online Marketing extension.

An additional sample servlet, EXStockQuotes, is also provided. It is similar to the SampleLiveExtension servlet.

You can use the EXStockQuotes servlet in three different ways within Online Marketing dialogs:

  • Insert it directly into broadcast or follow-up emails

  • Insert it directly into web documents

  • Insert it into the Content section(s) of a Dynamic Content object in an email document

In the third scenario the extension is used to retrieve content posted at an external URL, while the conditions specifying which content is to be displayed to whom are set up within the Dynamic Content object (in Online Marketing). Typically in this case, as in this sample, one or two parameters would be passed to retrieve the appropriate content. Each Content Section of the Dynamic Content object could have an extension inserted to retrieve content, or the Dynamic Content object could have a mix where some Content Sections have internally-stored content (content that is inserted or copy/pasted into the Content tab) while other Content Sections have an extension designed to retrieve content.