[java-opensaml] branch main updated: Add a lookup strategy hook to inject message handler function.

Scott Cantor cantor.2 at osu.edu
Tue Feb 28 16:35:13 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=94a965a3b8c807184786b257827c2f1f2a2685f3

The following commit(s) were added to refs/heads/main by this push:
     new 94a965a3b Add a lookup strategy hook to inject message handler function.
94a965a3b is described below

commit 94a965a3b8c807184786b257827c2f1f2a2685f3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Feb 28 11:35:10 2023 -0500

    Add a lookup strategy hook to inject message handler function.
---
 .../handler/impl/FunctionMessageHandler.java       | 31 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/FunctionMessageHandler.java b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/FunctionMessageHandler.java
index c52b22acb..a26aabe97 100644
--- a/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/FunctionMessageHandler.java
+++ b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/FunctionMessageHandler.java
@@ -26,6 +26,9 @@ import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.handler.AbstractMessageHandler;
 import org.opensaml.messaging.handler.MessageHandlerException;
 
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.FunctionSupport;
+
 /**
  * Message handler that runs an injected function (expected to have side effects).
  * 
@@ -36,7 +39,12 @@ import org.opensaml.messaging.handler.MessageHandlerException;
 public final class FunctionMessageHandler extends AbstractMessageHandler {
     
     /** The {@link Function} to run. */
-    @Nullable private Function<MessageContext,Exception> messageContextConsumer;
+    @Nonnull private Function<MessageContext,Function<MessageContext,Exception>> lookupStrategy;
+    
+    /** Constructor. */
+    public FunctionMessageHandler() {
+        lookupStrategy = FunctionSupport.constant(null);
+    }
     
     /**
      * Set the {@link Function} to use.
@@ -46,15 +54,30 @@ public final class FunctionMessageHandler extends AbstractMessageHandler {
     public void setFunction(@Nullable final Function<MessageContext,Exception> function) {
         checkSetterPreconditions();
 
-        messageContextConsumer = function;
+        lookupStrategy = FunctionSupport.constant(function);
+    }
+    
+    /**
+     * Set a lookup strategy for the {@link Function} to use.
+     * 
+     * @param strategy lookup strategy
+     * 
+     * @since 5.0.0
+     */
+    public void setFunctionLookupStrategy(
+            @Nonnull final Function<MessageContext,Function<MessageContext,Exception>> strategy) {
+        checkSetterPreconditions();
+        
+        lookupStrategy = Constraint.isNotNull(strategy, "Function lookup strategy cannot be null");
     }
     
     /** {@inheritDoc} */
     @Override
     protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
-        if (messageContextConsumer != null) {
+        final Function<MessageContext,Exception> f = lookupStrategy.apply(messageContext);
+        if (f != null) {
             try {
-                final Exception e = messageContextConsumer.apply(messageContext);
+                final Exception e = f.apply(messageContext);
                 if (e != null) {
                     throw e;
                 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list