Search in sources :

Example 16 with Logger

use of jp.ossc.nimbus.service.log.Logger in project nimbus by nimbus-org.

the class DefaultExceptionHandlerService method handleException.

public void handleException(Throwable th, ServletRequest request, ServletResponse response) throws Throwable {
    if (logMessageCode != null) {
        final Logger log = super.getLogger();
        if (isOutputStackTraceLog) {
            log.write(logMessageCode, logMessageArguments, th);
        } else {
            log.write(logMessageCode, logMessageArguments);
        }
    }
    if (journal != null) {
        journal.addInfo(exceptionJournalKey, th, exceptionEditorFinder);
    }
    if (httpResponseStatus != -1 && response instanceof HttpServletResponse) {
        if (httpResponseStatusMessage == null) {
            ((HttpServletResponse) response).setStatus(httpResponseStatus);
        } else {
            ((HttpServletResponse) response).sendError(httpResponseStatus, httpResponseStatusMessage);
        }
    }
    if (responseObject != null || responseObjectServiceName != null) {
        Object resObj = responseObject;
        if (responseObjectServiceName != null) {
            resObj = ServiceManagerFactory.getServiceObject(responseObjectServiceName);
        }
        if (exceptionAndResponseObjectPropertyMapping != null) {
            Iterator entries = exceptionAndResponseObjectPropertyMapping.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry entry = (Map.Entry) entries.next();
                try {
                    Object val = propertyAccess.get(th, (String) entry.getKey());
                    if (val != null) {
                        propertyAccess.set(resObj, (String) entry.getValue(), val);
                    }
                } catch (IllegalArgumentException e) {
                } catch (NoSuchPropertyException e) {
                } catch (InvocationTargetException e) {
                }
            }
        }
        request.setAttribute(responseObjectAttributeName, resObj);
    }
    if (isThrowException) {
        throw th;
    } else if (forwardPath != null) {
        final RequestDispatcher rd = request.getRequestDispatcher(forwardPath);
        if (rd != null) {
            request.setAttribute(REQUEST_ATTIBUTE_EXCEPTION_KEY, th);
            rd.forward(request, response);
        }
    } else if (redirectPath != null && response instanceof HttpServletResponse) {
        ((HttpServletResponse) response).sendRedirect(((HttpServletResponse) response).encodeRedirectURL(redirectPath));
    }
}
Also used : Iterator(java.util.Iterator) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Logger(jp.ossc.nimbus.service.log.Logger) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

Logger (jp.ossc.nimbus.service.log.Logger)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)1