use of org.entando.entando.aps.system.services.api.model.ApiMethodResult in project entando-core by entando.
the class ResponseBuilder method createResponse.
@Override
public Object createResponse(ApiMethod method, Object bodyObject, Properties parameters) throws ApsSystemException {
AbstractApiResponse response = null;
try {
this.checkParameter(method, parameters);
Object bean = this.extractBean(method);
Object masterResult = null;
if (method.getHttpMethod().equals(ApiMethod.HttpMethod.GET)) {
masterResult = this.invokeGetMethod(method, bean, null, parameters, true);
if (null == masterResult) {
ApiError error = new ApiError(IApiErrorCodes.API_INVALID_RESPONSE, "Invalid or null Response", Response.Status.SERVICE_UNAVAILABLE);
throw new ApiException(error);
}
} else {
masterResult = this.invokePutPostDeleteMethod(method, bean, parameters, bodyObject);
}
if (null == method.getResponseClassName()) {
return masterResult;
}
response = this.buildApiResponseObject(method);
if (null == response && (masterResult instanceof String)) {
return masterResult;
}
String htmlResult = this.extractHtmlResult(masterResult, response, method, parameters, bean);
if (masterResult instanceof ApiMethodResult) {
response.addErrors(((ApiMethodResult) masterResult).getErrors());
response.setResult(((ApiMethodResult) masterResult).getResult(), htmlResult);
} else {
response.setResult(masterResult, htmlResult);
}
} catch (ApiException e) {
if (response == null) {
response = new StringApiResponse();
}
response.addErrors(e.getErrors());
response.setResult(FAILURE, null);
} catch (Throwable t) {
_logger.error("Error creating response - {}", this.buildApiSignature(method), t);
String message = "Error creating response - " + this.buildApiSignature(method);
if (response == null) {
response = new StringApiResponse();
}
ApiError error = new ApiError(IApiErrorCodes.API_METHOD_ERROR, message, Response.Status.INTERNAL_SERVER_ERROR);
response.addError(error);
response.setResult(FAILURE, null);
}
return response;
}
Aggregations