Java SDK
We now present a high-level Java API as a type-safe and gentle wrapper for the OpenMetadata backend. The open-source OpenMetadata SDK for Java simplifies provisioning, managing, and using OpenMetadata resources from the Java application code.The OpenMetadata SDK for Java libraries build on top of the underlying OpenMetadata REST API, allows you to use those APIs through familiar Java paradigms. However, you can always use the REST API directly from Java code, if you prefer to do so. You can find the source code for the OpenMetadata libraries in the GitHub repository. As an open-source project, contributions are always welcome! You can add the below Maven Dependency for the OpenMetadata Java SDK.
Connect to the OpenMetadata Server
To connect to your OpenMetadata server, you need:- Server URL: The URL where your OpenMetadata instance is running, ending in
/api. For example,http://localhost:8585/api. - Access token: A JSON Web Token (JWT) for a user or bot. See Authentication to learn how to get one.
header adds a custom header to every request:
Authenticate with a JWT Token
The Java SDK authenticates with a JWT access token that you pass toaccessToken(...). This is the same for every sign-in method on your OpenMetadata server, including Google, Okta, Auth0, Azure, and custom OpenID Connect (OIDC). Generate a bot token or a personal access token in OpenMetadata and use it here.
If your server doesn’t require authentication, leave out accessToken(...).
Use the Fluent API
The fluent classes, such asTables, Users, and Teams, work with a default client. Register your client once with OM.init, and the fluent classes use it:
Use the Service Clients
Every entity type has a service on the client, such asclient.tables(), client.users(), and client.dashboards(). These services offer methods such as create, get, getByName, list, update, delete, and restore. Below are some examples:
- Create a table
- Get a table by fully qualified name
- Search
Handle Errors
When the server returns an error, the SDK throws anOpenMetadataException. Use getStatusCode() to see which error it was: