Developing a WebFOCUS Servlet Plug-in Activated by the WFEXT Setting

In this section:

How to:

A WebFOCUS Servlet WFEXT plug-in is a custom-written program which, when configured, can be called when the WebFOCUS Client is processing the request. It has access to cookies, headers, and request objects, including the query string. It can also populate the WebFOCUS Variable table.

This plug-in is enabled by specifying the fully qualified package and class name in the WFEXT setting in the General settings on the Configuration menu of the WebFOCUS Administration Console. In this class, you can define any number of methods which you can then call with the <call> methodname function described in How to Invoke the WebFOCUS Servlet WFEXT Plug-in. Calls to WFEXT plug-ins are normally placed in site.wfs.

When configured for the WebFOCUS Servlet, a pre-built WFEXT plug-in is configured for you with useful methods for pre-processing an HTTP request. For information on the WebFOCUS Servlet plug-in shipped with WebFOCUS, see Copying WebFOCUS Variables Using the WebFOCUS Servlet Plug-in.


Top of page

x
Procedure: How to Configure the WebFOCUS WFEXT Servlet Plug-in

To configure your WebFOCUS Servlet plug-in, you must set the WFEXT parameter to the fully qualified package and classname.

Perform the following steps:

  1. In the WebFOCUS Administration Console, select the General section of the Configuration menu and scroll down to the WFEXT variable.

    WebFOCUS administration concole dialog box

    By default, this variable is set to the package and classname of the plug-in supplied with WebFOCUS:

    ibi.webfoc.WFEXTDefault
  2. Change the value to the fully qualified name of the package and class that contains the methods you will be calling with the <CALL> method name.
  3. Click Save to save your changes.
  4. Install the plug-in .jar or class file. The class file containing the plug-in must be in the classpath of the Application Server.

Note: The plug-in class is loaded once per WebFOCUS Servlet instance.


Top of page

x
Processing a Request Between the WebFOCUS Client and the Browser

How to:

Reference:

This section outlines the method signature required to create a WebFOCUS Servlet WFEXT plug-in, public class classname (for example, WFSamplePlugin).

Note: Only one WFEXT plug-in can be enabled. You should extend ibi.webfoc.WFEXTDefault if you wish to develop new methods that can be used in combination with those supplied in the built-in WFEXT plug-in.



x
Reference: Constructor Detail
public WFSamplePlugin()

Constructor for WFSamplePlugin. There is only one instance of the WFEXT plug-in object per Servlet. This object is instantiated when the plug-in method is called for the first time.



x
Reference: Method Detail

Method:

public long method(java.lang.String[] newvars,
javax.servlet.http.HttpServletRequest req)
java.lang.String parm1...
method
method

Is the name of the routine to be called.

Parameters:

newvars

Is the buffer that is used to return new or updated WebFOCUS script variables. Although this parameter is an array of String variables, only the first element in the array is used. Element zero [0] can be used to specify a series of name equal value pairs that are separated with an ampersand. The WebFOCUS script variable table receives this and those variables can be used in subsequent request. The newvars format is as follows:

name1=value1&name2=value2&name3=value3

where:

name1,name2,name3 are the names of WFS variables.

value1,value2,value3 are the values for those named variables.

& is the delimiter used to separate variable value pairs from the next variable name.

req

Is the user defined request object used to integrate parameters in the HTTP request buffer (for example, sessions).

parm1...

Defines input parameters. This is an optional parameter. You can pass as many parameters as necessary.

Returns:

Status Code returned by method as an 8-byte integer. This populates the WebFOCUS script variable table with a value for the variable named RETCODE, which can be checked to determine whether the plug-in function succeeded or failed. A common WFS convention is to use a value of 0 to indicate success.



x
Syntax: How to Invoke the WebFOCUS Servlet WFEXT Plug-in

The following command invokes the WebFOCUS Servlet WFEXT plug-in

<CALL> method(parm1...)<if> RETCODE NE "returncodevalue"
...
<endif>

where:

<CALL>

Is the command that invokes the WebFOCUS Servlet plug-in method.

method

Defines the name of the actual method to be called (for example, getSession).

(parm1...)

Are the optional parameters of the WebFOCUS Servlet plug-in. There is no limit to the number of input parameters that may be used by the WebFOCUS Servlet plug-in. The output buffer is not passed in as a parameter in this statement.

RETCODE

Is the status of the method call.

returncodevalue

Is the value you are comparing with what the plug-in returns (for example, 0).

Note: For more information about WFS commands that can be placed within the call to this plug-in, see Manipulating WebFOCUS Variables.



Example: Sample WebFOCUS Servlet WFEXT Plug-in

The following is a sample WebFOCUS Servlet plug-in that extends the default WFEXT plug-in so that its predefined methods can continue to be used in a WebFOCUS script.

This sample provides a method named getKeyValue() that searches for a token (key name) in a text file and returns its corresponding value which is also stored in the text file. The format of the text file has a single name and value pair separated by a comma per line. For example:

Name1, Value1
Name2, Value2
Name3, Value3

When the getKeyValue() method is called by the WebFOCUS script, the script must pass three parameters to the method. The parameters are keyName (Name of key to search for), returnValueName (Name of WebFOCUS script variable that contains the corresponding key value), and file_name (Name of the text file with the Name Value pairs).

The following is the sample WebFOCUS Servlet WFEXT plug-in, called ibiSampleExit. The source and class files can be found in the/ibi/WebFOCUS/samples/wfplugins/lookup/ directory.

/*
 * ibiSampleExit.java
 *
 */
// Returns 0 ; Success ; Key name and Value found
// Returns 1 ; Key name and Value not found
// Returns 2 ; Java Exception has occurred ; view app server log for  detail
// package customer.webfocus.exit
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ibiSampleExit extends ibi.webfoc.WFEXTDefault
{
  public ibiSampleExit()
  {
  }
  public long getKeyValue(String[] NewVars, HttpServletRequest req,
                          String keyName, String returnValueName,
                          String file_name)
  {
    try
      {
      FileInputStream fis = new FileInputStream(file_name);
      BufferedReader br = new BufferedReader(new InputStreamReader(fis));
      String line = "";
      while((line = br.readLine()) != null)
      {
        if (line.toLowerCase().indexOf(keyName.toLowerCase()) != -1)
        {
          StringTokenizer st =new StringTokenizer(line," ,");
          if ((st.hasMoreTokens() == true) &&
              (st.nextToken().compareToIgnoreCase(keyName)==0))
          {
            NewVars[0] = (st.hasMoreTokens()) ?
                         returnValueName+"=" + st.nextToken():
                         null;
            // Syntax for NewVars[0]:
            // Variable=abc&Variable2=xyz&Variable3=value
            fis.close();
            return 0;
          }
        }
      }
      fis.close();
    }
    catch (Exception e)
    {
      System.out.println(e);
      return 2;
    }
    return 1;
  }
}

To implement this sample WebFOCUS Servlet WFEXT plug-in, perform the following steps:

  1. Configure the sample WebFOCUS Servlet WFEXT plug-in (see How to Configure the WebFOCUS WFEXT Servlet Plug-in) by specifying ibiSampleExit for the WFEXT setting, as shown in the following image.

    WFEXT setting dialog box

  2. Copy the /ibi/WebFOCUS/samples/wfplugins/lookup/ibiSampleExit class to a directory that is in the CLASSPATH of the Application Server. For example, when your context document base for /ibi_apps comes from the open directory structure (not the .war file), you can copy the class file to /ibi/webfocus/webapps/webfocus/web-inf/classes.
  3. Invoke the sample WebFOCUS Servlet WFEXT plug-in by following the steps outlined in How to Invoke the WebFOCUS Servlet WFEXT Plug-in.
  4. Type and then save the following code into site.wfs (accessible in the WebFOCUS Administration Console by clicking Configuration and then Custom Settings) to apply it to an environment that uses DBA security in Master Files. You can cut and paste this code from /ibi/WebFOCUS/samples/wfplugins/lookup/site.wfs.
    <if> IBIMR_action EQ "MR_SIGNON"
      TRESULT = LOOKUPVALUE
      TPATH = &IBI_DOCUMENT_ROOT/config/ibi_sample_exit.txt
      <call> getKeyValue(IBIMR_user, TRESULT, TPATH)
      <if> RETCODE EQ "0"
        httpsession = _dbapassword
        <call> CopyWFVarToSessionVar(LOOKUPVALUE,httpsession)
      <endif>
    <else>
        wfvar = DBAPASS
        httpsession=_dbapassword
        <call> CopySessionVarToWFVar(httpsession,wfvar)
        <if> RETCODE NE "0"
          DBAPASS=ERROR
        <endif>
    <endif>
  5. Set IBIF_dbapass_src to WebFOCUS Variable with a value of DBAPASS for the variable name. To access this setting in the WebFOCUS Administration Console, click Configuration and then Managed Reporting (located under Client Settings).

    MR Client Settings dialog box

  6. Copy the /ibi/WebFOCUS/samples/wfplugins/lookup/ibi_sample_exit.txt to the /ibi/WebFOCUS/config directory. This text file lists Managed Reporting user IDs and their corresponding DBA group (group1 or group2). For example:
    bob, group1
    mary, group2
    user1, group1
  7. Rename /ibi/apps/ibisamp/car.mas to car.mas.original and then copy /ibi/WebFOCUS/samples/wfplugins/lookup/car.mas to the ibisamp directory. The new car.mas differs from the original due to the following lines appended to the end:
    END
    DBA=JONES76,$
    USER=admin_pass, ACCESS=R, $
    USER=group1, ACCESS=R, RESTRICT=VALUE, NAME=ORIGIN,
     VALUE=COUNTRY EQ 'JAPAN', $
    USER=group2, ACCESS=R, RESTRICT=VALUE, NAME=ORIGIN,
     VALUE=COUNTRY EQ 'ENGLAND', $

WebFOCUS