Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import org.openapitools.jackson.nullable.JsonNullableJackson3Module;
{{/useJackson3}}
{{/openApiNullable}}

import org.apache.hc.client5.http.config.Configurable;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
Expand All @@ -53,6 +55,7 @@ import org.apache.hc.core5.http.io.entity.FileEntity;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.util.Timeout;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -135,6 +138,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
protected Map<String, String> serverVariables = null;
protected boolean debugging = false;
protected int connectionTimeout = 0;
protected int readTimeout = 0;

protected CloseableHttpClient httpClient;
protected ObjectMapper objectMapper;
Expand Down Expand Up @@ -555,15 +559,50 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

/**
* Set the connect timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
* A value of 0 means the HTTP client's default connect timeout is used,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* The timeout is applied to each request via its request configuration;
* other request configuration defaults of the underlying HTTP client
* are preserved.
* @param connectionTimeout Connection timeout in milliseconds
* @return API client
* @throws IllegalArgumentException if connectionTimeout is negative
*/
public ApiClient setConnectTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}
public ApiClient setConnectTimeout(int connectionTimeout) {
if (connectionTimeout < 0) {
throw new IllegalArgumentException("connectionTimeout must not be negative");
}
this.connectionTimeout = connectionTimeout;
return this;
}

/**
* Read timeout (in milliseconds).
* @return Read timeout
*/
public int getReadTimeout() {
return readTimeout;
}

/**
* Set the read timeout (in milliseconds), i.e. the response timeout
* while waiting for data after the connection is established.
* A value of 0 means the HTTP client's default response timeout is used,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* The timeout is applied to each request via its request configuration;
* other request configuration defaults of the underlying HTTP client
* are preserved.
* @param readTimeout Read timeout in milliseconds
* @return API client
* @throws IllegalArgumentException if readTimeout is negative
*/
public ApiClient setReadTimeout(int readTimeout) {
if (readTimeout < 0) {
throw new IllegalArgumentException("readTimeout must not be negative");
}
this.readTimeout = readTimeout;
return this;
}

/**
* Get the date format used to parse/format date parameters.
Expand Down Expand Up @@ -1150,6 +1189,20 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(store);

if (connectionTimeout > 0 || readTimeout > 0) {
// start from the default request configuration of the underlying HTTP client, if
// accessible, so that only the configured timeouts are overridden
RequestConfig defaultConfig = httpClient instanceof Configurable ? ((Configurable) httpClient).getConfig() : null;
RequestConfig.Builder requestConfigBuilder = defaultConfig == null ? RequestConfig.custom() : RequestConfig.copy(defaultConfig);
if (connectionTimeout > 0) {
requestConfigBuilder.setConnectTimeout(Timeout.ofMilliseconds(connectionTimeout));
}
if (readTimeout > 0) {
requestConfigBuilder.setResponseTimeout(Timeout.ofMilliseconds(readTimeout));
}
context.setRequestConfig(requestConfigBuilder.build());
}

ContentType contentTypeObj = getContentType(contentType);
if (body != null || !formParams.isEmpty()) {
if (isBodyAllowed(method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import org.openapitools.jackson.nullable.JsonNullableModule;

import org.apache.hc.client5.http.config.Configurable;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
Expand All @@ -42,6 +44,7 @@
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.util.Timeout;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -95,6 +98,7 @@ public class ApiClient extends JavaTimeFormatter {
protected Map<String, String> serverVariables = null;
protected boolean debugging = false;
protected int connectionTimeout = 0;
protected int readTimeout = 0;

protected CloseableHttpClient httpClient;
protected ObjectMapper objectMapper;
Expand Down Expand Up @@ -430,15 +434,50 @@ public int getConnectTimeout() {

/**
* Set the connect timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
* A value of 0 means the HTTP client's default connect timeout is used,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* The timeout is applied to each request via its request configuration;
* other request configuration defaults of the underlying HTTP client
* are preserved.
* @param connectionTimeout Connection timeout in milliseconds
* @return API client
* @throws IllegalArgumentException if connectionTimeout is negative
*/
public ApiClient setConnectTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}
public ApiClient setConnectTimeout(int connectionTimeout) {
if (connectionTimeout < 0) {
throw new IllegalArgumentException("connectionTimeout must not be negative");
}
this.connectionTimeout = connectionTimeout;
return this;
}

/**
* Read timeout (in milliseconds).
* @return Read timeout
*/
public int getReadTimeout() {
return readTimeout;
}

/**
* Set the read timeout (in milliseconds), i.e. the response timeout
* while waiting for data after the connection is established.
* A value of 0 means the HTTP client's default response timeout is used,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* The timeout is applied to each request via its request configuration;
* other request configuration defaults of the underlying HTTP client
* are preserved.
* @param readTimeout Read timeout in milliseconds
* @return API client
* @throws IllegalArgumentException if readTimeout is negative
*/
public ApiClient setReadTimeout(int readTimeout) {
if (readTimeout < 0) {
throw new IllegalArgumentException("readTimeout must not be negative");
}
this.readTimeout = readTimeout;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
return this;
}

/**
* Get the date format used to parse/format date parameters.
Expand Down Expand Up @@ -1016,6 +1055,20 @@ public <T> T invokeAPI(
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(store);

if (connectionTimeout > 0 || readTimeout > 0) {
// start from the default request configuration of the underlying HTTP client, if
// accessible, so that only the configured timeouts are overridden
RequestConfig defaultConfig = httpClient instanceof Configurable ? ((Configurable) httpClient).getConfig() : null;
RequestConfig.Builder requestConfigBuilder = defaultConfig == null ? RequestConfig.custom() : RequestConfig.copy(defaultConfig);
if (connectionTimeout > 0) {
requestConfigBuilder.setConnectTimeout(Timeout.ofMilliseconds(connectionTimeout));
}
if (readTimeout > 0) {
requestConfigBuilder.setResponseTimeout(Timeout.ofMilliseconds(readTimeout));
}
context.setRequestConfig(requestConfigBuilder.build());
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
}

ContentType contentTypeObj = getContentType(contentType);
if (body != null || !formParams.isEmpty()) {
if (isBodyAllowed(method)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import tools.jackson.core.JacksonException;
import org.openapitools.jackson.nullable.JsonNullableJackson3Module;

import org.apache.hc.client5.http.config.Configurable;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
Expand All @@ -44,6 +46,7 @@
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.util.Timeout;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -142,6 +145,7 @@ public class ApiClient extends JavaTimeFormatter {
protected Map<String, String> serverVariables = null;
protected boolean debugging = false;
protected int connectionTimeout = 0;
protected int readTimeout = 0;

protected CloseableHttpClient httpClient;
protected ObjectMapper objectMapper;
Expand Down Expand Up @@ -525,15 +529,50 @@ public int getConnectTimeout() {

/**
* Set the connect timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
* {@link Integer#MAX_VALUE}.
* A value of 0 means the HTTP client's default connect timeout is used,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* The timeout is applied to each request via its request configuration;
* other request configuration defaults of the underlying HTTP client
* are preserved.
* @param connectionTimeout Connection timeout in milliseconds
* @return API client
* @throws IllegalArgumentException if connectionTimeout is negative
*/
public ApiClient setConnectTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}
public ApiClient setConnectTimeout(int connectionTimeout) {
if (connectionTimeout < 0) {
throw new IllegalArgumentException("connectionTimeout must not be negative");
}
this.connectionTimeout = connectionTimeout;
return this;
}

/**
* Read timeout (in milliseconds).
* @return Read timeout
*/
public int getReadTimeout() {
return readTimeout;
}

/**
* Set the read timeout (in milliseconds), i.e. the response timeout
* while waiting for data after the connection is established.
* A value of 0 means the HTTP client's default response timeout is used,
* otherwise values must be between 1 and {@link Integer#MAX_VALUE}.
* The timeout is applied to each request via its request configuration;
* other request configuration defaults of the underlying HTTP client
* are preserved.
* @param readTimeout Read timeout in milliseconds
* @return API client
* @throws IllegalArgumentException if readTimeout is negative
*/
public ApiClient setReadTimeout(int readTimeout) {
if (readTimeout < 0) {
throw new IllegalArgumentException("readTimeout must not be negative");
}
this.readTimeout = readTimeout;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
return this;
}

/**
* Get the date format used to parse/format date parameters.
Expand Down Expand Up @@ -1115,6 +1154,20 @@ public <T> T invokeAPI(
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(store);

if (connectionTimeout > 0 || readTimeout > 0) {
// start from the default request configuration of the underlying HTTP client, if
// accessible, so that only the configured timeouts are overridden
RequestConfig defaultConfig = httpClient instanceof Configurable ? ((Configurable) httpClient).getConfig() : null;
RequestConfig.Builder requestConfigBuilder = defaultConfig == null ? RequestConfig.custom() : RequestConfig.copy(defaultConfig);
if (connectionTimeout > 0) {
requestConfigBuilder.setConnectTimeout(Timeout.ofMilliseconds(connectionTimeout));
}
if (readTimeout > 0) {
requestConfigBuilder.setResponseTimeout(Timeout.ofMilliseconds(readTimeout));
}
context.setRequestConfig(requestConfigBuilder.build());
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
}

ContentType contentTypeObj = getContentType(contentType);
if (body != null || !formParams.isEmpty()) {
if (isBodyAllowed(method)) {
Expand Down
Loading
Loading