Fix for issue #5777 - java/jersey2 ApiClient.invokeAPI doesn´t close the Response object (#5782)

* Update ApiClient.mustache

Fix for issue #5777

* Update ApiClient.mustache

* Create ApiClient.mustache

* Run java-petstore-jersey2.sh
This commit is contained in:
Moscagus 2017-06-14 13:45:14 -03:00 committed by wing328
parent 77c14bca39
commit f2276e5b35
2 changed files with 96 additions and 80 deletions

View File

@ -682,48 +682,56 @@ public class ApiClient {
Entity<?> entity = serialize(body, formParams, contentType);
Response response;
Response response = null;
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
try {
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
} finally {
try {
response.close();
} catch (Exception e) {
// it's not critical, since the response object is local in method invokeAPI; that's fine, just continue
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
}

View File

@ -671,48 +671,56 @@ public class ApiClient {
Entity<?> entity = serialize(body, formParams, contentType);
Response response;
Response response = null;
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
try {
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
} finally {
try {
response.close();
} catch (Exception e) {
// it's not critical, since the response object is local in method invokeAPI; that's fine, just continue
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
}