use of org.entando.entando.aps.system.services.api.model.AbstractApiResponse in project entando-core by entando.
the class ResponseBuilder method buildApiResponseObject.
private AbstractApiResponse buildApiResponseObject(ApiMethod apiMethod) throws ApiException {
AbstractApiResponse apiResponse = null;
try {
Class responseClass = Class.forName(apiMethod.getResponseClassName());
apiResponse = (AbstractApiResponse) responseClass.newInstance();
} catch (Exception e) {
_logger.error("Error creating instance of response '{}'", apiMethod.getResponseClassName(), e);
}
return apiResponse;
}
use of org.entando.entando.aps.system.services.api.model.AbstractApiResponse 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;
}
use of org.entando.entando.aps.system.services.api.model.AbstractApiResponse in project entando-core by entando.
the class SelfRestCaller method extractResponseStatusCode.
protected Response.Status extractResponseStatusCode(Object responseObject) {
if (responseObject instanceof AbstractApiResponse) {
Response.Status status = Response.Status.OK;
AbstractApiResponse mainResponse = (AbstractApiResponse) responseObject;
if (null != mainResponse.getErrors()) {
for (int i = 0; i < mainResponse.getErrors().size(); i++) {
ApiError error = mainResponse.getErrors().get(i);
Response.Status errorStatus = error.getStatus();
if (null != errorStatus && status.getStatusCode() < errorStatus.getStatusCode()) {
status = errorStatus;
}
}
}
return status;
} else {
return Response.Status.OK;
}
}
Aggregations