Create an Encoder/Decoder

This tutorial describes how to implement the Data Format Extension API to handle data format extensions.

To learn more about the implementation of the Data Format Extension API in NeoLoad, see Data Format Extension requests. Or get more details about the Data Format Extension API architecture.

Use case environment

The use case presented in this tutorial was performed in the following environment:

  • Computer on Windows 7 with an Administrator account

  • Java Development Kit version 7

  • Eclipse for Java developers launched with Administrator privileges

  • NeoLoad 5.0 and above

Create a Java project to implement the Data Format Extension API

This section describes how to create a Java project with Eclipse to implement the Data Format Extension API provided by Neotys.

To create a Java project to implement the Data Format Extension API, follow these steps:

  1. Create a workspace in Eclipse.

  2. Select the New > Java Project command.

    The New Java Project dialog appears.

  3. Enter a name for the project in Project name and click Finish.

  4. Open the Properties for my project dialog.

  5. Select the Java Build Path property.

  6. Click the Add JARs button and browse to the JAR files available in the NeoLoad installation directory:

    • <install-dir>\api\Data Format Extension API\Java\neotys-codec-api-1.0.4.jar

    • the files in the <install-dir>\api\Common\Java folder

  7. Click OK to save the project.

The Java project is ready to create an implementation of the Data Format Extension API.

Attach the API source in Eclipse

This section describes how to attach the sources of the public API provided. The sources are provided in the NeoLoad installation directory as a JAR file:

<install-dir>\api\Data Format Extension API\Java\neotys-codec-api-1.0.4-sources.jar

To , follow these steps:

  1. Open the Java project in Eclipse.

  2. Right-click the neotys-codec-api-1.0.4.jar file and select Properties.

  3. Select the Java Source Attachment property.

  4. Check the External location option and click the External File button to select the file <install-dir>/api\Data Format Extension API\Java\neotys-codec-api-1.0.4-sources.jar.

  5. Click OK to validate the attachment.

    The sources are attached and you can read the Javadoc and the API source code.

Implement and declare the binder in a Java project

This section describes how to implement and declare the binder of the Data Format Extension API in a Java project.

In Eclipse, a new Java project must be created to implement the public Codec API. A new META-INF/services sub-directory must be created in the src directory.

In the META-INF/services sub-directory, a file called com.neotys.extensions.codec.AbstractBinder must be created.

Below src, a Java package must be created with a custom name, e.g. com.neotys.codec.sample.

An implementation of the com.neotys.extensions.codec.AbstractBinder abstract class must be created in the new Java package.

The Name of the new Java Class is free, e.g. MyBinder.

A click on Finish validates the project.

For more information about the implementation of the class com.neotys.extensions.codec.AbstractBinder, it is useful to read its Javadoc.

The com.neotys.extensions.codec.AbstractBinder must be declared in META-INF/services/com.neotys.extensions.codec.AbstractBinder. The file must be edited and the line com.neotys.codec.sample.MyBinder must be inserted.

The MyBinder declaration is finished. MyBinder can be detected now by NeoLoad as an implementation of com.neotys.extensions.codec.AbstractBinder. The bindings defined in MyBinder can be used by NeoLoad.

To implement and declare the Binder in a Java project, follow these steps:

  1. Create a Java project to implement the API.

  2. In the src directory, create a META-INF/services sub-directory.

  3. In META-INF/services, create a file com.neotys.extensions.codec.AbstractBinder.

  4. Create a Java package.

  5. In the Java package, create an implementation of the abstract class com.neotys.extensions.codec.AbstractBinder.

  6. To declare the class, edit the file com.neotys.extensions.codec.AbstractBinder and insert a line with the name of the Java package.

    NeoLoad can now detect the Binder as a implementation of com.neotys.extensions.codec.AbstractBinder.

Create a decoder and link it to the binder

This section describes how to create a Decoder and link it to the Binder.

In Eclipse, a class must be created to implement the interface com.neotys.extensions.codec.functions.Decoder.

The Name of the Java class can be a custom one, e.g. MyDecoder.

A click on Finish validates the new MyDecoder class.

It is now necessary to link MyDecoder to MyBinder.

For example, when a request is received while recording, the contenu of the request body is decoded with MyDecoder.

To create a Decoder and link it to the binder, follow these steps:

  1. In New Java Class, create a class to implement com.neotys.extensions.codec.functions.Decoder.

  2. Click Finish.

  3. Link the Decoder class to the Binder.

Create and link an Encoder

This section describes how to create and link a Encoder.

In Eclipse, a class must be created to implement the interface com.neotys.extensions.codec.functions.Encoder.

The Name of the Java class can be a custom one, e.g. MyEncoder.

Clicking on Finish validate the new MyEncoder class.

It is now necessary to link MyEncoder to MyBinder.

For example, every object generated by the decoders is encoded by MyEncoder.

To create and link an Encoder, follow these steps:

  1. In New Java Class, create a class to implement com.neotys.extensions.codec.functions.Encoder.

  2. Click Finish.

  3. Link the Encoder class to the Binder.

Export a project in a JAR file

This section describes how to create a Java project to implement the Data Format Extension API.

  1. In Eclipse, right-click the Java project and select Export.

  2. Browse to Java > JAR file and click Next.

  3. In the JAR Export screen, browse to the JAR file where you want to export the project in Select the export destination.

  4. Click Finish to validate the export.

The JAR which contains the API implementation is now exported and ready to be used in NeoLoad. For more information, see Data Format Extensions.

To create a Java project and implement the Data Format Extension API, follow these steps:

  1. In Eclipse, right-click the Java projet and select Export.

  2. Select Java, then JAR file, and click Next.

  3. Select the target directory, and click Finish.

  4. You can specify the JAR file in NeoLoad.

Debug the API implementation in Eclipse

To debug the API implementation in Eclipse, it is necessary to have:

  • Eclipse, Java JDK, and NeoLoad installed on the machine,

  • the JAR including the compiled sources of the Java project to debut specified in NeoLoad, as described in Data Format Extensions.

The following procedures require advanced Java programming skills. If the configuration is inaccurate, NeoLoad may not start properly.