From d7edbad8d649d2ebe83c7933124aef58a1f2b7fb Mon Sep 17 00:00:00 2001 From: Andre Vegas Date: Wed, 15 Feb 2023 02:12:39 -0500 Subject: [PATCH] [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 --- README.md | 16 ++--- docs/generators/java.md | 2 +- .../codegen/languages/JavaClientCodegen.java | 2 +- .../apache-httpclient/ApiClient.mustache | 69 +++++++++---------- .../apache-httpclient/build.gradle.mustache | 5 +- .../libraries/apache-httpclient/pom.mustache | 11 +-- .../java/apache-httpclient/build.gradle | 5 +- .../echo_api/java/apache-httpclient/pom.xml | 11 +-- .../org/openapitools/client/ApiClient.java | 69 +++++++++---------- .../java/apache-httpclient/build.gradle | 5 +- .../petstore/java/apache-httpclient/pom.xml | 11 +-- .../org/openapitools/client/ApiClient.java | 69 +++++++++---------- 12 files changed, 121 insertions(+), 154 deletions(-) diff --git a/README.md b/README.md index bf15a2ecb57..a3112f80708 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,13 @@ If you find OpenAPI Generator useful for work, please consider asking your compa ## Overview OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification) (both 2.0 and 3.0 are supported). Currently, the following languages/frameworks are supported: -| | Languages/Frameworks | -| -------------------------------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.1, .NET Core 3.1, .NET 5.0. Libraries: RestSharp, GenericHost, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Apache HttpClient, Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client, Helidon), **Jetbrains HTTP Client**, **Julia**, **k6**, **Kotlin**, **Lua**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (2.x - 13.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs) | -| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, Ktor, Vertx), **PHP** (Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), Scalatra) | -| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** | -| **Configuration files** | [**Apache2**](https://httpd.apache.org/) | -| **Others** | **GraphQL**, **JMeter**, **Ktorm**, **MySQL Schema**, **Protocol Buffer**, **WSDL** | +| | Languages/Frameworks | +| -------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.1, .NET Core 3.1, .NET 5.0. Libraries: RestSharp, GenericHost, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Apache HttpClient 4.x, Apache HttpClient 5.x, Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, MicroProfile Rest Client, Helidon), **Jetbrains HTTP Client**, **Julia**, **k6**, **Kotlin**, **Lua**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (AngularJS, Angular (2.x - 13.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs) | +| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, Ktor, Vertx), **PHP** (Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), Scalatra) | +| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** | +| **Configuration files** | [**Apache2**](https://httpd.apache.org/) | +| **Others** | **GraphQL**, **JMeter**, **Ktorm**, **MySQL Schema**, **Protocol Buffer**, **WSDL** | ## Table of contents @@ -957,7 +957,7 @@ Here is a list of template creators: * Java (Google APIs Client Library): @charlescapps * Java (Rest-assured): @viclovsky * Java (Java 11 Native HTTP client): @bbdouglas - * Java (Apache HttpClient): @harrywhite4 + * Java (Apache HttpClient 5.x): @harrywhite4 @andrevegas * Java (Helidon): @spericas @tjquinno @tvallin * Javascript/NodeJS: @jfiala * JavaScript (Apollo DataSource): @erithmetic diff --git a/docs/generators/java.md b/docs/generators/java.md index 9412972ea89..55bc644c86b 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -57,7 +57,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null| |invokerPackage|root package for generated code| |org.openapitools.client| |legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| -|library|library template (sub-template) to use|
**jersey1**
HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead.
**jersey2**
HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x
**jersey3**
HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x
**feign**
HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x. or Gson 2.x
**okhttp-gson**
[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
**retrofit2**
HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
**resttemplate**
HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x
**webclient**
HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x
**resteasy**
HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x
**vertx**
HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x
**google-api-client**
HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x
**rest-assured**
HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8
**native**
HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+
**microprofile**
HTTP client: Microprofile client 1.x. JSON processing: JSON-B or Jackson 2.9.x
**apache-httpclient**
HTTP client: Apache httpclient 4.x
|okhttp-gson| +|library|library template (sub-template) to use|
**jersey1**
HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey3' or other HTTP libraries instead.
**jersey2**
HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x
**jersey3**
HTTP client: Jersey client 3.x. JSON processing: Jackson 2.x
**feign**
HTTP client: OpenFeign 10.x. JSON processing: Jackson 2.9.x. or Gson 2.x
**okhttp-gson**
[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
**retrofit2**
HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)
**resttemplate**
HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x
**webclient**
HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x
**resteasy**
HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x
**vertx**
HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x
**google-api-client**
HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x
**rest-assured**
HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8
**native**
HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+
**microprofile**
HTTP client: Microprofile client 1.x. JSON processing: JSON-B or Jackson 2.9.x
**apache-httpclient**
HTTP client: Apache httpclient 5.x
|okhttp-gson| |licenseName|The name of the license| |Unlicense| |licenseUrl|The URL of the license| |http://unlicense.org| |microprofileFramework|Framework for microprofile. Possible values "kumuluzee"| |null| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 39255711a97..eb831dfa544 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -228,7 +228,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen supportedLibraries.put(REST_ASSURED, "HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.10.x. Only for Java 8"); supportedLibraries.put(NATIVE, "HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+"); supportedLibraries.put(MICROPROFILE, "HTTP client: Microprofile client 1.x. JSON processing: JSON-B or Jackson 2.9.x"); - supportedLibraries.put(APACHE, "HTTP client: Apache httpclient 4.x"); + supportedLibraries.put(APACHE, "HTTP client: Apache httpclient 5.x"); CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use"); libraryOption.setEnum(supportedLibraries); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache index 87568915770..14ec22fe248 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache @@ -13,29 +13,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; @@ -58,6 +57,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; @@ -735,7 +735,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { 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); } } @@ -816,7 +816,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { * @throws IOException IO exception */ @SuppressWarnings("unchecked") - public T deserialize(HttpResponse response, TypeReference valueType) throws ApiException, IOException { + public T deserialize(CloseableHttpResponse response, TypeReference valueType) throws ApiException, IOException, ParseException { if (valueType == null) { return null; } @@ -846,14 +846,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { } 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); @@ -978,13 +978,13 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return cookie; } - protected T processResponse(CloseableHttpResponse response, TypeReference returnType) throws ApiException, IOException { - statusCode = response.getStatusLine().getStatusCode(); + protected T processResponse(CloseableHttpResponse response, TypeReference 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 { @@ -1034,14 +1034,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { 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); } @@ -1082,7 +1077,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) { return processResponse(response, returnType); - } catch (IOException e) { + } catch (IOException | ParseException e) { throw new ApiException(e); } } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/build.gradle.mustache index 6c7379be3ce..f21d15812fe 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/build.gradle.mustache @@ -120,7 +120,7 @@ ext { jackson_databind_nullable_version = "0.2.4" {{/openApiNullable}} 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" } @@ -128,8 +128,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" diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/pom.mustache index 75ec717fec4..84251301092 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/pom.mustache @@ -232,13 +232,8 @@ - org.apache.httpcomponents - httpclient - ${httpclient-version} - - - org.apache.httpcomponents - httpmime + org.apache.httpcomponents.client5 + httpclient5 ${httpclient-version} @@ -337,7 +332,7 @@ {{#swagger1AnnotationLibrary}} 1.6.6 {{/swagger1AnnotationLibrary}} - 4.5.13 + 5.1.3 2.14.1 2.14.1 {{#openApiNullable}} diff --git a/samples/client/echo_api/java/apache-httpclient/build.gradle b/samples/client/echo_api/java/apache-httpclient/build.gradle index 0f232470e16..fb375783d8c 100644 --- a/samples/client/echo_api/java/apache-httpclient/build.gradle +++ b/samples/client/echo_api/java/apache-httpclient/build.gradle @@ -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" diff --git a/samples/client/echo_api/java/apache-httpclient/pom.xml b/samples/client/echo_api/java/apache-httpclient/pom.xml index ff221f1c1b6..f3b687231bc 100644 --- a/samples/client/echo_api/java/apache-httpclient/pom.xml +++ b/samples/client/echo_api/java/apache-httpclient/pom.xml @@ -218,13 +218,8 @@ - org.apache.httpcomponents - httpclient - ${httpclient-version} - - - org.apache.httpcomponents - httpmime + org.apache.httpcomponents.client5 + httpclient5 ${httpclient-version} @@ -275,7 +270,7 @@ UTF-8 - 4.5.13 + 5.1.3 2.14.1 2.14.1 0.2.4 diff --git a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java index 58de7cfee18..3d8794d49af 100644 --- a/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java @@ -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 deserialize(HttpResponse response, TypeReference valueType) throws ApiException, IOException { + public T deserialize(CloseableHttpResponse response, TypeReference 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 processResponse(CloseableHttpResponse response, TypeReference returnType) throws ApiException, IOException { - statusCode = response.getStatusLine().getStatusCode(); + protected T processResponse(CloseableHttpResponse response, TypeReference 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); } } diff --git a/samples/client/petstore/java/apache-httpclient/build.gradle b/samples/client/petstore/java/apache-httpclient/build.gradle index 4378618057f..74a808e1983 100644 --- a/samples/client/petstore/java/apache-httpclient/build.gradle +++ b/samples/client/petstore/java/apache-httpclient/build.gradle @@ -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" diff --git a/samples/client/petstore/java/apache-httpclient/pom.xml b/samples/client/petstore/java/apache-httpclient/pom.xml index e87487e616b..92a8cc2c316 100644 --- a/samples/client/petstore/java/apache-httpclient/pom.xml +++ b/samples/client/petstore/java/apache-httpclient/pom.xml @@ -218,13 +218,8 @@ - org.apache.httpcomponents - httpclient - ${httpclient-version} - - - org.apache.httpcomponents - httpmime + org.apache.httpcomponents.client5 + httpclient5 ${httpclient-version} @@ -275,7 +270,7 @@ UTF-8 - 4.5.13 + 5.1.3 2.14.1 2.14.1 0.2.4 diff --git a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java index a8620ed4e71..3a0c4c5ef77 100644 --- a/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/apache-httpclient/src/main/java/org/openapitools/client/ApiClient.java @@ -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; @@ -751,7 +751,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); } } @@ -832,7 +832,7 @@ public class ApiClient extends JavaTimeFormatter { * @throws IOException IO exception */ @SuppressWarnings("unchecked") - public T deserialize(HttpResponse response, TypeReference valueType) throws ApiException, IOException { + public T deserialize(CloseableHttpResponse response, TypeReference valueType) throws ApiException, IOException, ParseException { if (valueType == null) { return null; } @@ -862,14 +862,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); @@ -994,13 +994,13 @@ public class ApiClient extends JavaTimeFormatter { return cookie; } - protected T processResponse(CloseableHttpResponse response, TypeReference returnType) throws ApiException, IOException { - statusCode = response.getStatusLine().getStatusCode(); + protected T processResponse(CloseableHttpResponse response, TypeReference 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 { @@ -1050,14 +1050,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); } @@ -1098,7 +1093,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); } }