org.openziti.edge.api.SessionApi 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.DetailSessionEnvelope;
import org.openziti.edge.model.Empty;
import org.openziti.edge.model.ListSessionsEnvelope;
import org.openziti.edge.model.SessionCreate;
import org.openziti.edge.model.SessionCreateEnvelope;
@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 SessionApi {
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 SessionApi() {
this(new ApiClient());
}
public SessionApi(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;
}
/**
* Create a session resource Create a session resource.
*
* @param session A session to create (required)
* @return CompletableFuture<SessionCreateEnvelope>
* @throws ApiException if fails to make API call
*/
public CompletableFuture createSession(SessionCreate session)
throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = createSessionRequestBuilder(session);
return memberVarHttpClient
.sendAsync(localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString())
.thenComposeAsync(
localVarResponse -> {
if (localVarResponse.statusCode() / 100 != 2) {
return CompletableFuture.failedFuture(
getApiException("createSession", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
responseBody == null || responseBody.isBlank()
? null
: memberVarObjectMapper.readValue(
responseBody,
new TypeReference<
SessionCreateEnvelope>() {}));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
/**
* Create a session resource Create a session resource.
*
* @param session A session to create (required)
* @return CompletableFuture<ApiResponse<SessionCreateEnvelope>>
* @throws ApiException if fails to make API call
*/
public CompletableFuture> createSessionWithHttpInfo(
SessionCreate session) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = createSessionRequestBuilder(session);
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("createSession", 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<
SessionCreateEnvelope>() {})));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
private HttpRequest.Builder createSessionRequestBuilder(SessionCreate session)
throws ApiException {
// verify the required parameter 'session' is set
if (session == null) {
throw new ApiException(
400, "Missing the required parameter 'session' when calling createSession");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/sessions";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Content-Type", "application/json");
localVarRequestBuilder.header("Accept", "application/json");
try {
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(session);
localVarRequestBuilder.method(
"POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) {
throw new ApiException(e);
}
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Delete a session Delete a session by id.
*
* @param id The id of the requested resource (required)
* @return CompletableFuture<Empty>
* @throws ApiException if fails to make API call
*/
public CompletableFuture deleteSession(String id) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = deleteSessionRequestBuilder(id);
return memberVarHttpClient
.sendAsync(localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString())
.thenComposeAsync(
localVarResponse -> {
if (localVarResponse.statusCode() / 100 != 2) {
return CompletableFuture.failedFuture(
getApiException("deleteSession", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
responseBody == null || responseBody.isBlank()
? null
: memberVarObjectMapper.readValue(
responseBody,
new TypeReference() {}));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
/**
* Delete a session Delete a session by id.
*
* @param id The id of the requested resource (required)
* @return CompletableFuture<ApiResponse<Empty>>
* @throws ApiException if fails to make API call
*/
public CompletableFuture> deleteSessionWithHttpInfo(String id)
throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = deleteSessionRequestBuilder(id);
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("deleteSession", 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<
Empty>() {})));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
private HttpRequest.Builder deleteSessionRequestBuilder(String id) throws ApiException {
// verify the required parameter 'id' is set
if (id == null) {
throw new ApiException(
400, "Missing the required parameter 'id' when calling deleteSession");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/sessions/{id}".replace("{id}", ApiClient.urlEncode(id.toString()));
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "application/json");
localVarRequestBuilder.method("DELETE", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Retrieves a single session Retrieves a single session by id.
*
* @param id The id of the requested resource (required)
* @return CompletableFuture<DetailSessionEnvelope>
* @throws ApiException if fails to make API call
*/
public CompletableFuture detailSession(String id) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = detailSessionRequestBuilder(id);
return memberVarHttpClient
.sendAsync(localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString())
.thenComposeAsync(
localVarResponse -> {
if (localVarResponse.statusCode() / 100 != 2) {
return CompletableFuture.failedFuture(
getApiException("detailSession", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
responseBody == null || responseBody.isBlank()
? null
: memberVarObjectMapper.readValue(
responseBody,
new TypeReference<
DetailSessionEnvelope>() {}));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
/**
* Retrieves a single session Retrieves a single session by id.
*
* @param id The id of the requested resource (required)
* @return CompletableFuture<ApiResponse<DetailSessionEnvelope>>
* @throws ApiException if fails to make API call
*/
public CompletableFuture> detailSessionWithHttpInfo(
String id) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = detailSessionRequestBuilder(id);
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("detailSession", 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<
DetailSessionEnvelope>() {})));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
private HttpRequest.Builder detailSessionRequestBuilder(String id) throws ApiException {
// verify the required parameter 'id' is set
if (id == null) {
throw new ApiException(
400, "Missing the required parameter 'id' when calling detailSession");
}
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/sessions/{id}".replace("{id}", ApiClient.urlEncode(id.toString()));
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;
}
/**
* List sessions Retrieves a list of active sessions resources; supports filtering, sorting, and
* pagination. Sessions are tied to an API session and are moved when an API session times out
* or logs out. Active sessions (i.e. Ziti SDK connected to an edge router) will keep the
* session and API session marked as active.
*
* @param limit (optional)
* @param offset (optional)
* @param filter (optional)
* @return CompletableFuture<ListSessionsEnvelope>
* @throws ApiException if fails to make API call
*/
public CompletableFuture listSessions(
Integer limit, Integer offset, String filter) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder =
listSessionsRequestBuilder(limit, offset, filter);
return memberVarHttpClient
.sendAsync(localVarRequestBuilder.build(), HttpResponse.BodyHandlers.ofString())
.thenComposeAsync(
localVarResponse -> {
if (localVarResponse.statusCode() / 100 != 2) {
return CompletableFuture.failedFuture(
getApiException("listSessions", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
responseBody == null || responseBody.isBlank()
? null
: memberVarObjectMapper.readValue(
responseBody,
new TypeReference<
ListSessionsEnvelope>() {}));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
/**
* List sessions Retrieves a list of active sessions resources; supports filtering, sorting, and
* pagination. Sessions are tied to an API session and are moved when an API session times out
* or logs out. Active sessions (i.e. Ziti SDK connected to an edge router) will keep the
* session and API session marked as active.
*
* @param limit (optional)
* @param offset (optional)
* @param filter (optional)
* @return CompletableFuture<ApiResponse<ListSessionsEnvelope>>
* @throws ApiException if fails to make API call
*/
public CompletableFuture> listSessionsWithHttpInfo(
Integer limit, Integer offset, String filter) throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder =
listSessionsRequestBuilder(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("listSessions", 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<
ListSessionsEnvelope>() {})));
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
} catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
private HttpRequest.Builder listSessionsRequestBuilder(
Integer limit, Integer offset, String filter) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/sessions";
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;
}
}