forked from loafle/openapi-generator-original
fix empty body in java apache client (#14574)
This commit is contained in:
parent
8d9816e193
commit
32499a19fc
@ -830,7 +830,15 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
String mimeType = getResponseMimeType(response);
|
String mimeType = getResponseMimeType(response);
|
||||||
if (mimeType == null || isJsonMime(mimeType)) {
|
if (mimeType == null || isJsonMime(mimeType)) {
|
||||||
// Assume json if no mime type
|
// Assume json if no mime type
|
||||||
return objectMapper.readValue(entity.getContent(), valueType);
|
// convert input stream to string
|
||||||
|
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||||
|
String content = (String) (s.hasNext() ? s.next() : "");
|
||||||
|
|
||||||
|
if ("".equals(content)) { // returns null for empty body
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectMapper.readValue(content, valueType);
|
||||||
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
||||||
// convert input stream to string
|
// convert input stream to string
|
||||||
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||||
@ -1069,7 +1077,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// for empty body
|
// for empty body
|
||||||
builder.setEntity(serialize(null, null, contentTypeObj));
|
builder.setEntity(new StringEntity("", contentTypeObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||||
|
@ -703,7 +703,15 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
String mimeType = getResponseMimeType(response);
|
String mimeType = getResponseMimeType(response);
|
||||||
if (mimeType == null || isJsonMime(mimeType)) {
|
if (mimeType == null || isJsonMime(mimeType)) {
|
||||||
// Assume json if no mime type
|
// Assume json if no mime type
|
||||||
return objectMapper.readValue(entity.getContent(), valueType);
|
// convert input stream to string
|
||||||
|
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||||
|
String content = (String) (s.hasNext() ? s.next() : "");
|
||||||
|
|
||||||
|
if ("".equals(content)) { // returns null for empty body
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectMapper.readValue(content, valueType);
|
||||||
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
||||||
// convert input stream to string
|
// convert input stream to string
|
||||||
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||||
@ -942,7 +950,7 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// for empty body
|
// for empty body
|
||||||
builder.setEntity(serialize(null, null, contentTypeObj));
|
builder.setEntity(new StringEntity("", contentTypeObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||||
|
@ -846,7 +846,15 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
String mimeType = getResponseMimeType(response);
|
String mimeType = getResponseMimeType(response);
|
||||||
if (mimeType == null || isJsonMime(mimeType)) {
|
if (mimeType == null || isJsonMime(mimeType)) {
|
||||||
// Assume json if no mime type
|
// Assume json if no mime type
|
||||||
return objectMapper.readValue(entity.getContent(), valueType);
|
// convert input stream to string
|
||||||
|
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||||
|
String content = (String) (s.hasNext() ? s.next() : "");
|
||||||
|
|
||||||
|
if ("".equals(content)) { // returns null for empty body
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectMapper.readValue(content, valueType);
|
||||||
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
||||||
// convert input stream to string
|
// convert input stream to string
|
||||||
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||||
@ -1085,7 +1093,7 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// for empty body
|
// for empty body
|
||||||
builder.setEntity(serialize(null, null, contentTypeObj));
|
builder.setEntity(new StringEntity("", contentTypeObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
try (CloseableHttpResponse response = httpClient.execute(builder.build(), context)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user