Create the Java Data Exchange API client

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.");
	}
}