mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-04 11:26:09 +00:00
[java][apache-httpclient] update httpclient dependency to the latest 5.x (#14673)
* #14672 - adding generator with apache http client 5 * #14672 - adding generator with apache http client 5 * #14672 - adding generator with apache http client 5 * #14672 - adding generator with apache http client 5
This commit is contained in:
@@ -118,7 +118,7 @@ ext {
|
||||
jackson_databind_version = "2.14.1"
|
||||
jackson_databind_nullable_version = "0.2.4"
|
||||
jakarta_annotation_version = "1.3.5"
|
||||
httpclient_version = "4.5.13"
|
||||
httpclient_version = "5.1.3"
|
||||
jodatime_version = "2.9.9"
|
||||
junit_version = "4.13.2"
|
||||
}
|
||||
@@ -126,8 +126,7 @@ ext {
|
||||
dependencies {
|
||||
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
implementation "com.google.code.findbugs:jsr305:3.0.2"
|
||||
implementation "org.apache.httpcomponents:httpclient:$httpclient_version"
|
||||
implementation "org.apache.httpcomponents:httpmime:$httpclient_version"
|
||||
implementation "org.apache.httpcomponents.client5:httpclient5:$httpclient_version"
|
||||
implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||
implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||
implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
|
||||
|
||||
@@ -218,13 +218,8 @@
|
||||
|
||||
<!-- HTTP client: apache client -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
</dependency>
|
||||
|
||||
@@ -275,7 +270,7 @@
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<httpclient-version>4.5.13</httpclient-version>
|
||||
<httpclient-version>5.1.3</httpclient-version>
|
||||
<jackson-version>2.14.1</jackson-version>
|
||||
<jackson-databind-version>2.14.1</jackson-databind-version>
|
||||
<jackson-databind-nullable-version>0.2.4</jackson-databind-nullable-version>
|
||||
|
||||
@@ -21,29 +21,28 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.ParseException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.RequestBuilder;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.impl.client.BasicCookieStore;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.cookie.BasicClientCookie;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.http.cookie.Cookie;
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore;
|
||||
import org.apache.hc.client5.http.cookie.Cookie;
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
|
||||
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.client5.http.impl.cookie.BasicClientCookie;
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.Header;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.ParseException;
|
||||
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
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 java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -66,6 +65,7 @@ import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.Paths;
|
||||
@@ -608,7 +608,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
private ContentType getContentType(String headerValue) throws ApiException {
|
||||
try {
|
||||
return ContentType.parse(headerValue);
|
||||
} catch (ParseException e) {
|
||||
} catch (UnsupportedCharsetException e) {
|
||||
throw new ApiException("Could not parse content type " + headerValue);
|
||||
}
|
||||
}
|
||||
@@ -689,7 +689,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @throws IOException IO exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserialize(HttpResponse response, TypeReference<T> valueType) throws ApiException, IOException {
|
||||
public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueType) throws ApiException, IOException, ParseException {
|
||||
if (valueType == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -719,14 +719,14 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"Deserialization for content type '" + mimeType + "' not supported for type '" + valueType + "'",
|
||||
response.getStatusLine().getStatusCode(),
|
||||
response.getCode(),
|
||||
responseHeaders,
|
||||
EntityUtils.toString(entity)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private File downloadFileFromResponse(HttpResponse response) throws IOException {
|
||||
private File downloadFileFromResponse(CloseableHttpResponse response) throws IOException {
|
||||
Header contentDispositionHeader = response.getFirstHeader("Content-Disposition");
|
||||
String contentDisposition = contentDispositionHeader == null ? null : contentDispositionHeader.getValue();
|
||||
File file = prepareDownloadFile(contentDisposition);
|
||||
@@ -851,13 +851,13 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
protected <T> T processResponse(CloseableHttpResponse response, TypeReference<T> returnType) throws ApiException, IOException {
|
||||
statusCode = response.getStatusLine().getStatusCode();
|
||||
protected <T> T processResponse(CloseableHttpResponse response, TypeReference<T> returnType) throws ApiException, IOException, ParseException {
|
||||
statusCode = response.getCode();
|
||||
if (statusCode == HttpStatus.SC_NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
responseHeaders = transformResponseHeaders(response.getAllHeaders());
|
||||
responseHeaders = transformResponseHeaders(response.getHeaders());
|
||||
if (isSuccessfulStatus(statusCode)) {
|
||||
return this.deserialize(response, returnType);
|
||||
} else {
|
||||
@@ -907,14 +907,9 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);
|
||||
final String url = buildUrl(path, queryParams, collectionQueryParams, urlQueryDeepObject);
|
||||
|
||||
RequestBuilder builder = RequestBuilder.create(method);
|
||||
ClassicRequestBuilder builder = ClassicRequestBuilder.create(method);
|
||||
builder.setUri(url);
|
||||
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setConnectionRequestTimeout(connectionTimeout)
|
||||
.build();
|
||||
builder.setConfig(config);
|
||||
|
||||
if (accept != null) {
|
||||
builder.addHeader("Accept", accept);
|
||||
}
|
||||
@@ -955,7 +950,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
|
||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||
return processResponse(response, returnType);
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | ParseException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user