Implementation > Electronic Signature > Developing exits for Electronic Signature

Developing exits for Electronic Signature

About the exit framework

Overview

In the main use case of Electronic Signature, a signer user can sign or reject a payment. To enable you to add specific post-processing behavior in this use case (for example, adding a payload in a specific archiver, generating a signature proof, and so on), Electronic Signature provides an Exit Framework as an API.

This framework is an asynchronous events dispatcher. When a payment is signed or rejected, a corresponding event is created and placed in a persisted queue. A periodic timer dispatches all these events to the registered implementation of the API. After being dispatched, an event is removed from the queue. For each event a post-processor instance is launched which enables you to post-process several events simultaneously. As such, the exit is not processed immediately after the signature or rejection action.

The success or failure of the post-processing is of no significance to the framework. It only ensures that all the events are correctly dispatched to post-processors. The error management is in charge of the exit implementation that you develop.

Description of exit framework API

There are two kinds of event: Sign Event and Reject Event. Each one is dispatched to a specialized class of post-processing: SignExitOperation and RejectExitOperation. An event is a set of properties such as payment signer, received date, payment number and so on. A property is defined by a unique String key and a value which together constitute a Java Object. The list below describes the main interfaces and classes of the API. For more information, refer to the Exit API Javadoc.

The main interfaces and classes of the API are:

Development

Prerequisites

Electronic Signature provides a sample implementation of the Exit Framework. This sample is developed in JAVA and its environment based on Maven and Eclipse.

Oracle Java™

  1. Installation
    1. Download Oracle Java™ JDK6 from: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-download-346242.html.
    2. Install Oracle Java™ JDK6 on your system.
    3. Accept the License Agreement and select a delivery in the list for your platform.
  2. Setting the path
  3. Set up your path environment variable:

Windows

  1. Right-click the Computer Icon on your desktop and click Properties.
  2. If using Windows 7, in the ControlPanel, select Advanced System Settings on the left.
  3. In the System Properties window, click the Advanced tab then click Environment Variables.
  4. Create a new User Variable by clicking New.
  5. Name it JAVA_HOME and set the value to the Java™ installation directory path, usually in C:\Program Files\Java\jdk1.6.XXX if you didn’t specify another location.
  6. Note that the XXX represents the version of your Java™ installation.
  7. Click OK.
  8. Go to the Systems Variables list and select the variable named PATH. Then click Edit.
  9. At the end of the value line add: ";%JAVA_HOME%\bin". ( Without the " and don’t forget the ; at the beginning ).

Linux

To set up the PATH on a Linux system, edit the file ~/.bashrc. Add the following lines at the end of the file:

export JAVA_HOME=<YOUR_JAVA_INSTALL_DIR>

export PATH=$PATH:$JAVA_HOME/bin

Apache Maven

The sample is packaged with Apache Maven.

  1. Go to http://maven.apache.org/download.html.
  2. Select a Maven version 2.2.1 in the Mirrors list and download it.
  3. To install Maven, go to http://maven.apache.org/maven-1.x/start/install.html. For Linux users, remember to define your MAVEN_HOME and add it to the PATH, see Setting the PATH.

Eclipse

The sample is packaged for Eclipse IDE. If you don’t have it:

  1. Download the Classic distribution from: http://www.eclipse.org/downloads/.
  2. Select your platform and select a mirror.
  3. The download starts.
  4. Unzip the Eclipse Archive file wherever you want.
  5. The executable eclipse file is <ECLIPSE_INSTALL_DIR>/eclipse/eclipse.

Developing exits

Getting Started

In your development environment, make sure you are using Java 1.6 and Maven 2. After creating your project add the following jars into your build path:

Now you can start your development. If you want to create a post-processing of a signature, create a class which extends SignExitOperation (or for a reject post-processing extend RejectExitOperation).

Then override the following methods:

@Override

public void setEvent(HashMap<String, Object> event) {

/*

* This method is called by Electronic Signature to send the event to your IExitOperation.

* At least you should store the event.

*/

}

@Override

public void executeSignPostProcessing() { // Or executeRejectPostProcessing() for a RejectExitOperation.

/*

* This method is called by Electronic Signature after setEvent.

* Put your custom post-processing there.

*/

Remember: all implementations are, in fact, stateless as an instance of your IExitOperation is created for each event. Remember to ensure thread safety. Several instances of your IExitOperation may run at the same time in different threads.

You can pack several IExitOperation in the same jar. However, only one SignExitOperation class and only one RejectExitOperation class will be loaded in Electronic Signature.

Note that the runtime directory of Electronic Signature (and that of your implementation) is <ELECTRONIC_SIGNATURE_INSTALL_DIR>.

Installing and configuring exit implementation in Electronic Signature

  1. Place your jar and all its dependencies in <ELECTRONIC_SIGNATURE_INSTALL_DIR>/lib without the Exit API jars, Sentinel API jar and log4j.
  2. You may have to place your resource dependencies in <ELECTRONIC_SIGNATURE_INSTALL_DIR>/ (as with your configuration files).
  3. To configure Electronic Signature to run your implementation, open the configuration.properties file located in <ELECTRONIC_SIGNATURE_INSTALL_DIR>/conf.
  4. Navigate to the Exit Configuration part:
  5. ######################################

    #### Exit Configuration ####

    ######################################

    # frequency of exit scanner, default 60 seconds

    # the value is in milliseconds

    exit.pollingFrequency=60000

    # size of the thread pool used for reject exit processing

    exit.reject.thread.pool.size=2

    # size of the thread pool used for sign exit processing

    exit.sign.thread.pool.size=5

    # activate the reject exit post-processing

    exit.useReject=false

    # the name of the implementation class of the reject exit

    exit.reject.classname=

    # the classpath with all the dependencies of the reject exit

    # all jars must be separated by ; example: file:jars/signExit.jar;file:lib/dependency1.jar;file:lib/dependency2.jar

    exit.reject.classpath=

    # activate the sign exit post-processing

    exit.useSign=false

    # the name of the implementation class of the sign exit

    exit.sign.classname=

    # the classpath with all the dependencies of the sign exit

    # all jars must be separated by ; example: file:jars/signExit.jar;file:lib/dependency1.jar;file:lib/dependency2.jar

    exit.sign.classpath=

Now you can run Electronic Signature and test your implementations.

Electronic Signature provides a sample of Exit API implementations.

Sample exit

Overview

The sample is provided by the Electronic Signature installation. It is located in <ELECTRONIC_SIGNATURE_INSTALL_DIR>/devKit/exit/.

Importing a sample project into Eclipse

  1. Open a terminal and go to <ELECTRONIC_SIGNATURE_INSTALL_DIR>/devKit/exit/.
  2. Run mvn eclipse:eclipse.
  3. This generates the .classpath and the .project files.
  4. Import it into Eclipse using the import menu.
  5. Set the root directory of the project to <ELECTRONIC_SIGNATURE_INSTALL_DIR>/devKit/exit/.

Building the sample

  1. Open a terminal and go to <ELECTRONIC_SIGNATURE_INSTALL_DIR>/devKit/exit/,
  2. Launch an mvn clean install.
  3. This builds the sample and at the end of the building phase you should find a target directory with the following:

Sample description

The following sample contains two different implementations:

Both are located in <ELECTRONIC_SIGNATURE_INSTALL_DIR>/devKit/exit/src/main/com/axway/fex/es/exit/sample.

Installing the sample in Electronic Signature

  1. Unzip the delivery archive generated during the build.
  2. This generates a fex-es-exit-sample-XXX directory.
  3. Copy all its subdirectories (lib/, doc/ and conf/) to <ELECTRONIC_SIGNATURE_INSTALL_DIR>.
  4. Configure the code in Electronic Signature in the directory <ELECTRONIC_SIGNATURE_INSTALL_DIR>/conf/configuration.properties.
  5. Replace it with the following code in the Exit configuration part:
  6. exit.useReject=true

    exit.reject.classname= com.axway.fex.es.exit.sample.RejectSentinelNotifier

    exit.reject.classpath= file:lib/fex-es-exit-sample-XXX.jar

     

    exit.useSign=true

    exit.sign.classname=com.axway.fex.es.exit.sample.XMLProofSignature

    exit.sign.classpath=file:lib/fex-es-exit-sample-XXX.jar

  7. Start Electronic Signature.

Related topics

Configuring Electronic Signature