[java-opensaml COMMIT] /trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java

noreply at shibboleth.net noreply at shibboleth.net
Fri Apr 19 10:22:30 EDT 2013


Author: scantor
Date: Fri Apr 19 10:22:30 2013
New Revision: 3305

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3305&view=rev
Log:
Extend exception handling to avoid suppressing checked errors.

Modified:
    trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java

Modified: trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java?rev=3305&r1=3304&r2=3305&view=diff
==============================================================================
--- trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java (original)
+++ trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java Fri Apr 19 10:22:30 2013
@@ -19,6 +19,7 @@
 
 import javax.annotation.Nonnull;
 
+import org.apache.log4j.Logger;
 import org.opensaml.profile.ProfileException;
 import org.opensaml.profile.context.ProfileRequestContext;
 
@@ -65,12 +66,32 @@
             @Nonnull final ProfileRequestContext<InboundMessageType, OutboundMessageType> profileRequestContext)
             throws ProfileException {
         
+        // The try/catch logic is designed to favor a checked ProfileException raised by
+        // the doExecute step over any unchecked errors. It also favors an unchecked error
+        // from doExecute over one raised by doPostExecute.
+        
         if (doPreExecute(profileRequestContext)) {
             try {
                 doExecute(profileRequestContext);
-            } finally {
-                doPostExecute(profileRequestContext);
+            } catch (ProfileException e) {
+                try {
+                    doPostExecute(profileRequestContext, e);
+                } catch (RuntimeException re) {
+                    Logger.getInstance(AbstractProfileAction.class).warn(
+                            "Runtime exception thrown by doPostExecute of " + getId(), re);
+                }
+                throw e;
+            } catch (RuntimeException e) {
+                try {
+                    doPostExecute(profileRequestContext, e);
+                } catch (RuntimeException re) {
+                    Logger.getInstance(AbstractProfileAction.class).warn(
+                            "Runtime exception thrown by doPostExecute of " + getId(), re);
+                }
+                throw e;
             }
+
+            doPostExecute(profileRequestContext);
         }
     }
     
@@ -122,4 +143,27 @@
     protected void doPostExecute(
             @Nonnull final ProfileRequestContext<InboundMessageType, OutboundMessageType> profileRequestContext) {
     }    
+
+    /**
+     * Called after execution, actions may override this method to perform post-processing for a
+     * request.
+     * 
+     * <p>Actions must not "fail" during this step and will not have the opportunity to signal
+     * events at this stage. This method will not be called if {@link #doPreExecute} fails, but
+     * is called if an exception is raised by {@link #doExecute}.</p>
+     * 
+     * <p>This version of the method will be called if an exception is raised during execution of
+     * the action. The overall action result will be to raise this error, so any errors inadvertently
+     * raised by this method will be logged and superseded.</p>
+     * 
+     * <p>The default implementation simply calls the error-less version of this method.</p>
+     * 
+     * @param profileRequestContext the current IdP profile request context
+     * @param e an exception raised by the {@link #doExecute} method
+     */
+    protected void doPostExecute(
+            @Nonnull final ProfileRequestContext<InboundMessageType, OutboundMessageType> profileRequestContext,
+            @Nonnull final Exception e) {
+        doPostExecute(profileRequestContext);
+    }    
 }



More information about the commits mailing list