Skip to content

Commit

Permalink
improvements of error pages
Browse files Browse the repository at this point in the history
Issue #493
  • Loading branch information
rsoika committed Apr 5, 2022
1 parent 7966228 commit 91d864f
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 72 deletions.
6 changes: 2 additions & 4 deletions imixs-office-workflow-app/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@
<!-- Error handling -->
<error-page>
<exception-type>javax.enterprise.context.NonexistentConversationException</exception-type>
<location>/error_conversationexpired.xhtml?nocid=true</location>
<location>/errorhandler.jsf?nocid=true</location>
</error-page>


<error-page>
<exception-type>javax.faces.view.facelets.TagAttributeException</exception-type>
<location>/errorhandler.jsf</location>
Expand All @@ -80,7 +78,7 @@

<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/error.jsf</location>
<location>/errorhandler.jsf</location>
</error-page>
<error-page>
<error-code>401</error-code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,34 @@
when a session expired
-->
<ui:define name="content">
<h:form id="logoutform">
<div class="imixs-form">
<div class="imixs-header">
<h2><span class="typcn typcn-messages"></span> #{message['login.optimisticlock_exception_title']}</h2>
</div>
<div class="imixs-body">
<div class="imixs-form-panel">
<p>#{message['login.optimisticlock_exception_help']}</p>
<br /> <br />
<h:commandButton value="#{message['continue']}"
action="/index.xhtml" />
</div>
</div>


<h:panelGroup styleClass="ui-widget">
<div class="ui-state-error ui-corner-all"
style="padding: .7em; margin-bottom: .7em;">
<h3>
<span class="typcn typcn-messages"> </span>
#{message['login.optimisticlock_exception_title']}
</h3>
<p>#{message['login.optimisticlock_exception_help']}</p>
<strong><h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="#{message.dateTimePatternLong}"
type="date" />
</h:outputText> </strong> <br />

</div>
</h:form>
<h:form>
<h:commandButton action="home" value="#{message.close}"
immediate="true" />
</h:form>

</h:panelGroup>







</ui:define>
</ui:composition>
128 changes: 76 additions & 52 deletions imixs-office-workflow-app/src/main/webapp/errorhandler.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,91 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/layout/template.xhtml">


<h:head>

<c:choose>
<!-- Handle WELD-000321: No conversation found to restore for .... -->
<c:when
test="#{(!empty requestScope['javax.servlet.error.exception'].cause) and (!empty requestScope['javax.servlet.error.exception'].cause.cause) and (requestScope['javax.servlet.error.exception'].cause.cause.class.name eq 'javax.enterprise.context.NonexistentConversationException')}">
<meta http-equiv="refresh"
content="0; URL=#{facesContext.externalContext.requestContextPath}/error_conversationexpired.xhtml?nocid=true" />
</c:when>

<!-- Handle javax.persistence.OptimisticLockException .... -->
<c:when
test="#{requestScope['javax.servlet.error.exception'].toString().contains('OptimisticLockException')}">
<meta http-equiv="refresh"
content="0; URL=#{facesContext.externalContext.requestContextPath}/error_optimisticlock.xhtml?nocid=true" />
</c:when>
<!-- handle rollback exceptions -->
<c:when
test="#{!requestScope['javax.servlet.error.exception'].toString().contains('javax.ejb.EJBTransactionRolledbackException')}">
<meta http-equiv="refresh"
content="10; URL=#{facesContext.externalContext.requestContextPath}/error.jsf" />
</c:when>
</c:choose>
</h:head>



<!--
Display the cause of a rollback excepiton
Display a error message depending on the cause of a exception
-->

<ui:define name="content">
<ui:define name="content">
<!-- Display only if error messages available -->
<h:panelGroup styleClass="ui-widget">
<div class="ui-state-error ui-corner-all"
<h:panelGroup styleClass="" layout="block">
<div class="ui-state-error ui-corner-all imixs-header"
style="padding: .7em; margin-bottom: .7em;">
<h3>
<span class="typcn typcn-weather-stormy"></span>
#{message.error_message_rollback_title}
</h3>
<p>#{message.error_message_rollback}</p>
<strong><h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="#{message.dateTimePatternLong}"
type="date" />
</h:outputText> :</strong> <br />
<!-- display exception details -->
<h:panelGroup layout="block"
style="background: #EEE; padding: 10px; margin: 5px 0 20px 0;border: 1px solid #999;"
rendered="#{! empty requestScope['javax.servlet.error.exception']}">
<h:outputText
value="#{requestScope['javax.servlet.error.exception']}" />
</h:panelGroup>

<!-- Show different Error Message types -->

<c:choose>
<!-- Handle WELD-000321: No conversation found to restore for .... -->
<c:when
test="#{errorController.isCausedBy(requestScope['javax.servlet.error.exception'],'ConversationException')}">

<h3>
<span class="typcn typcn-stopwatch"></span>
#{message['login.conversation_expired_title']}
</h3>
<p>#{message['login.optimisticlock_exception_help']}</p>
<h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="#{message.dateTimePatternLong}"
type="date" />
</h:outputText>
</c:when>

<!-- Handle javax.persistence.OptimisticLockException .... -->
<c:when
test="#{errorController.isCausedBy(requestScope['javax.servlet.error.exception'],'OptimisticLockException')}">

<h3>
<span class="typcn typcn-messages"> </span>
#{message['login.optimisticlock_exception_title']}
</h3>
<p>#{message['login.optimisticlock_exception_help']}</p>
<h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="#{message.dateTimePatternLong}"
type="date" />
</h:outputText>
</c:when>

<!-- handle rollback exceptions -->
<c:when
test="#{errorController.isCausedBy(requestScope['javax.servlet.error.exception'],'RolledbackException')}">

<h3>
<span class="typcn typcn-weather-stormy"></span>
#{message.error_message_rollback_title}
</h3>
<p>#{message['login.error_message_rollback']}</p>
<h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="#{message.dateTimePatternLong}"
type="date" />
</h:outputText>

</c:when>

<!-- Display Stacktrace Inforamtion as we encountered a undefiend error -->
<c:otherwise>
<h3>
<span class="typcn typcn-weather-stormy"></span>
#{message.error_message_rollback_title}
</h3>
<p>#{message.error_message_rollback}</p>
<strong><h:outputText value="#{session.lastAccessedTime}">
<f:convertDateTime pattern="#{message.dateTimePatternLong}"
type="date" />
</h:outputText> :</strong>
<br />
<!-- display exception details -->
<h:panelGroup layout="block"
style="background: #EEE; padding: 10px; margin: 5px 0 20px 0;border: 1px solid #999;"
rendered="#{! empty requestScope['javax.servlet.error.exception']}">
<h:outputText
value="#{requestScope['javax.servlet.error.exception']}" />
</h:panelGroup>
</c:otherwise>
</c:choose>
</div>
<h:form>
<h:commandButton action="home" value="#{message.close}"
immediate="true" />
</h:form>

</h:panelGroup>
</ui:define>

</ui:composition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Imixs Workflow
* Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,
* http://www.imixs.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You can receive a copy of the GNU General Public
* License at http://www.gnu.org/licenses/gpl.html
*
* Project:
* http://www.imixs.org
* http://java.net/projects/imixs-workflow
*
* Contributors:
* Imixs Software Solutions GmbH - initial API and implementation
* Ralph Soika - Software Developer
*******************************************************************************/

package org.imixs.workflow.office.util;

import java.io.Serializable;
import java.util.logging.Logger;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

/**
* The ErrorController provides methods to analyse a exception stack trace.
* The controller is used in the errorhandler.xhtml page to redirect the user to a corresponding error page.
*
* @author rsoika
*/
@Named
@RequestScoped
public class ErrorController implements Serializable {

private static final long serialVersionUID = 1L;

private static Logger logger = Logger.getLogger(ErrorController.class.getName());

public ErrorController() {
super();
}

/**
* Returns true if the exception is caused by a OptimisticLockException
* @param e
* @return
*/
public boolean isCausedBy(Exception e, String excpetionType) {
logger.info("test is caused by: " + e);
if (e==null) {
return false;
}
// iterate over the full exception stack trace
Throwable cause = e.getCause();
while (cause!=null) {
if (cause.toString().contains(excpetionType)) {
logger.warning("...exception caused by " + excpetionType );
return true;
}
// take next cause from stack
cause=cause.getCause();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ public static void handleModelException(ModelException me) {
}
}


}

0 comments on commit 91d864f

Please sign in to comment.