Java client

First instantiate a DataExchangeAPIClient providing a URL, Context, and API key.

Then call the method addEntry() to send one Entry at a time or the method addEntries() to send more than one Entry at a time.

Configure the project

To configure your Java project, it is recommended to use Maven.

Maven projects

In a Java Maven project, you need to add a dependency to the Maven settings file (pom.xml) using the examples below.

Repository:

Copy
<repositories>
    <repository>
    <id>neotys-public-releases</id>
     <url>http://maven.neotys.com/content/repositories/releases/</url>
           <releases><enabled>true</enabled></releases>
     <snapshots><enabled>false</enabled></snapshots>
    </repository>
</repositories>

Dependency:

Copy
<dependencies>
    <dependency>
        <groupId>com.neotys.rest</groupId>
        <artifactId>neotys-rest-api-dataexchange-client-olingo</artifactId>
        <version>1.0.4</version>
    </dependency>
</dependencies>

Non-Maven projects

If your project is not developed using Maven, it is necessary to include the JAR files available in the \api folder of the NeoLoad installation directory:

Create the Java Data Exchange API client

To use our Java API to inject external data into NeoLoad, use our classes to create Context and Entry objects.

The following code results in one path being sent to the NeoLoad Data Exchange API. A new Entry is created each second for 100 seconds.

Example 1

import java.util.Arrays;
import com.neotys.rest.dataexchange.client.DataExchangeAPIClient;
import com.neotys.rest.dataexchange.client.DataExchangeAPIClientFactory;
import com.neotys.rest.dataexchange.model.ContextBuilder;
import com.neotys.rest.dataexchange.model.EntryBuilder;
public class DataExchangeAPIExample {
    public static void main(String[] args) throws Exception {
        final ContextBuilder cb = new ContextBuilder();
        cb.hardware("example hardware").location("example location").software("example software")
            .script("example script " + System.currentTimeMillis());
        final DataExchangeAPIClient client = DataExchangeAPIClientFactory.newClient("http://localhost:7400/DataExchange/v1/Service.svc/", 
                cb.build(), "apiKeyToSend");
        for (int i = 0; i < 100; i++) {
            Thread.sleep(1000);
            final EntryBuilder eb = new EntryBuilder(Arrays.asList("_ScriptName_", "Entry", "Path"), System.currentTimeMillis());
            eb.unit("units");
            eb.value((double) i);
            client.addEntry(eb.build());
            System.out.println("DataExchangeAPIExample.main() sent entry with value " + i);
        }
    }
}

Example 2

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import com.neotys.rest.dataexchange.client.DataExchangeAPIClient;
import com.neotys.rest.dataexchange.client.DataExchangeAPIClientFactory;
import com.neotys.rest.dataexchange.model.ContextBuilder;
import com.neotys.rest.dataexchange.model.Entry;
import com.neotys.rest.dataexchange.model.EntryBuilder;
import com.neotys.rest.dataexchange.model.Status.State;
import com.neotys.rest.dataexchange.model.StatusBuilder;
public class DataExchangeAPIExample2 {
    /** Generate pseudo-random numbers. */
    private static final Random RANDOM = new Random(System.currentTimeMillis());
    public static void main(String[] args) throws Exception {
        final List<Entry> entriesToSend = new ArrayList<>();
        final ContextBuilder cb = new ContextBuilder();
        cb.hardware("example hardware").location("example location").software("example software")
            .script("example script " + System.currentTimeMillis());
        final DataExchangeAPIClient client = DataExchangeAPIClientFactory.newClient("http://localhost:7400/DataExchange/v1/Service.svc/", 
                cb.build(), "apiKeyToSend");
        for (int i = 0; i < 100; i++) {
            Thread.sleep(1000);
            // create a status.
            final StatusBuilder sb = new StatusBuilder();
            sb.code("any string " + i);
            sb.message("any string " + i);
            if (RANDOM.nextInt(100) >= 9) {
                sb.state(State.PASS);
            } else {
                sb.state(State.FAIL);
            }
            // create an entry.
            final EntryBuilder eb = new EntryBuilder(Arrays.asList("_ScriptName_", "Entry", "Path"), System.currentTimeMillis());
            eb.unit("units").value((double) i).url("http://www.neotys.com").status(sb.build());
            entriesToSend.add(eb.build());
            System.out.println("DataExchangeAPIExample2.main() stored entry with value " + i);
        }
        // send the entries.
        client.addEntries(entriesToSend);
        System.out.println("DataExchangeAPIExample2.main() sent " + entriesToSend.size() + " entries.");
    }
}