mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-19 09:07:07 +00:00
[JAVA][NATIVE] Add gzip capability (#22358)
* add gzip capability * fixed test * added docstring * regenerated samples
This commit is contained in:
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.http.HttpClient;
|
||||
@@ -34,6 +35,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.Optional;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
@@ -62,7 +65,7 @@ public class ApiClient {
|
||||
protected String basePath;
|
||||
protected Consumer<HttpRequest.Builder> interceptor;
|
||||
protected Consumer<HttpResponse<InputStream>> responseInterceptor;
|
||||
protected Consumer<HttpResponse<String>> asyncResponseInterceptor;
|
||||
protected Consumer<HttpResponse<InputStream>> asyncResponseInterceptor;
|
||||
protected Duration readTimeout;
|
||||
protected Duration connectTimeout;
|
||||
|
||||
@@ -384,7 +387,7 @@ public class ApiClient {
|
||||
* of null resets the interceptor to a no-op.
|
||||
* @return This object.
|
||||
*/
|
||||
public ApiClient setAsyncResponseInterceptor(Consumer<HttpResponse<String>> interceptor) {
|
||||
public ApiClient setAsyncResponseInterceptor(Consumer<HttpResponse<InputStream>> interceptor) {
|
||||
this.asyncResponseInterceptor = interceptor;
|
||||
return this;
|
||||
}
|
||||
@@ -394,7 +397,7 @@ public class ApiClient {
|
||||
*
|
||||
* @return The custom interceptor that was set, or null if there isn't any.
|
||||
*/
|
||||
public Consumer<HttpResponse<String>> getAsyncResponseInterceptor() {
|
||||
public Consumer<HttpResponse<InputStream>> getAsyncResponseInterceptor() {
|
||||
return asyncResponseInterceptor;
|
||||
}
|
||||
|
||||
@@ -454,4 +457,32 @@ public class ApiClient {
|
||||
public Duration getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the response body InputStream, transparently decoding gzip-compressed
|
||||
* payloads when the server sets {@code Content-Encoding: gzip}.
|
||||
*
|
||||
* @param response HTTP response whose body should be consumed
|
||||
* @return Original or decompressed InputStream for the response body
|
||||
* @throws IOException if the response body cannot be accessed or wrapping fails
|
||||
*/
|
||||
public static InputStream getResponseBody(HttpResponse<InputStream> response) throws IOException {
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
InputStream body = response.body();
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
Optional<String> encoding = response.headers().firstValue("Content-Encoding");
|
||||
if (encoding.isPresent()) {
|
||||
for (String token : encoding.get().split(",")) {
|
||||
if ("gzip".equalsIgnoreCase(token.trim())) {
|
||||
return new GZIPInputStream(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class AuthApi {
|
||||
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
|
||||
private final Duration memberVarReadTimeout;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
|
||||
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
|
||||
|
||||
public AuthApi() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
@@ -91,7 +91,15 @@ public class AuthApi {
|
||||
|
||||
|
||||
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
|
||||
String body = response.body() == null ? null : new String(response.body().readAllBytes());
|
||||
InputStream responseBody = ApiClient.getResponseBody(response);
|
||||
String body = null;
|
||||
try {
|
||||
body = responseBody == null ? null : new String(responseBody.readAllBytes());
|
||||
} finally {
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
String message = formatExceptionMessage(operationId, response.statusCode(), body);
|
||||
return new ApiException(response.statusCode(), message, response.headers(), body);
|
||||
}
|
||||
@@ -110,10 +118,13 @@ public class AuthApi {
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response, InputStream responseBody) throws ApiException {
|
||||
if (responseBody == null) {
|
||||
throw new ApiException(new IOException("Response body is empty"));
|
||||
}
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -199,6 +210,7 @@ public class AuthApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testAuthHttpBasic", localVarResponse);
|
||||
@@ -206,7 +218,8 @@ public class AuthApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -217,6 +230,9 @@ public class AuthApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -297,6 +313,7 @@ public class AuthApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testAuthHttpBearer", localVarResponse);
|
||||
@@ -304,7 +321,8 @@ public class AuthApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -315,6 +333,9 @@ public class AuthApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class BodyApi {
|
||||
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
|
||||
private final Duration memberVarReadTimeout;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
|
||||
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
|
||||
|
||||
public BodyApi() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
@@ -101,7 +101,15 @@ public class BodyApi {
|
||||
|
||||
|
||||
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
|
||||
String body = response.body() == null ? null : new String(response.body().readAllBytes());
|
||||
InputStream responseBody = ApiClient.getResponseBody(response);
|
||||
String body = null;
|
||||
try {
|
||||
body = responseBody == null ? null : new String(responseBody.readAllBytes());
|
||||
} finally {
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
String message = formatExceptionMessage(operationId, response.statusCode(), body);
|
||||
return new ApiException(response.statusCode(), message, response.headers(), body);
|
||||
}
|
||||
@@ -120,10 +128,13 @@ public class BodyApi {
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response, InputStream responseBody) throws ApiException {
|
||||
if (responseBody == null) {
|
||||
throw new ApiException(new IOException("Response body is empty"));
|
||||
}
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -209,11 +220,13 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testBinaryGif", localVarResponse);
|
||||
}
|
||||
if (localVarResponse.body() == null) {
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
if (localVarResponseBody == null) {
|
||||
return new ApiResponse<File>(
|
||||
localVarResponse.statusCode(),
|
||||
localVarResponse.headers().map(),
|
||||
@@ -223,9 +236,8 @@ public class BodyApi {
|
||||
|
||||
|
||||
// Handle file downloading.
|
||||
File responseValue = downloadFileFromResponse(localVarResponse);
|
||||
File responseValue = downloadFileFromResponse(localVarResponse, localVarResponseBody);
|
||||
|
||||
localVarResponse.body().close();
|
||||
|
||||
return new ApiResponse<File>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -233,6 +245,9 @@ public class BodyApi {
|
||||
responseValue
|
||||
);
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -317,6 +332,7 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testBodyApplicationOctetstreamBinary", localVarResponse);
|
||||
@@ -324,7 +340,8 @@ public class BodyApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -335,6 +352,9 @@ public class BodyApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -425,6 +445,7 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testBodyMultipartFormdataArrayOfBinary", localVarResponse);
|
||||
@@ -432,7 +453,8 @@ public class BodyApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -443,6 +465,9 @@ public class BodyApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -497,8 +522,9 @@ public class BodyApi {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] formBytes = formOutputStream.toByteArray();
|
||||
formDataPublisher = HttpRequest.BodyPublishers
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray()));
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formBytes));
|
||||
}
|
||||
localVarRequestBuilder
|
||||
.header("Content-Type", entity.getContentType().getValue())
|
||||
@@ -566,6 +592,7 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testBodyMultipartFormdataSingleBinary", localVarResponse);
|
||||
@@ -573,7 +600,8 @@ public class BodyApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -584,6 +612,9 @@ public class BodyApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -632,8 +663,9 @@ public class BodyApi {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] formBytes = formOutputStream.toByteArray();
|
||||
formDataPublisher = HttpRequest.BodyPublishers
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray()));
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formBytes));
|
||||
}
|
||||
localVarRequestBuilder
|
||||
.header("Content-Type", entity.getContentType().getValue())
|
||||
@@ -701,11 +733,13 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEchoBodyAllOfPet", localVarResponse);
|
||||
}
|
||||
if (localVarResponse.body() == null) {
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
if (localVarResponseBody == null) {
|
||||
return new ApiResponse<Pet>(
|
||||
localVarResponse.statusCode(),
|
||||
localVarResponse.headers().map(),
|
||||
@@ -715,10 +749,9 @@ public class BodyApi {
|
||||
|
||||
|
||||
|
||||
String responseBody = new String(localVarResponse.body().readAllBytes());
|
||||
String responseBody = new String(localVarResponseBody.readAllBytes());
|
||||
Pet responseValue = responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference<Pet>() {});
|
||||
|
||||
localVarResponse.body().close();
|
||||
|
||||
return new ApiResponse<Pet>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -726,6 +759,9 @@ public class BodyApi {
|
||||
responseValue
|
||||
);
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -816,6 +852,7 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEchoBodyFreeFormObjectResponseString", localVarResponse);
|
||||
@@ -823,7 +860,8 @@ public class BodyApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -834,6 +872,9 @@ public class BodyApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -924,11 +965,13 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEchoBodyPet", localVarResponse);
|
||||
}
|
||||
if (localVarResponse.body() == null) {
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
if (localVarResponseBody == null) {
|
||||
return new ApiResponse<Pet>(
|
||||
localVarResponse.statusCode(),
|
||||
localVarResponse.headers().map(),
|
||||
@@ -938,10 +981,9 @@ public class BodyApi {
|
||||
|
||||
|
||||
|
||||
String responseBody = new String(localVarResponse.body().readAllBytes());
|
||||
String responseBody = new String(localVarResponseBody.readAllBytes());
|
||||
Pet responseValue = responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference<Pet>() {});
|
||||
|
||||
localVarResponse.body().close();
|
||||
|
||||
return new ApiResponse<Pet>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -949,6 +991,9 @@ public class BodyApi {
|
||||
responseValue
|
||||
);
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1039,6 +1084,7 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEchoBodyPetResponseString", localVarResponse);
|
||||
@@ -1046,7 +1092,8 @@ public class BodyApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1057,6 +1104,9 @@ public class BodyApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1147,11 +1197,13 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEchoBodyStringEnum", localVarResponse);
|
||||
}
|
||||
if (localVarResponse.body() == null) {
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
if (localVarResponseBody == null) {
|
||||
return new ApiResponse<StringEnumRef>(
|
||||
localVarResponse.statusCode(),
|
||||
localVarResponse.headers().map(),
|
||||
@@ -1161,10 +1213,9 @@ public class BodyApi {
|
||||
|
||||
|
||||
|
||||
String responseBody = new String(localVarResponse.body().readAllBytes());
|
||||
String responseBody = new String(localVarResponseBody.readAllBytes());
|
||||
StringEnumRef responseValue = responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference<StringEnumRef>() {});
|
||||
|
||||
localVarResponse.body().close();
|
||||
|
||||
return new ApiResponse<StringEnumRef>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1172,6 +1223,9 @@ public class BodyApi {
|
||||
responseValue
|
||||
);
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1262,6 +1316,7 @@ public class BodyApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEchoBodyTagResponseString", localVarResponse);
|
||||
@@ -1269,7 +1324,8 @@ public class BodyApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1280,6 +1336,9 @@ public class BodyApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class FormApi {
|
||||
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
|
||||
private final Duration memberVarReadTimeout;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
|
||||
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
|
||||
|
||||
public FormApi() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
@@ -98,7 +98,15 @@ public class FormApi {
|
||||
|
||||
|
||||
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
|
||||
String body = response.body() == null ? null : new String(response.body().readAllBytes());
|
||||
InputStream responseBody = ApiClient.getResponseBody(response);
|
||||
String body = null;
|
||||
try {
|
||||
body = responseBody == null ? null : new String(responseBody.readAllBytes());
|
||||
} finally {
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
String message = formatExceptionMessage(operationId, response.statusCode(), body);
|
||||
return new ApiException(response.statusCode(), message, response.headers(), body);
|
||||
}
|
||||
@@ -117,10 +125,13 @@ public class FormApi {
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response, InputStream responseBody) throws ApiException {
|
||||
if (responseBody == null) {
|
||||
throw new ApiException(new IOException("Response body is empty"));
|
||||
}
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -218,6 +229,7 @@ public class FormApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testFormIntegerBooleanString", localVarResponse);
|
||||
@@ -225,7 +237,8 @@ public class FormApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -236,6 +249,9 @@ public class FormApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -273,10 +289,11 @@ public class FormApi {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] formBytes = formOutputStream.toByteArray();
|
||||
localVarRequestBuilder
|
||||
.header("Content-Type", entity.getContentType().getValue())
|
||||
.method("POST", HttpRequest.BodyPublishers
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray())));
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formBytes)));
|
||||
if (memberVarReadTimeout != null) {
|
||||
localVarRequestBuilder.timeout(memberVarReadTimeout);
|
||||
}
|
||||
@@ -340,6 +357,7 @@ public class FormApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testFormObjectMultipart", localVarResponse);
|
||||
@@ -347,7 +365,8 @@ public class FormApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -358,6 +377,9 @@ public class FormApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -411,8 +433,9 @@ public class FormApi {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] formBytes = formOutputStream.toByteArray();
|
||||
formDataPublisher = HttpRequest.BodyPublishers
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray()));
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formBytes));
|
||||
}
|
||||
localVarRequestBuilder
|
||||
.header("Content-Type", entity.getContentType().getValue())
|
||||
@@ -500,6 +523,7 @@ public class FormApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testFormOneof", localVarResponse);
|
||||
@@ -507,7 +531,8 @@ public class FormApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -518,6 +543,9 @@ public class FormApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -564,10 +592,11 @@ public class FormApi {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] formBytes = formOutputStream.toByteArray();
|
||||
localVarRequestBuilder
|
||||
.header("Content-Type", entity.getContentType().getValue())
|
||||
.method("POST", HttpRequest.BodyPublishers
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray())));
|
||||
.ofInputStream(() -> new ByteArrayInputStream(formBytes)));
|
||||
if (memberVarReadTimeout != null) {
|
||||
localVarRequestBuilder.timeout(memberVarReadTimeout);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class HeaderApi {
|
||||
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
|
||||
private final Duration memberVarReadTimeout;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
|
||||
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
|
||||
|
||||
public HeaderApi() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
@@ -98,7 +98,15 @@ public class HeaderApi {
|
||||
|
||||
|
||||
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
|
||||
String body = response.body() == null ? null : new String(response.body().readAllBytes());
|
||||
InputStream responseBody = ApiClient.getResponseBody(response);
|
||||
String body = null;
|
||||
try {
|
||||
body = responseBody == null ? null : new String(responseBody.readAllBytes());
|
||||
} finally {
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
String message = formatExceptionMessage(operationId, response.statusCode(), body);
|
||||
return new ApiException(response.statusCode(), message, response.headers(), body);
|
||||
}
|
||||
@@ -117,10 +125,13 @@ public class HeaderApi {
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response, InputStream responseBody) throws ApiException {
|
||||
if (responseBody == null) {
|
||||
throw new ApiException(new IOException("Response body is empty"));
|
||||
}
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -226,6 +237,7 @@ public class HeaderApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testHeaderIntegerBooleanStringEnums", localVarResponse);
|
||||
@@ -233,7 +245,8 @@ public class HeaderApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -244,6 +257,9 @@ public class HeaderApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class PathApi {
|
||||
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
|
||||
private final Duration memberVarReadTimeout;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
|
||||
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
|
||||
|
||||
public PathApi() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
@@ -98,7 +98,15 @@ public class PathApi {
|
||||
|
||||
|
||||
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
|
||||
String body = response.body() == null ? null : new String(response.body().readAllBytes());
|
||||
InputStream responseBody = ApiClient.getResponseBody(response);
|
||||
String body = null;
|
||||
try {
|
||||
body = responseBody == null ? null : new String(responseBody.readAllBytes());
|
||||
} finally {
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
String message = formatExceptionMessage(operationId, response.statusCode(), body);
|
||||
return new ApiException(response.statusCode(), message, response.headers(), body);
|
||||
}
|
||||
@@ -117,10 +125,13 @@ public class PathApi {
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response, InputStream responseBody) throws ApiException {
|
||||
if (responseBody == null) {
|
||||
throw new ApiException(new IOException("Response body is empty"));
|
||||
}
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -222,6 +233,7 @@ public class PathApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath", localVarResponse);
|
||||
@@ -229,7 +241,8 @@ public class PathApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -240,6 +253,9 @@ public class PathApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class QueryApi {
|
||||
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
|
||||
private final Duration memberVarReadTimeout;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
|
||||
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
|
||||
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
|
||||
|
||||
public QueryApi() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
@@ -104,7 +104,15 @@ public class QueryApi {
|
||||
|
||||
|
||||
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
|
||||
String body = response.body() == null ? null : new String(response.body().readAllBytes());
|
||||
InputStream responseBody = ApiClient.getResponseBody(response);
|
||||
String body = null;
|
||||
try {
|
||||
body = responseBody == null ? null : new String(responseBody.readAllBytes());
|
||||
} finally {
|
||||
if (responseBody != null) {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
String message = formatExceptionMessage(operationId, response.statusCode(), body);
|
||||
return new ApiException(response.statusCode(), message, response.headers(), body);
|
||||
}
|
||||
@@ -123,10 +131,13 @@ public class QueryApi {
|
||||
* @return File
|
||||
* @throws ApiException If fail to read file content from response and write to disk
|
||||
*/
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response) throws ApiException {
|
||||
public File downloadFileFromResponse(HttpResponse<InputStream> response, InputStream responseBody) throws ApiException {
|
||||
if (responseBody == null) {
|
||||
throw new ApiException(new IOException("Response body is empty"));
|
||||
}
|
||||
try {
|
||||
File file = prepareDownloadFile(response);
|
||||
java.nio.file.Files.copy(response.body(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
java.nio.file.Files.copy(responseBody, file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -220,6 +231,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testEnumRefString", localVarResponse);
|
||||
@@ -227,7 +239,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -238,6 +251,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -347,6 +363,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryDatetimeDateString", localVarResponse);
|
||||
@@ -354,7 +371,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -365,6 +383,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -476,6 +497,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryIntegerBooleanString", localVarResponse);
|
||||
@@ -483,7 +505,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -494,6 +517,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -597,6 +623,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleDeepObjectExplodeTrueObject", localVarResponse);
|
||||
@@ -604,7 +631,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -615,6 +643,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -719,6 +750,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleDeepObjectExplodeTrueObjectAllOf", localVarResponse);
|
||||
@@ -726,7 +758,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -737,6 +770,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -841,6 +877,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleFormExplodeFalseArrayInteger", localVarResponse);
|
||||
@@ -848,7 +885,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -859,6 +897,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -958,6 +999,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleFormExplodeFalseArrayString", localVarResponse);
|
||||
@@ -965,7 +1007,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -976,6 +1019,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1075,6 +1121,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleFormExplodeTrueArrayString", localVarResponse);
|
||||
@@ -1082,7 +1129,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1093,6 +1141,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1192,6 +1243,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleFormExplodeTrueObject", localVarResponse);
|
||||
@@ -1199,7 +1251,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1210,6 +1263,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1314,6 +1370,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleFormExplodeTrueObjectAllOf", localVarResponse);
|
||||
@@ -1321,7 +1378,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1332,6 +1390,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
@@ -1435,6 +1496,7 @@ public class QueryApi {
|
||||
if (memberVarResponseInterceptor != null) {
|
||||
memberVarResponseInterceptor.accept(localVarResponse);
|
||||
}
|
||||
InputStream localVarResponseBody = null;
|
||||
try {
|
||||
if (localVarResponse.statusCode()/ 100 != 2) {
|
||||
throw getApiException("testQueryStyleJsonSerializationObject", localVarResponse);
|
||||
@@ -1442,7 +1504,8 @@ public class QueryApi {
|
||||
// for plain text response
|
||||
if (localVarResponse.headers().map().containsKey("Content-Type") &&
|
||||
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
|
||||
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
|
||||
java.util.Scanner s = new java.util.Scanner(localVarResponseBody == null ? InputStream.nullInputStream() : localVarResponseBody).useDelimiter("\\A");
|
||||
String responseBodyText = s.hasNext() ? s.next() : "";
|
||||
return new ApiResponse<String>(
|
||||
localVarResponse.statusCode(),
|
||||
@@ -1453,6 +1516,9 @@ public class QueryApi {
|
||||
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
|
||||
}
|
||||
} finally {
|
||||
if (localVarResponseBody != null) {
|
||||
localVarResponseBody.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
|
||||
Reference in New Issue
Block a user