Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

![](https://www.anduril.com/lattice-sdk/)

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fanduril%2Flattice-sdk-java)
[![Maven Central](https://img.shields.io/maven-central/v/com.anduril/lattice-sdk)](https://central.sonatype.com/artifact/com.anduril/lattice-sdk)

The Lattice SDK Java library provides convenient access to the Lattice API from Java.
The Anduril Java library provides convenient access to the Anduril APIs from Java.

## Documentation

Expand Down Expand Up @@ -34,7 +35,7 @@ Add the dependency in your `pom.xml` file:
<dependency>
<groupId>com.anduril</groupId>
<artifactId>lattice-sdk</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
</dependency>
```

Expand Down Expand Up @@ -175,3 +176,43 @@ client.entities().longPollEntityEvents(
.build()
);
```

### Custom Headers

The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level.

```java
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()
);
```

## Reference

A full reference for this library is available [here](https://github.com/anduril/lattice-sdk-java/blob/HEAD/./reference.md).

## Contributing

While we value open-source contributions to this SDK, this library is generated programmatically.
Additions made directly to this library would have to be moved over to our generation code,
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
}


Expand All @@ -46,7 +47,7 @@ java {

group = 'com.anduril'

version = '2.2.0'
version = '2.3.0'

jar {
dependsOn(":generatePomFileForMavenPublication")
Expand Down Expand Up @@ -77,21 +78,21 @@ publishing {
maven(MavenPublication) {
groupId = 'com.anduril'
artifactId = 'lattice-sdk'
version = '2.2.0'
version = '2.3.0'
from components.java
pom {
name = 'Anduril Industries, Inc.'
description = 'Anduril Lattice SDK for Java'
url = 'https://developer.anduril.com'
name = 'anduril'
description = 'The official SDK of anduril'
url = 'https://buildwithfern.com'
licenses {
license {
name = 'Anduril Lattice Software Development Kit License Agreement'
name = 'Custom License (LICENSE)'
}
}
developers {
developer {
name = 'Anduril Industries, Inc.'
email = 'lattice-[email protected]'
name = 'anduril'
email = '[email protected]'
}
}
scm {
Expand Down Expand Up @@ -120,9 +121,10 @@ sonatypeCentralUpload {
}

signing {
def signingKeyId = "$System.env.MAVEN_SIGNATURE_SECRET_KEY"
def signingKeyId = "$System.env.MAVEN_SIGNATURE_KID"
def signingKey = "$System.env.MAVEN_SIGNATURE_SECRET_KEY"
def signingPassword = "$System.env.MAVEN_SIGNATURE_PASSWORD"
useInMemoryPgpKeys(signingKeyId, signingPassword)
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign publishing.publications.maven
}

Expand Down
154 changes: 146 additions & 8 deletions src/main/java/com/anduril/AsyncLatticeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@

import com.anduril.core.ClientOptions;
import com.anduril.core.Environment;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import okhttp3.OkHttpClient;

public final class AsyncLatticeBuilder {
private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder();
public class AsyncLatticeBuilder {
private Optional<Integer> timeout = Optional.empty();

private Optional<Integer> maxRetries = Optional.empty();

private final Map<String, String> customHeaders = new HashMap<>();

private String token = null;

private Environment environment = Environment.DEFAULT;

private OkHttpClient httpClient;

/**
* Sets token
*/
Expand All @@ -36,29 +45,158 @@ public AsyncLatticeBuilder url(String url) {
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
*/
public AsyncLatticeBuilder timeout(int timeout) {
this.clientOptionsBuilder.timeout(timeout);
this.timeout = Optional.of(timeout);
return this;
}

/**
* Sets the maximum number of retries for the client. Defaults to 2 retries.
*/
public AsyncLatticeBuilder maxRetries(int maxRetries) {
this.clientOptionsBuilder.maxRetries(maxRetries);
this.maxRetries = Optional.of(maxRetries);
return this;
}

/**
* Sets the underlying OkHttp client
*/
public AsyncLatticeBuilder httpClient(OkHttpClient httpClient) {
this.clientOptionsBuilder.httpClient(httpClient);
this.httpClient = httpClient;
return this;
}

/**
* Add a custom header to be sent with all requests.
* For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.
*
* @param name The header name
* @param value The header value
* @return This builder for method chaining
*/
public AsyncLatticeBuilder addHeader(String name, String value) {
this.customHeaders.put(name, value);
return this;
}

protected ClientOptions buildClientOptions() {
ClientOptions.Builder builder = ClientOptions.builder();
setEnvironment(builder);
setAuthentication(builder);
setHttpClient(builder);
setTimeouts(builder);
setRetries(builder);
for (Map.Entry<String, String> header : this.customHeaders.entrySet()) {
builder.addHeader(header.getKey(), header.getValue());
}
setAdditional(builder);
return builder.build();
}

/**
* Sets the environment configuration for the client.
* Override this method to modify URLs or add environment-specific logic.
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setEnvironment(ClientOptions.Builder builder) {
builder.environment(this.environment);
}

/**
* Override this method to customize authentication.
* This method is called during client options construction to set up authentication headers.
*
* @param builder The ClientOptions.Builder to configure
*
* Example:
* <pre>{@code
* &#64;Override
* protected void setAuthentication(ClientOptions.Builder builder) {
* super.setAuthentication(builder); // Keep existing auth
* builder.addHeader("X-API-Key", this.apiKey);
* }
* }</pre>
*/
protected void setAuthentication(ClientOptions.Builder builder) {
if (this.token != null) {
builder.addHeader("Authorization", "Bearer " + this.token);
}
}

/**
* Sets the request timeout configuration.
* Override this method to customize timeout behavior.
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setTimeouts(ClientOptions.Builder builder) {
if (this.timeout.isPresent()) {
builder.timeout(this.timeout.get());
}
}

/**
* Sets the retry configuration for failed requests.
* Override this method to implement custom retry strategies.
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setRetries(ClientOptions.Builder builder) {
if (this.maxRetries.isPresent()) {
builder.maxRetries(this.maxRetries.get());
}
}

/**
* Sets the OkHttp client configuration.
* Override this method to customize HTTP client behavior (interceptors, connection pools, etc).
*
* @param builder The ClientOptions.Builder to configure
*/
protected void setHttpClient(ClientOptions.Builder builder) {
if (this.httpClient != null) {
builder.httpClient(this.httpClient);
}
}

/**
* Override this method to add any additional configuration to the client.
* This method is called at the end of the configuration chain, allowing you to add
* custom headers, modify settings, or perform any other client customization.
*
* @param builder The ClientOptions.Builder to configure
*
* Example:
* <pre>{@code
* &#64;Override
* protected void setAdditional(ClientOptions.Builder builder) {
* builder.addHeader("X-Request-ID", () -&gt; UUID.randomUUID().toString());
* builder.addHeader("X-Client-Version", "1.0.0");
* }
* }</pre>
*/
protected void setAdditional(ClientOptions.Builder builder) {}

/**
* Override this method to add custom validation logic before the client is built.
* This method is called at the beginning of the build() method to ensure the configuration is valid.
* Throw an exception to prevent client creation if validation fails.
*
* Example:
* <pre>{@code
* &#64;Override
* protected void validateConfiguration() {
* super.validateConfiguration(); // Run parent validations
* if (tenantId == null || tenantId.isEmpty()) {
* throw new IllegalStateException("tenantId is required");
* }
* }
* }</pre>
*/
protected void validateConfiguration() {}

public AsyncLattice build() {
this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token);
clientOptionsBuilder.environment(this.environment);
return new AsyncLattice(clientOptionsBuilder.build());
validateConfiguration();
return new AsyncLattice(buildClientOptions());
}
}
Loading