Search in sources :

Example 1 with CmisStorageException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException in project copper-cms by PogeyanOSS.

the class ServletHelpers method printError.

static void printError(Exception ex, HttpServletRequest request, HttpServletResponse response) {
    int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    String exceptionName = CmisRuntimeException.EXCEPTION_NAME;
    if (ex instanceof CmisRuntimeException) {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
        statusCode = getErrorCode((CmisRuntimeException) ex);
    } else if (ex instanceof CmisStorageException) {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
        statusCode = getErrorCode((CmisStorageException) ex);
        exceptionName = ((CmisStorageException) ex).getExceptionName();
    } else if (ex instanceof CmisBaseException) {
        statusCode = getErrorCode((CmisBaseException) ex);
        exceptionName = ((CmisBaseException) ex).getExceptionName();
        if (statusCode == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
            AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
        }
    } else if (ex instanceof IOException) {
        AkkaCmisBrowserBindingServlet.LOG.warn(createLogMessage(ex, request), ex);
    } else {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), ex);
    }
    if (response.isCommitted()) {
        AkkaCmisBrowserBindingServlet.LOG.warn("Failed to send error message to client. Response is already committed.", ex);
        return;
    }
    String message = ex.getMessage();
    /*
		 * if (!(ex instanceof CmisBaseException)) { message =
		 * "An error occurred!"; }
		 */
    response.resetBuffer();
    response.setStatus(statusCode);
    JSONObject jsonResponse = new JSONObject();
    jsonResponse.put(BrowserConstants.ERROR_EXCEPTION, exceptionName);
    jsonResponse.put(BrowserConstants.MESSAGE, message);
    String st = ExceptionHelper.getStacktraceAsString(ex);
    if (st != null) {
        jsonResponse.put(BrowserConstants.ERROR_STACKTRACE, st);
    }
    if (ex instanceof CmisBaseException) {
        Map<String, String> additionalData = ((CmisBaseException) ex).getAdditionalData();
        if (additionalData != null && !additionalData.isEmpty()) {
            for (Map.Entry<String, String> e : additionalData.entrySet()) {
                if (BrowserConstants.ERROR_EXCEPTION.equalsIgnoreCase(e.getKey()) || BrowserConstants.MESSAGE.equalsIgnoreCase(e.getKey())) {
                    continue;
                }
                jsonResponse.put(e.getKey(), e.getValue());
            }
        }
    }
    try {
        ServletHelpers.writeJSON(jsonResponse, request, response);
    } catch (Exception e) {
        AkkaCmisBrowserBindingServlet.LOG.error(createLogMessage(ex, request), e);
        try {
            response.sendError(statusCode, message);
        } catch (Exception en) {
        // there is nothing else we can do
        }
    }
}
Also used : CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) IOException(java.io.IOException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) HashMap(java.util.HashMap) Map(java.util.Map) CmisStreamNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisServiceUnavailableException(org.apache.chemistry.opencmis.commons.exceptions.CmisServiceUnavailableException) CmisNameConstraintViolationException(org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException) CmisFilterNotValidException(org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException) CmisTooManyRequestsException(org.apache.chemistry.opencmis.commons.exceptions.CmisTooManyRequestsException) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisStorageException(org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisVersioningException(org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)1 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)1 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)1 CmisFilterNotValidException (org.apache.chemistry.opencmis.commons.exceptions.CmisFilterNotValidException)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisNameConstraintViolationException (org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException)1 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1 CmisServiceUnavailableException (org.apache.chemistry.opencmis.commons.exceptions.CmisServiceUnavailableException)1 CmisStorageException (org.apache.chemistry.opencmis.commons.exceptions.CmisStorageException)1 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)1 CmisTooManyRequestsException (org.apache.chemistry.opencmis.commons.exceptions.CmisTooManyRequestsException)1 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)1 CmisVersioningException (org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException)1 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)1