Search in sources :

Example 1 with SelfRestCallPostProcess

use of org.entando.entando.aps.system.init.model.SelfRestCallPostProcess in project entando-core by entando.

the class SelfRestCaller method executePostProcess.

@Override
public int executePostProcess(IPostProcess postProcess) throws InvalidPostProcessResultException, ApsSystemException {
    if (!(postProcess instanceof SelfRestCallPostProcess)) {
        return 0;
    }
    SelfRestCallPostProcess selfRestCall = (SelfRestCallPostProcess) postProcess;
    IResponseBuilder responseBuilder = this.getResponseBuilder();
    try {
        Object result = null;
        ApiMethod method = responseBuilder.extractApiMethod(selfRestCall.getMethod(), selfRestCall.getNamespace(), selfRestCall.getResourceName());
        Properties properties = this.extractParameters(selfRestCall);
        if (method.getHttpMethod().equals(ApiMethod.HttpMethod.GET) || method.getHttpMethod().equals(ApiMethod.HttpMethod.DELETE)) {
            result = responseBuilder.createResponse(method, properties);
        } else {
            String contentBody = this.getContentBody(selfRestCall);
            Object bodyObject = UnmarshalUtils.unmarshal(method, contentBody, selfRestCall.getContentType());
            result = responseBuilder.createResponse(method, bodyObject, properties);
        }
        Response.Status responseStatus = this.extractResponseStatusCode(result);
        if (selfRestCall.isPrintResponse()) {
            this.printResponse(selfRestCall, result, responseStatus, method, properties);
        }
    } catch (InvalidPostProcessResultException t) {
        _logger.error("error in executePostProcess", t);
        // ApsSystemUtils.logThrowable(t, this, "executePostProcess", t.getMessage());
        throw t;
    } catch (Throwable t) {
        _logger.error("Error invoking api method", t);
        // ApsSystemUtils.logThrowable(t, this, "executePostProcess", "Error invoking api method");
        throw new ApsSystemException("Error invoking api method", t);
    }
    return 1;
}
Also used : StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) Response(javax.ws.rs.core.Response) AbstractApiResponse(org.entando.entando.aps.system.services.api.model.AbstractApiResponse) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) InvalidPostProcessResultException(org.entando.entando.aps.system.init.model.InvalidPostProcessResultException) SelfRestCallPostProcess(org.entando.entando.aps.system.init.model.SelfRestCallPostProcess) Properties(java.util.Properties) IResponseBuilder(org.entando.entando.aps.system.services.api.server.IResponseBuilder)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 Properties (java.util.Properties)1 Response (javax.ws.rs.core.Response)1 InvalidPostProcessResultException (org.entando.entando.aps.system.init.model.InvalidPostProcessResultException)1 SelfRestCallPostProcess (org.entando.entando.aps.system.init.model.SelfRestCallPostProcess)1 AbstractApiResponse (org.entando.entando.aps.system.services.api.model.AbstractApiResponse)1 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)1 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)1 IResponseBuilder (org.entando.entando.aps.system.services.api.server.IResponseBuilder)1