Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* dip-mds
* DIP-Massendatenschnittstelle
*
* The version of the OpenAPI document: DIP-MDS 1.3
* The version of the OpenAPI document: DIP-MDS 2.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -56,6 +56,7 @@
import java.util.Date;
import java.util.function.Supplier;
import java.util.TimeZone;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -77,11 +78,12 @@
import java.text.DateFormat;

import software.xdev.bzst.dip.client.generated.client.auth.Authentication;
import software.xdev.bzst.dip.client.generated.client.auth.HttpBearerAuth;

public class ApiClient extends JavaTimeFormatter {
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
private String basePath = "http://localhost";
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
protected String basePath = "http://localhost";
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
new ServerConfiguration(
"",
Expand All @@ -91,22 +93,22 @@ public class ApiClient extends JavaTimeFormatter {
));
protected Integer serverIndex = 0;
protected Map<String, String> serverVariables = null;
private boolean debugging = false;
private int connectionTimeout = 0;
protected boolean debugging = false;
protected int connectionTimeout = 0;

private CloseableHttpClient httpClient;
private ObjectMapper objectMapper;
protected CloseableHttpClient httpClient;
protected ObjectMapper objectMapper;
protected String tempFolderPath = null;

private Map<String, Authentication> authentications;
protected Map<String, Authentication> authentications;

private int statusCode;
private Map<String, List<String>> responseHeaders;
protected ThreadLocal<Integer> lastStatusCode = new ThreadLocal<>();
protected ThreadLocal<Map<String, List<String>>> lastResponseHeaders = new ThreadLocal<>();

private DateFormat dateFormat;
protected DateFormat dateFormat;

// Methods that can have a request body
private static List<String> bodyMethods = Arrays.asList("POST", "PUT", "DELETE", "PATCH");
protected static List<String> bodyMethods = Arrays.asList("POST", "PUT", "DELETE", "PATCH");

public ApiClient(CloseableHttpClient httpClient) {
objectMapper = new ObjectMapper();
Expand All @@ -118,15 +120,17 @@ public ApiClient(CloseableHttpClient httpClient) {
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new JsonNullableModule());
objectMapper.registerModule(new RFC3339JavaTimeModule());
objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat());

dateFormat = ApiClient.buildDefaultDateFormat();

// Set default User-Agent.
setUserAgent("OpenAPI-Generator/DIP-MDS 1.3/java");
setUserAgent("OpenAPI-Generator/DIP-MDS 2.1/java");

// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("BearerAuth", new HttpBearerAuth("bearer"));
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);

Expand Down Expand Up @@ -245,16 +249,18 @@ public ApiClient setServerVariables(Map<String, String> serverVariables) {
*
* @return Status code
*/
@Deprecated
public int getStatusCode() {
return statusCode;
return lastStatusCode.get();
}

/**
* Gets the response headers of the previous request
* @return Response headers
*/
@Deprecated
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
return lastResponseHeaders.get();
}

/**
Expand Down Expand Up @@ -286,6 +292,35 @@ public String getTempFolderPath() {
return tempFolderPath;
}

/**
* Helper method to set access token for the first Bearer authentication.
* @param bearerToken Bearer token
* @return API client
*/
public ApiClient setBearerToken(String bearerToken) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(bearerToken);
return this;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}

/**
* Helper method to set the supplier of access tokens for Bearer authentication.
*
* @param tokenSupplier the token supplier function
*/
public void setBearerToken(Supplier<String> tokenSupplier) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(tokenSupplier);
return;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}



Expand All @@ -295,7 +330,7 @@ public String getTempFolderPath() {
* @param userAgent User agent
* @return API client
*/
public ApiClient setUserAgent(String userAgent) {
public final ApiClient setUserAgent(String userAgent) {
addDefaultHeader("User-Agent", userAgent);
return this;
}
Expand All @@ -317,7 +352,7 @@ public ApiClient setTempFolderPath(String tempFolderPath) {
* @param value The header's value
* @return API client
*/
public ApiClient addDefaultHeader(String key, String value) {
public final ApiClient addDefaultHeader(String key, String value) {
defaultHeaderMap.put(key, value);
return this;
}
Expand Down Expand Up @@ -473,7 +508,7 @@ public List<Pair> parameterToPair(String name, Object value) {
* @param value The value of the parameter.
* @return A list of {@code Pair} objects.
*/
public List<Pair> parameterToPairs(String collectionFormat, String name, Collection value) {
public List<Pair> parameterToPairs(String collectionFormat, String name, Collection<?> value) {
List<Pair> params = new ArrayList<Pair>();

// preconditions
Expand Down Expand Up @@ -607,7 +642,7 @@ protected Map<String, List<String>> transformResponseHeaders(Header[] headers) {
/**
* Parse content type object from header value
*/
private ContentType getContentType(String headerValue) throws ApiException {
protected ContentType getContentType(String headerValue) throws ApiException {
try {
return ContentType.parse(headerValue);
} catch (UnsupportedCharsetException e) {
Expand All @@ -618,7 +653,7 @@ private ContentType getContentType(String headerValue) throws ApiException {
/**
* Get content type of a response or null if one was not provided
*/
private String getResponseMimeType(HttpResponse response) throws ApiException {
protected String getResponseMimeType(HttpResponse response) throws ApiException {
Header contentTypeHeader = response.getFirstHeader("Content-Type");
if (contentTypeHeader != null) {
return getContentType(contentTypeHeader.getValue()).getMimeType();
Expand Down Expand Up @@ -713,10 +748,11 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
}

return objectMapper.readValue(content, valueType);
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
} else if (mimeType.toLowerCase().startsWith("text/")) {
// convert input stream to string
return (T) EntityUtils.toString(entity);
} else {
Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
throw new ApiException(
"Deserialization for content type '" + mimeType + "' not supported for type '" + valueType + "'",
response.getCode(),
Expand All @@ -726,7 +762,7 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
}
}

private File downloadFileFromResponse(CloseableHttpResponse response) throws IOException {
protected File downloadFileFromResponse(CloseableHttpResponse response) throws IOException {
Header contentDispositionHeader = response.getFirstHeader("Content-Disposition");
String contentDisposition = contentDispositionHeader == null ? null : contentDispositionHeader.getValue();
File file = prepareDownloadFile(contentDisposition);
Expand Down Expand Up @@ -778,6 +814,7 @@ public String getBaseURL() {
if (serverIndex != null) {
if (serverIndex < 0 || serverIndex >= servers.size()) {
throw new ArrayIndexOutOfBoundsException(String.format(
Locale.ROOT,
"Invalid index %d when selecting the host settings. Must be less than %d", serverIndex, servers.size()
));
}
Expand All @@ -797,7 +834,7 @@ public String getBaseURL() {
* @param urlQueryDeepObject URL query string of the deep object parameters
* @return The full URL
*/
private String buildUrl(String path, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject) {
protected String buildUrl(String path, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject) {
String baseURL = getBaseURL();

final StringBuilder url = new StringBuilder();
Expand Down Expand Up @@ -862,12 +899,15 @@ protected Cookie buildCookie(String key, String value, URI uri) {
}

protected <T> T processResponse(CloseableHttpResponse response, TypeReference<T> returnType) throws ApiException, IOException, ParseException {
statusCode = response.getCode();
int statusCode = response.getCode();
lastStatusCode.set(statusCode);
if (statusCode == HttpStatus.SC_NO_CONTENT) {
return null;
}

responseHeaders = transformResponseHeaders(response.getHeaders());
Map<String, List<String>> responseHeaders = transformResponseHeaders(response.getHeaders());
lastResponseHeaders.set(responseHeaders);

if (isSuccessfulStatus(statusCode)) {
return this.deserialize(response, returnType);
} else {
Expand Down Expand Up @@ -973,7 +1013,7 @@ public <T> T invokeAPI(
* @param headerParams Header parameters
* @param cookieParams Cookie parameters
*/
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* dip-mds
* DIP-Massendatenschnittstelle
*
* The version of the OpenAPI document: DIP-MDS 1.3
* The version of the OpenAPI document: DIP-MDS 2.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* dip-mds
* DIP-Massendatenschnittstelle
*
* The version of the OpenAPI document: DIP-MDS 1.3
* The version of the OpenAPI document: DIP-MDS 2.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* dip-mds
* DIP-Massendatenschnittstelle
*
* The version of the OpenAPI document: DIP-MDS 1.3
* The version of the OpenAPI document: DIP-MDS 2.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -13,28 +13,50 @@

package software.xdev.bzst.dip.client.generated.client;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

public class Configuration {
public static final String VERSION = "DIP-MDS 1.3";

private static ApiClient defaultApiClient = new ApiClient();

/**
* Get the default API client, which would be used when creating API
* instances without providing an API client.
*
* @return Default API client
*/
public static ApiClient getDefaultApiClient() {
return defaultApiClient;
}
public static final String VERSION = "DIP-MDS 2.1";

private static final AtomicReference<ApiClient> defaultApiClient = new AtomicReference<>();
private static volatile Supplier<ApiClient> apiClientFactory = ApiClient::new;

/**
* Set the default API client, which would be used when creating API
* instances without providing an API client.
*
* @param apiClient API client
*/
public static void setDefaultApiClient(ApiClient apiClient) {
defaultApiClient = apiClient;
/**
* Get the default API client, which would be used when creating API instances without providing an API client.
*
* @return Default API client
*/
public static ApiClient getDefaultApiClient() {
ApiClient client = defaultApiClient.get();
if (client == null) {
client = defaultApiClient.updateAndGet(val -> {
if (val != null) { // changed by another thread
return val;
}
return apiClientFactory.get();
});
}
}
return client;
}

/**
* Set the default API client, which would be used when creating API instances without providing an API client.
*
* @param apiClient API client
*/
public static void setDefaultApiClient(ApiClient apiClient) {
defaultApiClient.set(apiClient);
}

/**
* set the callback used to create new ApiClient objects
*/
public static void setApiClientFactory(Supplier<ApiClient> factory) {
apiClientFactory = Objects.requireNonNull(factory);
}

private Configuration() {
}
}
Loading