[java-opensaml COMMIT] in /trunk: opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessage...

noreply at shibboleth.net noreply at shibboleth.net
Thu Apr 25 16:47:48 EDT 2013


Author: scantor
Date: Thu Apr 25 16:47:48 2013
New Revision: 3318

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3318&view=rev
Log:
Rework exception handling for abstract handler/action classes

Added:
    trunk/opensaml-messaging-api/src/test/java/org/opensaml/messaging/handler/
    trunk/opensaml-messaging-api/src/test/java/org/opensaml/messaging/handler/AbstractMessageHandlerTest.java   (with props)
    trunk/opensaml-messaging-api/src/test/resources/logback-test.xml   (with props)
Modified:
    trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java
    trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java
    trunk/opensaml-profile-api/src/test/java/org/opensaml/profile/action/AbstractProfileActionTest.java

Modified: trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java?rev=3318&r1=3317&r2=3318&view=diff
==============================================================================
--- trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java (original)
+++ trunk/opensaml-messaging-api/src/main/java/org/opensaml/messaging/handler/AbstractMessageHandler.java Thu Apr 25 16:47:48 2013
@@ -56,9 +56,10 @@
     public void invoke(@Nonnull final MessageContext<MessageType> messageContext) throws MessageHandlerException {
         Constraint.isNotNull(messageContext, "Message context cannot be null");
         
-        // 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.
+        // The try/catch logic is designed to suppress a checked exception raised by
+        // the doInvoke step by any unchecked errors in the doPostInvoke method.
+        // The original exception is logged, and can be accessed from the suppressing
+        // error object using the Java 7 API.
         
         if (doPreInvoke(messageContext)) {
             try {
@@ -66,19 +67,25 @@
             } catch (MessageHandlerException e) {
                 try {
                     doPostInvoke(messageContext, e);
-                } catch (RuntimeException re) {
-                    Logger.getInstance(AbstractMessageHandler.class).warn(
-                            "Runtime exception thrown by doPostInvoke of " + getId(), re);
+                } catch (Throwable t) {
+                    Logger.getInstance(AbstractMessageHandler.class).warn(getLogPrefix()
+                            + " Unchecked exception/error thrown by doPostInvoke, "
+                            + "superseding a MessageHandlerException ", e);
+                    t.addSuppressed(e);
+                    throw t;
                 }
                 throw e;
-            } catch (RuntimeException e) {
+            } catch (Throwable t) {
                 try {
-                    doPostInvoke(messageContext, e);
-                } catch (RuntimeException re) {
-                    Logger.getInstance(AbstractMessageHandler.class).warn(
-                            "Runtime exception thrown by doPostInvoke of " + getId(), re);
+                    doPostInvoke(messageContext);
+                } catch (Throwable t2) {
+                    Logger.getInstance(AbstractMessageHandler.class).warn(getLogPrefix()
+                            + " Unchecked exception/error thrown by doPostInvoke, "
+                            + "superseding an unchecked exception/error ", t);
+                    t2.addSuppressed(t);
+                    throw t2;
                 }
-                throw e;
+                throw t;
             }
 
             doPostInvoke(messageContext);

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=3318&r1=3317&r2=3318&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 Thu Apr 25 16:47:48 2013
@@ -20,6 +20,7 @@
 import javax.annotation.Nonnull;
 
 import org.apache.log4j.Logger;
+import org.opensaml.messaging.handler.AbstractMessageHandler;
 import org.opensaml.profile.ProfileException;
 import org.opensaml.profile.context.ProfileRequestContext;
 
@@ -59,9 +60,10 @@
             @Nonnull final ProfileRequestContext<InboundMessageType, OutboundMessageType> profileRequestContext)
             throws ProfileException {
         

[... 99 lines stripped ...]


More information about the commits mailing list