| 56 | | if (exception != null) { |
|---|
| 57 | | if (exception instanceof APIAuthenticationException) { |
|---|
| 58 | | // If they are not authorized to use a function |
|---|
| 59 | | session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, exception.getMessage()); |
|---|
| 60 | | session.setAttribute(WebConstants.OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR, request.getAttribute("javax.servlet.error.request_uri")); |
|---|
| 61 | | response.sendRedirect(request.getContextPath() + "/login.htm"); |
|---|
| 62 | | } |
|---|
| 63 | | else { |
|---|
| 64 | | java.lang.StackTraceElement[] elements; |
|---|
| 65 | | |
|---|
| 66 | | if (exception instanceof ServletException) { |
|---|
| 67 | | // It's a ServletException: we should extract the root cause |
|---|
| 68 | | ServletException sEx = (ServletException) exception; |
|---|
| 69 | | Throwable rootCause = sEx.getRootCause(); |
|---|
| 70 | | if (rootCause == null) |
|---|
| 71 | | rootCause = sEx; |
|---|
| 72 | | out.println("<br/><br/>** Root cause is: "+ rootCause.getMessage()); |
|---|
| 73 | | elements = rootCause.getStackTrace(); |
|---|
| | 57 | // check to see if the current user is authenticated |
|---|
| | 58 | // this logic copied from the OpenmrsFilter because this |
|---|
| | 59 | // page isn't passed through that filter like all other pages |
|---|
| | 60 | UserContext userContext = (UserContext) session.getAttribute(WebConstants.OPENMRS_USER_CONTEXT_HTTPSESSION_ATTR); |
|---|
| | 61 | if (userContext == null || userContext.getAuthenticatedUser() == null) { |
|---|
| | 62 | out.println("You must be logged in to view the stack trace"); |
|---|
| | 63 | } |
|---|
| | 64 | else { |
|---|
| | 65 | if (exception != null) { |
|---|
| | 66 | if (exception instanceof APIAuthenticationException) { |
|---|
| | 67 | // If they are not authorized to use a function |
|---|
| | 68 | session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, exception.getMessage()); |
|---|
| | 69 | session.setAttribute(WebConstants.OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR, request.getAttribute("javax.servlet.error.request_uri")); |
|---|
| | 70 | response.sendRedirect(request.getContextPath() + "/login.htm"); |
|---|
| 76 | | // It's not a ServletException, so we'll just show it |
|---|
| 77 | | elements = exception.getStackTrace(); |
|---|
| | 73 | java.lang.StackTraceElement[] elements; |
|---|
| | 74 | |
|---|
| | 75 | if (exception instanceof ServletException) { |
|---|
| | 76 | // It's a ServletException: we should extract the root cause |
|---|
| | 77 | ServletException sEx = (ServletException) exception; |
|---|
| | 78 | Throwable rootCause = sEx.getRootCause(); |
|---|
| | 79 | if (rootCause == null) |
|---|
| | 80 | rootCause = sEx; |
|---|
| | 81 | out.println("<br/><br/>** Root cause is: "+ rootCause.getMessage()); |
|---|
| | 82 | elements = rootCause.getStackTrace(); |
|---|
| | 83 | } |
|---|
| | 84 | else { |
|---|
| | 85 | // It's not a ServletException, so we'll just show it |
|---|
| | 86 | elements = exception.getStackTrace(); |
|---|
| | 87 | } |
|---|
| | 88 | for (StackTraceElement element : elements) { |
|---|
| | 89 | if (element.getClassName().contains("openmrs")) |
|---|
| | 90 | out.println("<b>" + element + "</b><br/>"); |
|---|
| | 91 | else |
|---|
| | 92 | out.println(element + "<br/>"); |
|---|
| | 93 | } |
|---|