in sdk/core/azure-core-rest/src/main/java/com/azure/android/core/rest/HttpResponseMapper.java [544:609]
private Response<?> instantiateResponse(Constructor<? extends Response<?>> responseCtr,
int responseCtrParamCount,
HttpRequest httpRequest,
HttpResponse httpResponse,
Object headerAsObject,
Object bodyAsObject) {
final int responseStatusCode = httpResponse.getStatusCode();
final HttpHeaders responseHeaders = httpResponse.getHeaders();
switch (responseCtrParamCount) {
case 3:
try {
return responseCtr.newInstance(httpRequest,
responseStatusCode,
responseHeaders);
} catch (IllegalAccessException e) {
throw logger.logExceptionAsError(
new RuntimeException("Failed to deserialize 3-parameter response. ", e));
} catch (InvocationTargetException e) {
throw logger.logExceptionAsError(
new RuntimeException("Failed to deserialize 3-parameter response. ", e));
} catch (InstantiationException e) {
throw logger.logExceptionAsError(
new RuntimeException("Failed to deserialize 3-parameter response. ", e));
}
case 4:
try {
return responseCtr.newInstance(httpRequest,
responseStatusCode,
responseHeaders,
bodyAsObject);
} catch (IllegalAccessException e) {
throw logger.logExceptionAsError(
new RuntimeException("Failed to deserialize 4-parameter response. ", e));
} catch (InvocationTargetException e) {
throw logger.logExceptionAsError(
new RuntimeException("Failed to deserialize 4-parameter response. ", e));
} catch (InstantiationException e) {
throw logger.logExceptionAsError(
new RuntimeException("Failed to deserialize 4-parameter response. ", e));
}
case 5:
try {
return responseCtr.newInstance(httpRequest,
responseStatusCode,
responseHeaders,
bodyAsObject,
headerAsObject);
} catch (IllegalAccessException e) {
String message = String.format("Failed to deserialize 5-parameter response %s decoded headers. ",
headerAsObject != null ? "with" : "without");
throw logger.logExceptionAsError(new RuntimeException(message, e));
} catch (InvocationTargetException e) {
String message = String.format("Failed to deserialize 5-parameter response %s decoded headers. ",
headerAsObject != null ? "with" : "without");
throw logger.logExceptionAsError(new RuntimeException(message, e));
} catch (InstantiationException e) {
String message = String.format("Failed to deserialize 5-parameter response %s decoded headers. ",
headerAsObject != null ? "with" : "without");
throw logger.logExceptionAsError(new RuntimeException(message, e));
}
default:
throw logger.logExceptionAsError(
new IllegalStateException("Response constructor with expected parameters not found."));
}
}