Java SDK

The official CredVault SDK for Java applications. Built for enterprise environments, this SDK provides robust, type-safe access to all platform capabilities.

Why Use the Java SDK?

Java remains the language of choice for large-scale enterprise applications. The CredVault Java SDK is designed with enterprise needs in mind: thread safety, comprehensive error handling, and compatibility with popular frameworks like Spring Boot.

The SDK uses OkHttp for efficient HTTP communication and Gson for JSON serialization. These proven libraries ensure reliable performance under heavy load.

All public methods use descriptive return types, making it easy to work with responses. IDE support is excellent, with full JavaDoc documentation for every class and method.

System Requirements

The SDK requires Java 11 or higher. It's compatible with all major Java distributions including Oracle JDK, OpenJDK, and Amazon Corretto.

For building projects, the SDK works with both Maven and Gradle. Dependencies are published to Maven Central, the standard repository for Java libraries.

Installation

Add the SDK dependency to your build configuration.

For Gradle users (build.gradle):

implementation 'com.credvault:credvault-edge:1.0.0'

For Maven users (pom.xml):

<dependency>
    <groupId>com.credvault</groupId>
    <artifactId>credvault-edge</artifactId>
    <version>1.0.0</version>
</dependency>

You'll also need the OkHttp and Gson libraries, which the SDK uses internally.

Connecting to CredVault

Begin by creating a client instance with your API key. The client is thread-safe and should be reused for multiple requests.

import com.credvault.CredVaultClient;

String apiKey = System.getenv("CREDVAULT_API_KEY");
CredVaultClient client = new CredVaultClient(apiKey);

For applications with many concurrent users, create a single client instance and share it across threads. This allows efficient connection pooling.

If your organization uses a custom deployment, you can specify an alternative base URL when creating the client.

Working with Data

The SDK provides strongly-typed methods for all data operations.

Listing clusters retrieves your database clusters. The response includes details about each cluster's configuration and status.

Querying data fetches documents from collections. Pass your query parameters as a JSON string, and the SDK returns the matching documents.

Inserting data adds new documents. Provide documents as a JSON array, and the method returns information about the inserted records.

Updating data modifies existing documents. Specify a filter to match documents and provide the update operations to apply.

Deleting data removes documents. Like other operations, use a filter to select which documents to delete.

Error Handling

Java applications should handle IOException for all SDK operations. The SDK wraps API errors in descriptive exceptions with status codes and error messages.

Use try-catch blocks around API calls and handle errors appropriately for your application's needs. Consider retry logic for transient network errors.

Resources Available

The SDK organizes functionality into resource classes:

  • auth — User authentication
  • data — Database operations
  • cie — Machine learning
  • webhooks — Event notifications
  • functions — Serverless execution
  • triggers — Event automation
  • backups — Data protection
  • schema — Schema management
  • apiKeys — Key management
  • metrics — Monitoring
  • logs — Activity tracking
  • notifications — User notifications
  • settings — Configuration

Spring Boot Integration

The SDK integrates naturally with Spring Boot applications. Create a configuration class that provides the CredVault client as a bean. Spring's dependency injection will make the client available throughout your application.

Consider using Spring's @Value annotation to inject the API key from configuration properties, keeping credentials separate from code.

Best Practices

Reuse the client instance. Creating a new client for every request wastes resources. Create one instance and share it across your application.

Handle exceptions properly. Don't ignore exceptions. Log them, report them to monitoring systems, and provide appropriate feedback to users.

Use environment-specific configuration. Keep API keys and base URLs in configuration files or environment variables, not in source code.

Close resources properly. While the SDK manages connections automatically, ensure your application shuts down cleanly.

For detailed API documentation, refer to the JavaDoc included with the SDK or explore the source code on GitHub.