Chapter 6. Managing Service Registry content using a Java client


This chapter explains how to use the Service Registry Java client:

6.1. Service Registry Java client

You can manage artifacts stored in Service Registry by using a Java client application. You can create, read, update, or delete artifacts by using the Service Registry Java client classes. You can also use the Service Registry Java client to perform administrator functions, such as managing global rules or importing and exporting Service Registry data.

You can access the Service Registry Java client by adding the correct dependency to your Apache Maven project. For more details, see Section 6.2, “Writing Service Registry Java client applications”.

The Service Registry client is implemented by using the HTTP client provided by the JDK, which you can customize as needed. For example, you can add custom headers or enable configuration options for Transport Layer Security (TLS) authentication. For more details, see Section 6.3, “Service Registry Java client configuration”.

6.2. Writing Service Registry Java client applications

You can write a Java client application to manage artifacts stored in Service Registry by using the Service Registry Java client classes.

Prerequisites

  • Service Registry is installed and running in your environment.
  • You have created a Maven project for your Java client application. For more details, see Apache Maven.

Procedure

  1. Add the following dependency to your Maven project:

    <dependency>
        <groupId>io.apicurio</groupId>
        <artifactId>apicurio-registry-client</artifactId>
        <version>${apicurio-registry.version}</version>
    </dependency>
  2. Create the Service Registry client as follows:

    public class ClientExample {
    
        public static void main(String[] args) throws Exception {
           // Create a registry client
           String registryUrl = "https://my-registry.my-domain.com/apis/registry/v2";
           RegistryClient client = RegistryClientFactory.create(registryUrl);
        }
    }
    • If you specify an example Service Registry URL of https://my-registry.my-domain.com, the client will automatically append /apis/registry/v2.
    • For more options when creating a Service Registry client, see the Java client configuration in the next section.

When the client is created, you can use all of the operations available in the Service Registry REST API in the client. For more details, see the Apicurio Registry REST API documentation.

Additional resources

6.3. Service Registry Java client configuration

The Service Registry Java client includes the following configuration options, based on the client factory:

Table 6.1. Service Registry Java client configuration options
OptionDescriptionArguments

Plain client

Basic REST client used to interact with a running Service Registry instance.

baseUrl

Client with custom configuration

Service Registry client using the configuration provided by the user.

baseUrl, Map<String Object> configs

Client with custom configuration and authentication

Service Registry client that accepts a map containing custom configuration. For example, this is useful to add custom headers to the calls. You must also provide an authentication server to authenticate the requests.

baseUrl, Map<String Object> configs, Auth auth

Custom header configuration

To configure custom headers, you must add the apicurio.registry.request.headers prefix to the configs map key. For example, a configs map key of apicurio.registry.request.headers.Authorization with a value of Basic: YWxhZGRpbjpvcGVuc2VzYW1 sets the Authorization header with the same value.

TLS configuration options

You can configure Transport Layer Security (TLS) authentication for the Service Registry Java client using the following properties:

  • apicurio.registry.request.ssl.truststore.location
  • apicurio.registry.request.ssl.truststore.password
  • apicurio.registry.request.ssl.truststore.type
  • apicurio.registry.request.ssl.keystore.location
  • apicurio.registry.request.ssl.keystore.password
  • apicurio.registry.request.ssl.keystore.type
  • apicurio.registry.request.ssl.key.password

Additional resources

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.