[java-opensaml] branch main updated: Hook for adapting existing function classes into a MessageHandler.
Scott Cantor
cantor.2 at osu.edu
Mon Jan 4 21:53:29 UTC 2021
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=30ac221a99f256e8dec566644bad8ebe1bd83c15
The following commit(s) were added to refs/heads/main by this push:
new 30ac221a9 Hook for adapting existing function classes into a MessageHandler.
30ac221a9 is described below
commit 30ac221a99f256e8dec566644bad8ebe1bd83c15
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Jan 4 16:53:26 2021 -0500
Hook for adapting existing function classes into a MessageHandler.
---
.../handler/impl/FunctionMessageHandler.java | 72 ++++++++++++++++++++++
1 file changed, 72 insertions(+)
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
new file mode 100644
index 000000000..8b8fdbaed
--- /dev/null
+++ b/opensaml-messaging-impl/src/main/java/org/opensaml/messaging/handler/impl/FunctionMessageHandler.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensaml.messaging.handler.impl;
+
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import net.shibboleth.utilities.java.support.component.ComponentSupport;
+
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.handler.AbstractMessageHandler;
+import org.opensaml.messaging.handler.MessageHandlerException;
+
+/**
+ * Message handler that runs an injected function (expected to have side effects).
+ *
+ * <p>The function may return an exception to signal failure, allowing for checked exceptions.</p>
+ *
+ * @since 4.1.0
+ */
+public final class FunctionMessageHandler extends AbstractMessageHandler {
+
+ /** The {@link Function} to run. */
+ @Nullable private Function<MessageContext,Exception> messageContextConsumer;
+
+ /**
+ * Set the {@link Function} to use.
+ *
+ * @param function the function to use
+ */
+ public void setFunction(@Nullable final Function<MessageContext,Exception> function) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+ messageContextConsumer = function;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
+ if (messageContextConsumer != null) {
+ try {
+ final Exception e = messageContextConsumer.apply(messageContext);
+ if (e != null) {
+ throw e;
+ }
+ } catch (final Exception e) {
+ if (e instanceof MessageHandlerException) {
+ throw (MessageHandlerException) e;
+ }
+ throw new MessageHandlerException(e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list