@@ -9,7 +9,88 @@ A Java Client or SDK that allows you to interact with the Microcks API. It has m
99
1010## Build Status
1111
12- The current development version is ` 0.0.1-SNAPSHOT ` .
12+ Latest released version is ` 0.0.1 ` .
13+
14+ Current development version is ` 0.0.2-SNAPSHOT ` .
1315
1416[ ![ GitHub Workflow Status] ( https://img.shields.io/github/actions/workflow/status/microcks/microcks-java-client/build-verify.yml?logo=github&style=for-the-badge )] ( https://github.com/microcks/microcks-java-client/actions )
1517
18+ ## Versions
19+
20+ | Java Client | Microcks Version |
21+ | -------------| ------------------|
22+ | 0.0.1 | 1.10.0 and + |
23+
24+ ## How to use it?
25+
26+ ### Include it into your project dependencies
27+
28+ If you're using Maven:
29+ ``` xml
30+ <dependency >
31+ <groupId >io.github.microcks</groupId >
32+ <artifactId >microcks-java-client</artifactId >
33+ <version >0.0.1</version >
34+ </dependency >
35+ ```
36+
37+ or if you're using Gradle:
38+ ``` groovy
39+ dependencies {
40+ implementation 'io.github.microcks:microcks-java-client:0.0.1'
41+ }
42+ ```
43+
44+ ### Use it in your code
45+
46+ The API endpoints available on Microcks backend are split in different classes in the ` io.github.microcks.client ` package.
47+ Each class represents a different part of the API but needs a common client configuration that is named ` ApiClient ` .
48+
49+ Here's the basic usage of the client where you configure the base URI of the Microcks API:
50+
51+ ``` java
52+ ApiClient apiClient = new ApiClient ();
53+ apiClient. updateBaseUri(" http://localhost:8585/api" );
54+ ```
55+
56+ You can then easily use the client to interact with the different part of the API:
57+
58+ ``` java
59+ ConfigApi configApi = new ConfigApi (apiClient);
60+ KeycloakConfig config = configApi. getKeycloakConfig();
61+ ```
62+
63+ Check the[ ] Microcks' OpenAPI reference] ( https://microcks.io/documentation/references/apis/open-api/ ) for comprehensive
64+ list of available endpoints and their parameters.
65+
66+ ### Access to authenticated endpoints
67+
68+ If your Microcks backend instance has enabled AuthN and AUthZ and if you need to access authenticated endpoints,
69+ we provide a ` KeycloakClient ` to first retrieve an oAuth token to use in following requests. You'll additionally need
70+ the service account name and credentials to retrieve the token (see our documentation on
71+ [ how Microcks is using Service Accounts] ( https://microcks.io/documentation/explanations/service-account/ ) ).
72+
73+ The flow is as follows:
74+
75+ ``` java
76+ KeycloakConfig keycloak = configApi. getKeycloakConfig();
77+
78+ // If Keycloak is enabled on target backend.
79+ if (config. isEnabled()) {
80+ // Build the OAuth token endpoint - here using Keycloak public url but it could be another private one.
81+ String tokenEndpoint = keycloak. getAuthServerUrl() + " /realms/" + keycloak. getRealm() + " /protocol/openid-connect/token" ;
82+ final String oauthToken = KeycloakClient . connectAndGetOAuthToken(" <service-account>" , " <service-account-credentials>" , tokenEndpoint);
83+
84+ // Set a new interceptor to add the Authorization header with the OAuth token.
85+ apiClient. setRequestInterceptor(request - > request. header(" Authorization" , " Bearer " + oauthToken));
86+ }
87+
88+ // Now you can use the client to create a protected resource.
89+ JobApi jobApi = new JobApi (apiClient);
90+
91+ ImportJob importJob = new ImportJob ();
92+ importJob. setName(" Hello Soap Service" );
93+ importJob. setRepositoryUrl(" https://raw.githubusercontent.com/microcks/microcks/master/samples/HelloService-soapui-project.xml" );
94+
95+ ImportJob result = jobApi. createImportJob(importJob);
96+ ```
0 commit comments