Skip to content

Commit 2372a49

Browse files
🌿 Fern Regeneration -- September 4, 2025 (#135)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Armin Farshidfard <[email protected]>
1 parent a397879 commit 2372a49

File tree

7 files changed

+348
-27
lines changed

7 files changed

+348
-27
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Anduril Java Library
1+
# Anduril Lattice SDK Java
22

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

@@ -34,7 +34,7 @@ Add the dependency in your `pom.xml` file:
3434
<dependency>
3535
<groupId>com.anduril</groupId>
3636
<artifactId>lattice-sdk</artifactId>
37-
<version>2.2.0</version>
37+
<version>2.3.0</version>
3838
</dependency>
3939
```
4040

@@ -175,3 +175,33 @@ client.entities().longPollEntityEvents(
175175
.build()
176176
);
177177
```
178+
179+
### Custom Headers
180+
181+
The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level.
182+
183+
```java
184+
import com.anduril.Lattice;
185+
import com.anduril.core.RequestOptions;
186+
187+
// Client level
188+
Lattice client = Lattice
189+
.builder()
190+
.addHeader("X-Custom-Header", "custom-value")
191+
.addHeader("X-Request-Id", "abc-123")
192+
.build();
193+
;
194+
195+
// Request level
196+
client.entities().longPollEntityEvents(
197+
...,
198+
RequestOptions
199+
.builder()
200+
.addHeader("X-Request-Header", "request-value")
201+
.build()
202+
);
203+
```
204+
205+
## Reference
206+
207+
A full reference for this library is available [here](https://github.com/anduril/lattice-sdk-java/blob/HEAD/./reference.md).

build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2'
2121
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
2222
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
23+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
2324
}
2425

2526

@@ -46,7 +47,7 @@ java {
4647

4748
group = 'com.anduril'
4849

49-
version = '2.2.0'
50+
version = '2.3.0'
5051

5152
jar {
5253
dependsOn(":generatePomFileForMavenPublication")
@@ -77,7 +78,7 @@ publishing {
7778
maven(MavenPublication) {
7879
groupId = 'com.anduril'
7980
artifactId = 'lattice-sdk'
80-
version = '2.2.0'
81+
version = '2.3.0'
8182
from components.java
8283
pom {
8384
name = 'Anduril Industries, Inc.'
@@ -120,9 +121,10 @@ sonatypeCentralUpload {
120121
}
121122

122123
signing {
123-
def signingKeyId = "$System.env.MAVEN_SIGNATURE_SECRET_KEY"
124+
def signingKeyId = "$System.env.MAVEN_SIGNATURE_KID"
125+
def signingKey = "$System.env.MAVEN_SIGNATURE_SECRET_KEY"
124126
def signingPassword = "$System.env.MAVEN_SIGNATURE_PASSWORD"
125-
useInMemoryPgpKeys(signingKeyId, signingPassword)
127+
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
126128
sign publishing.publications.maven
127129
}
128130

src/main/java/com/anduril/AsyncLatticeBuilder.java

Lines changed: 146 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@
55

66
import com.anduril.core.ClientOptions;
77
import com.anduril.core.Environment;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.Optional;
811
import okhttp3.OkHttpClient;
912

10-
public final class AsyncLatticeBuilder {
11-
private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder();
13+
public class AsyncLatticeBuilder {
14+
private Optional<Integer> timeout = Optional.empty();
15+
16+
private Optional<Integer> maxRetries = Optional.empty();
17+
18+
private final Map<String, String> customHeaders = new HashMap<>();
1219

1320
private String token = null;
1421

1522
private Environment environment = Environment.DEFAULT;
1623

24+
private OkHttpClient httpClient;
25+
1726
/**
1827
* Sets token
1928
*/
@@ -36,29 +45,158 @@ public AsyncLatticeBuilder url(String url) {
3645
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
3746
*/
3847
public AsyncLatticeBuilder timeout(int timeout) {
39-
this.clientOptionsBuilder.timeout(timeout);
48+
this.timeout = Optional.of(timeout);
4049
return this;
4150
}
4251

4352
/**
4453
* Sets the maximum number of retries for the client. Defaults to 2 retries.
4554
*/
4655
public AsyncLatticeBuilder maxRetries(int maxRetries) {
47-
this.clientOptionsBuilder.maxRetries(maxRetries);
56+
this.maxRetries = Optional.of(maxRetries);
4857
return this;
4958
}
5059

5160
/**
5261
* Sets the underlying OkHttp client
5362
*/
5463
public AsyncLatticeBuilder httpClient(OkHttpClient httpClient) {
55-
this.clientOptionsBuilder.httpClient(httpClient);
64+
this.httpClient = httpClient;
5665
return this;
5766
}
5867

68+
/**
69+
* Add a custom header to be sent with all requests.
70+
* For headers that need to be computed dynamically or conditionally, use the setAdditional() method override instead.
71+
*
72+
* @param name The header name
73+
* @param value The header value
74+
* @return This builder for method chaining
75+
*/
76+
public AsyncLatticeBuilder addHeader(String name, String value) {
77+
this.customHeaders.put(name, value);
78+
return this;
79+
}
80+
81+
protected ClientOptions buildClientOptions() {
82+
ClientOptions.Builder builder = ClientOptions.builder();
83+
setEnvironment(builder);
84+
setAuthentication(builder);
85+
setHttpClient(builder);
86+
setTimeouts(builder);
87+
setRetries(builder);
88+
for (Map.Entry<String, String> header : this.customHeaders.entrySet()) {
89+
builder.addHeader(header.getKey(), header.getValue());
90+
}
91+
setAdditional(builder);
92+
return builder.build();
93+
}
94+
95+
/**
96+
* Sets the environment configuration for the client.
97+
* Override this method to modify URLs or add environment-specific logic.
98+
*
99+
* @param builder The ClientOptions.Builder to configure
100+
*/
101+
protected void setEnvironment(ClientOptions.Builder builder) {
102+
builder.environment(this.environment);
103+
}
104+
105+
/**
106+
* Override this method to customize authentication.
107+
* This method is called during client options construction to set up authentication headers.
108+
*
109+
* @param builder The ClientOptions.Builder to configure
110+
*
111+
* Example:
112+
* <pre>{@code
113+
* &#64;Override
114+
* protected void setAuthentication(ClientOptions.Builder builder) {
115+
* super.setAuthentication(builder); // Keep existing auth
116+
* builder.addHeader("X-API-Key", this.apiKey);
117+
* }
118+
* }</pre>
119+
*/
120+
protected void setAuthentication(ClientOptions.Builder builder) {
121+
if (this.token != null) {
122+
builder.addHeader("Authorization", "Bearer " + this.token);
123+
}
124+
}
125+
126+
/**
127+
* Sets the request timeout configuration.
128+
* Override this method to customize timeout behavior.
129+
*
130+
* @param builder The ClientOptions.Builder to configure
131+
*/
132+
protected void setTimeouts(ClientOptions.Builder builder) {
133+
if (this.timeout.isPresent()) {
134+
builder.timeout(this.timeout.get());
135+
}
136+
}
137+
138+
/**
139+
* Sets the retry configuration for failed requests.
140+
* Override this method to implement custom retry strategies.
141+
*
142+
* @param builder The ClientOptions.Builder to configure
143+
*/
144+
protected void setRetries(ClientOptions.Builder builder) {
145+
if (this.maxRetries.isPresent()) {
146+
builder.maxRetries(this.maxRetries.get());
147+
}
148+
}
149+
150+
/**
151+
* Sets the OkHttp client configuration.
152+
* Override this method to customize HTTP client behavior (interceptors, connection pools, etc).
153+
*
154+
* @param builder The ClientOptions.Builder to configure
155+
*/
156+
protected void setHttpClient(ClientOptions.Builder builder) {
157+
if (this.httpClient != null) {
158+
builder.httpClient(this.httpClient);
159+
}
160+
}
161+
162+
/**
163+
* Override this method to add any additional configuration to the client.
164+
* This method is called at the end of the configuration chain, allowing you to add
165+
* custom headers, modify settings, or perform any other client customization.
166+
*
167+
* @param builder The ClientOptions.Builder to configure
168+
*
169+
* Example:
170+
* <pre>{@code
171+
* &#64;Override
172+
* protected void setAdditional(ClientOptions.Builder builder) {
173+
* builder.addHeader("X-Request-ID", () -&gt; UUID.randomUUID().toString());
174+
* builder.addHeader("X-Client-Version", "1.0.0");
175+
* }
176+
* }</pre>
177+
*/
178+
protected void setAdditional(ClientOptions.Builder builder) {}
179+
180+
/**
181+
* Override this method to add custom validation logic before the client is built.
182+
* This method is called at the beginning of the build() method to ensure the configuration is valid.
183+
* Throw an exception to prevent client creation if validation fails.
184+
*
185+
* Example:
186+
* <pre>{@code
187+
* &#64;Override
188+
* protected void validateConfiguration() {
189+
* super.validateConfiguration(); // Run parent validations
190+
* if (tenantId == null || tenantId.isEmpty()) {
191+
* throw new IllegalStateException("tenantId is required");
192+
* }
193+
* }
194+
* }</pre>
195+
*/
196+
protected void validateConfiguration() {}
197+
59198
public AsyncLattice build() {
60-
this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token);
61-
clientOptionsBuilder.environment(this.environment);
62-
return new AsyncLattice(clientOptionsBuilder.build());
199+
validateConfiguration();
200+
return new AsyncLattice(buildClientOptions());
63201
}
64202
}

0 commit comments

Comments
 (0)