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
}
}
}
Aggregations