From a2aa6270ef472ce430e28bf12f6f096b225db3eb Mon Sep 17 00:00:00 2001 From: jiangyuan04 Date: Wed, 3 Aug 2022 22:23:05 +0800 Subject: [PATCH] modify getContentType method --- .../libraries/apache-httpclient/ApiClient.mustache | 10 +++++++--- .../main/java/org/openapitools/client/ApiClient.java | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) 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 ac8bc8937dff..7e4d2181f5a0 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 @@ -708,14 +708,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { /** * Parse content type object from header value */ - private ContentType getContentType(String headerValue) { - return ContentType.getByMimeType(headerValue); + private ContentType getContentType(String headerValue) throws ApiException { + try { + return ContentType.parse(headerValue); + } catch (ParseException e) { + throw new ApiException("Could not parse content type " + headerValue); + } } /** * Get content type of a response or null if one was not provided */ - private String getResponseMimeType(HttpResponse response) { + private String getResponseMimeType(HttpResponse response) throws ApiException { Header contentTypeHeader = response.getFirstHeader("Content-Type"); if (contentTypeHeader != null) { return getContentType(contentTypeHeader.getValue()).getMimeType(); 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 ab5d8431ac43..43308167ad2c 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 @@ -663,14 +663,18 @@ protected Map> transformResponseHeaders(Header[] headers) { /** * Parse content type object from header value */ - private ContentType getContentType(String headerValue) { - return ContentType.getByMimeType(headerValue); + private ContentType getContentType(String headerValue) throws ApiException { + try { + return ContentType.parse(headerValue); + } catch (ParseException e) { + throw new ApiException("Could not parse content type " + headerValue); + } } /** * Get content type of a response or null if one was not provided */ - private String getResponseMimeType(HttpResponse response) { + private String getResponseMimeType(HttpResponse response) throws ApiException { Header contentTypeHeader = response.getFirstHeader("Content-Type"); if (contentTypeHeader != null) { return getContentType(contentTypeHeader.getValue()).getMimeType();