The Lattice SDK Java library provides convenient access to the Lattice SDK APIs from Java.
- Documentation
- Requirements
- Installation
- Support
- Usage
- Environments
- Base Url
- Exception Handling
- Advanced
- Reference
API reference documentation is available here.
This repository is tested against Java 1.8 or later.
Add the dependency in your build.gradle file:
dependencies {
implementation 'com.anduril:lattice-sdk'
}Add the dependency in your pom.xml file:
<dependency>
<groupId>com.anduril</groupId>
<artifactId>lattice-sdk</artifactId>
<version>5.0.0</version>
</dependency>For support with this library please reach out to your Anduril representative.
Instantiate and use the client with the following:
package com.example.usage;
import com.anduril.Lattice;
import com.anduril.resources.entities.requests.EntityEventRequest;
public class Example {
public static void main(String[] args) {
Lattice client = Lattice
.builder()
.token("<token>")
.build();
client.entities().longPollEntityEvents(
EntityEventRequest
.builder()
.sessionToken("sessionToken")
.build()
);
}
}This SDK allows you to configure different environments for API requests.
import com.anduril.Lattice;
import com.anduril.core.Environment;
Lattice client = Lattice
.builder()
.environment(Environment.Default)
.build();You can set a custom base URL when constructing the client.
import com.anduril.Lattice;
Lattice client = Lattice
.builder()
.url("https://example.com")
.build();When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.
import com.anduril.core.AndurilApiApiException;
try{
client.entities().longPollEntityEvents(...);
} catch (AndurilApiApiException e){
// Do something with the API exception...
}This SDK is built to work with any instance of OkHttpClient. By default, if no client is provided, the SDK will construct one.
However, you can pass your own client like so:
import com.anduril.Lattice;
import okhttp3.OkHttpClient;
OkHttpClient customClient = ...;
Lattice client = Lattice
.builder()
.httpClient(customClient)
.build();The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2). Before defaulting to exponential backoff, the SDK will first attempt to respect
the Retry-After header (as either in seconds or as an HTTP date), and then the X-RateLimit-Reset header
(as a Unix timestamp in epoch seconds); failing both of those, it will fall back to exponential backoff.
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the maxRetries client option to configure this behavior.
import com.anduril.Lattice;
Lattice client = Lattice
.builder()
.maxRetries(1)
.build();The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
import com.anduril.Lattice;
import com.anduril.core.RequestOptions;
// Client level
Lattice client = Lattice
.builder()
.timeout(10)
.build();
// Request level
client.entities().longPollEntityEvents(
...,
RequestOptions
.builder()
.timeout(10)
.build()
);The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level.
import com.anduril.Lattice;
import com.anduril.core.RequestOptions;
// Client level
Lattice client = Lattice
.builder()
.addHeader("X-Custom-Header", "custom-value")
.addHeader("X-Request-Id", "abc-123")
.build();
;
// Request level
client.entities().longPollEntityEvents(
...,
RequestOptions
.builder()
.addHeader("X-Request-Header", "request-value")
.build()
);The SDK provides access to raw response data, including headers, through the withRawResponse() method.
The withRawResponse() method returns a raw client that wraps all responses with body() and headers() methods.
(A normal client's response is identical to a raw client's response.body().)
LongPollEntityEventsHttpResponse response = client.entities().withRawResponse().longPollEntityEvents(...);
System.out.println(response.body());
System.out.println(response.headers().get("X-My-Header"));A full reference for this library is available here.