Skip to content

Configuration

The Java client uses a builder pattern for configuration. Both the API key and base URL are required since VaultSandbox is self-hosted.

ClientConfig config = ClientConfig.builder()
.apiKey("your-api-key")
.baseUrl("https://gateway.example.com")
.build();
VaultSandboxClient client = VaultSandboxClient.create(config);
ClientConfig config = ClientConfig.builder()
.apiKey("your-api-key")
.baseUrl("https://gateway.example.com")
.strategy(StrategyType.SSE)
.waitTimeout(Duration.ofSeconds(60))
.build();
VaultSandboxClient client = VaultSandboxClient.create(config);
OptionTypeDefaultDescription
apiKeyStringrequiredAPI key for authentication
baseUrlStringrequiredGateway API endpoint URL
strategyStrategyTypeAUTOEmail delivery strategy
httpTimeoutDuration30sHTTP request timeout
waitTimeoutDuration30sDefault email wait timeout
maxRetriesint3Maximum retry attempts
retryDelayDuration1sInitial retry delay
retryOnSet<Integer>408, 429, 500-504HTTP status codes to retry
sseReconnectIntervalDuration5sSSE reconnection interval
sseMaxReconnectAttemptsint10Max SSE reconnection attempts
pollIntervalDuration2sPolling check frequency
maxBackoffDuration30sMaximum backoff duration
backoffMultiplierdouble1.5Exponential backoff factor
jitterFactordouble0.3Random jitter factor (0-1)

The strategy option controls how the client receives emails:

StrategyDescriptionBest For
AUTOTries SSE first, falls back to pollingMost use cases (recommended)
SSEServer-Sent Events for real-time deliveryLow-latency requirements
POLLINGPeriodic HTTP requestsCI/CD, firewalled environments
import com.vaultsandbox.client.StrategyType;
// Real-time delivery
ClientConfig.builder()
.apiKey(apiKey)
.strategy(StrategyType.SSE)
.build();
// Reliable polling
ClientConfig.builder()
.apiKey(apiKey)
.strategy(StrategyType.POLLING)
.pollInterval(Duration.ofSeconds(1))
.build();
ClientConfig config = ClientConfig.builder()
.apiKey(System.getenv("VAULTSANDBOX_API_KEY"))
.strategy(StrategyType.AUTO)
.httpTimeout(Duration.ofSeconds(30))
.maxRetries(3)
.build();
ClientConfig config = ClientConfig.builder()
.apiKey(System.getenv("VAULTSANDBOX_API_KEY"))
.strategy(StrategyType.POLLING) // More reliable in CI
.pollInterval(Duration.ofSeconds(1))
.waitTimeout(Duration.ofSeconds(60))
.build();
ClientConfig config = ClientConfig.builder()
.apiKey("dev-api-key")
.strategy(StrategyType.SSE) // Fastest feedback
.httpTimeout(Duration.ofSeconds(10))
.build();
ClientConfig config = ClientConfig.builder()
.apiKey(apiKey)
.strategy(StrategyType.AUTO)
.maxRetries(5)
.retryDelay(Duration.ofMillis(500))
.sseMaxReconnectAttempts(20)
.build();

Use environment variables for sensitive configuration:

String apiKey = System.getenv("VAULTSANDBOX_API_KEY");
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalStateException("VAULTSANDBOX_API_KEY not set");
}
String baseUrl = System.getenv("VAULTSANDBOX_URL");
if (baseUrl == null || baseUrl.isBlank()) {
throw new IllegalStateException("VAULTSANDBOX_URL not set");
}
ClientConfig config = ClientConfig.builder()
.apiKey(apiKey)
.baseUrl(baseUrl)
.build();

The client implements Closeable and should be closed when done.

try (VaultSandboxClient client = VaultSandboxClient.create(config)) {
Inbox inbox = client.createInbox();
Email email = inbox.waitForEmail();
// Process email
}
// Client automatically closed
VaultSandboxClient client = VaultSandboxClient.create(config);
try {
Inbox inbox = client.createInbox();
Email email = inbox.waitForEmail();
// Process email
} finally {
client.close();
}

For JUnit 5, use @BeforeAll and @AfterAll:

class EmailTests {
private static VaultSandboxClient client;
@BeforeAll
static void setup() {
ClientConfig config = ClientConfig.builder()
.apiKey(System.getenv("VAULTSANDBOX_API_KEY"))
.baseUrl(System.getenv("VAULTSANDBOX_URL"))
.build();
client = VaultSandboxClient.create(config);
}
@AfterAll
static void teardown() {
if (client != null) {
client.close();
}
}
@Test
void testEmailFlow() {
Inbox inbox = client.createInbox();
// Test code
}
}

The SDK uses SLF4J for logging. Configure your logging framework to see SDK logs:

logback.xml
<configuration>
<logger name="com.vaultsandbox" level="DEBUG"/>
</configuration>
log4j2.xml
<Configuration>
<Loggers>
<Logger name="com.vaultsandbox" level="DEBUG"/>
</Loggers>
</Configuration>

Access the current configuration from an existing client:

VaultSandboxClient client = VaultSandboxClient.create(config);
ClientConfig currentConfig = client.getConfig();
System.out.println("Base URL: " + currentConfig.getBaseUrl());
System.out.println("Strategy: " + currentConfig.getStrategy());
System.out.println("Wait Timeout: " + currentConfig.getWaitTimeout());
  1. Use environment variables for API keys - never commit secrets
  2. Use try-with-resources for automatic cleanup
  3. Use POLLING in CI/CD - more reliable than SSE in containerized environments
  4. Set appropriate timeouts - longer for slow mail servers, shorter for fast feedback
  5. Configure retries - balance reliability vs test duration
  6. Share client instances - create once per test class, not per test method