org.openziti.edge.api.ControllersApi Maven / Gradle / Ivy
The newest version!
/*
* Ziti Edge Client
* OpenZiti Edge Client API
*
* The version of the OpenAPI document: 0.26.27
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openziti.edge.api;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.openziti.edge.ApiClient;
import org.openziti.edge.ApiException;
import org.openziti.edge.ApiResponse;
import org.openziti.edge.Pair;
import org.openziti.edge.model.ListControllersEnvelope;
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
date = "2024-09-04T10:11:22.635226-04:00[America/New_York]",
comments = "Generator version: 7.8.0")
public class ControllersApi {
private final HttpClient memberVarHttpClient;
private final ObjectMapper memberVarObjectMapper;
private final String memberVarBaseUri;
private final Consumer memberVarInterceptor;
private final Duration memberVarReadTimeout;
private final Consumer> memberVarResponseInterceptor;
private final Consumer> memberVarAsyncResponseInterceptor;
public ControllersApi() {
this(new ApiClient());
}
public ControllersApi(ApiClient apiClient) {
memberVarHttpClient = apiClient.getHttpClient();
memberVarObjectMapper = apiClient.getObjectMapper();
memberVarBaseUri = apiClient.getBaseUri();
memberVarInterceptor = apiClient.getRequestInterceptor();
memberVarReadTimeout = apiClient.getReadTimeout();
memberVarResponseInterceptor = apiClient.getResponseInterceptor();
memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor();
}
private ApiException getApiException(String operationId, HttpResponse response) {
String message =
formatExceptionMessage(operationId, response.statusCode(), response.body());
return new ApiException(
response.statusCode(), message, response.headers(), response.body());
}
private String formatExceptionMessage(String operationId, int statusCode, String body) {
if (body == null || body.isEmpty()) {
body = "[no body]";
}
return operationId + " call failed with: " + statusCode + " - " + body;
}
/**
* List controllers Retrieves a list of controllers
*
* @param limit (optional)
* @param offset (optional)
* @param filter (optional)
* @return CompletableFuture<ListControllersEnvelope>
* @throws ApiException if fails to make API call
*/
public CompletableFuture listControllers(
Integer limit, Integer offset, String filter) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder =
listControllersRequestBuilder(limit, offset, filter);
return memberVarHttpClient
.sendAsync(localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString())
.thenComposeAsync(
localVarResponse -> {
if (localVarResponse.statusCode() / 100 != 2) {
return CompletableFuture.failedFuture(
getApiException("listControllers", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
responseBody == null || responseBody.isBlank()
? null
: memberVarObjectMapper.readValue(
responseBody,
new TypeReference<
ListControllersEnvelope>() {}));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
/**
* List controllers Retrieves a list of controllers
*
* @param limit (optional)
* @param offset (optional)
* @param filter (optional)
* @return CompletableFuture<ApiResponse<ListControllersEnvelope>>
* @throws ApiException if fails to make API call
*/
public CompletableFuture> listControllersWithHttpInfo(
Integer limit, Integer offset, String filter) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder =
listControllersRequestBuilder(limit, offset, filter);
return memberVarHttpClient
.sendAsync(localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString())
.thenComposeAsync(
localVarResponse -> {
if (memberVarAsyncResponseInterceptor != null) {
memberVarAsyncResponseInterceptor.accept(localVarResponse);
}
if (localVarResponse.statusCode() / 100 != 2) {
return CompletableFuture.failedFuture(
getApiException("listControllers", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
new ApiResponse(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
responseBody == null || responseBody.isBlank()
? null
: memberVarObjectMapper.readValue(
responseBody,
new TypeReference<
ListControllersEnvelope>() {})));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
private HttpRequest.Builder listControllersRequestBuilder(
Integer limit, Integer offset, String filter) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/controllers";
List localVarQueryParams = new ArrayList<>();
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
String localVarQueryParameterBaseName;
localVarQueryParameterBaseName = "limit";
localVarQueryParams.addAll(ApiClient.parameterToPairs("limit", limit));
localVarQueryParameterBaseName = "offset";
localVarQueryParams.addAll(ApiClient.parameterToPairs("offset", offset));
localVarQueryParameterBaseName = "filter";
localVarQueryParams.addAll(ApiClient.parameterToPairs("filter", filter));
if (!localVarQueryParams.isEmpty() || localVarQueryStringJoiner.length() != 0) {
StringJoiner queryJoiner = new StringJoiner("&");
localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
if (localVarQueryStringJoiner.length() != 0) {
queryJoiner.add(localVarQueryStringJoiner.toString());
}
localVarRequestBuilder.uri(
URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
} else {
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
}
localVarRequestBuilder.header("Accept", "application/json");
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
}