deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-576 handling of exceptions in @PreRenderView callbacks
Date Fri, 18 Apr 2014 12:10:39 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 5060e439d -> cd518d880


DELTASPIKE-576 handling of exceptions in @PreRenderView callbacks


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/cd518d88
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/cd518d88
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/cd518d88

Branch: refs/heads/master
Commit: cd518d880ee3a6ded06f766d3a19e2fb101e731f
Parents: 5060e43
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Apr 18 14:00:20 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Apr 18 14:07:20 2014 +0200

----------------------------------------------------------------------
 .../control/BridgeExceptionHandlerWrapper.java  | 42 ++++++++++++++++++--
 .../request/DeltaSpikeFacesContextWrapper.java  | 10 ++++-
 2 files changed, 47 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/cd518d88/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/exception/control/BridgeExceptionHandlerWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/exception/control/BridgeExceptionHandlerWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/exception/control/BridgeExceptionHandlerWrapper.java
index 7cc4bb0..59b5ceb 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/exception/control/BridgeExceptionHandlerWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/exception/control/BridgeExceptionHandlerWrapper.java
@@ -19,6 +19,7 @@
 package org.apache.deltaspike.jsf.impl.exception.control;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Iterator;
 import javax.el.ELException;
 import javax.enterprise.inject.spi.BeanManager;
@@ -26,7 +27,11 @@ import javax.faces.FacesException;
 import javax.faces.context.ExceptionHandler;
 import javax.faces.context.ExceptionHandlerWrapper;
 import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
 import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.SystemEvent;
+
 import org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent;
 import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
@@ -34,11 +39,15 @@ import org.apache.deltaspike.core.spi.activation.Deactivatable;
 public class BridgeExceptionHandlerWrapper extends ExceptionHandlerWrapper implements Deactivatable
 {
     private final ExceptionHandler wrapped;
+    private final BeanManager beanManager;
     private final Annotation exceptionQualifier;
 
-    public BridgeExceptionHandlerWrapper(ExceptionHandler wrapped, Annotation exceptionQualifier)
+    public BridgeExceptionHandlerWrapper(ExceptionHandler wrapped,
+                                         BeanManager beanManager,
+                                         Annotation exceptionQualifier)
     {
         this.wrapped = wrapped;
+        this.beanManager = beanManager;
         this.exceptionQualifier = exceptionQualifier;
     }
 
@@ -93,12 +102,39 @@ public class BridgeExceptionHandlerWrapper extends ExceptionHandlerWrapper
imple
     @Override
     public Throwable getRootCause(Throwable throwable)
     {
-        while ((ELException.class.isInstance(throwable) || FacesException.class.isInstance(throwable))
-                && throwable.getCause() != null)
+        while ((ELException.class.isInstance(throwable) || FacesException.class.isInstance(throwable)
||
+            InvocationTargetException.class.isInstance(throwable)) && throwable.getCause()
!= null)
         {
             throwable = throwable.getCause();
         }
 
         return throwable;
     }
+
+    @Override
+    public void processEvent(SystemEvent event) throws AbortProcessingException
+    {
+        //handle exceptions which occur in a phase-listener (beforePhase) for PhaseId.RENDER_RESPONSE
+        //needed because #handle gets called too late in this case
+        if (event instanceof ExceptionQueuedEvent)
+        {
+            ExceptionQueuedEvent exceptionQueuedEvent = (ExceptionQueuedEvent)event;
+            FacesContext facesContext = exceptionQueuedEvent.getContext().getContext();
+
+            if (facesContext.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE &&
+                exceptionQueuedEvent.getContext().inBeforePhase())
+            {
+                Throwable exception = getRootCause(exceptionQueuedEvent.getContext().getException());
+
+                ExceptionToCatchEvent exceptionToCatchEvent = new ExceptionToCatchEvent(exception);
+                this.beanManager.fireEvent(exceptionToCatchEvent);
+
+                if (exceptionToCatchEvent.isHandled())
+                {
+                    return;
+                }
+            }
+        }
+        super.processEvent(event);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/cd518d88/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
index 83be4be..c7bd560 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
@@ -20,6 +20,7 @@ package org.apache.deltaspike.jsf.impl.listener.request;
 
 import java.lang.annotation.Annotation;
 import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.jsf.api.config.JsfModuleConfig;
@@ -27,6 +28,7 @@ import org.apache.deltaspike.jsf.impl.config.view.DefaultErrorViewAwareException
 import org.apache.deltaspike.jsf.impl.injection.InjectionAwareApplicationWrapper;
 import org.apache.deltaspike.jsf.impl.message.FacesMessageEntry;
 
+import javax.enterprise.inject.spi.BeanManager;
 import javax.faces.application.Application;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.ExceptionHandler;
@@ -46,6 +48,8 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
 {
     private final FacesContext wrappedFacesContext;
 
+    private BeanManager beanManager;
+
     private JsfRequestBroadcaster jsfRequestBroadcaster;
 
     private boolean defaultErrorViewExceptionHandlerActivated;
@@ -102,7 +106,8 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
 
         if (this.bridgeExceptionHandlerActivated)
         {
-            exceptionHandler = new BridgeExceptionHandlerWrapper(exceptionHandler, this.bridgeExceptionQualifier);
+            exceptionHandler = new BridgeExceptionHandlerWrapper(
+                exceptionHandler, this.beanManager, this.bridgeExceptionQualifier);
         }
         
         if (this.defaultErrorViewExceptionHandlerActivated)
@@ -135,7 +140,8 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
         // switch into paranoia mode
         if (this.initialized == null)
         {
-            this.jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
+            this.beanManager = BeanManagerProvider.getInstance().getBeanManager();
+            this.jsfModuleConfig = BeanProvider.getContextualReference(this.beanManager,
JsfModuleConfig.class, false);
 
             if (ClassDeactivationUtils.isActivated(JsfRequestBroadcaster.class))
             {


Mime
View raw message