Package org.opensaml.messaging.handler

# Class AbstractMessageHandler

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
org.opensaml.messaging.handler.AbstractMessageHandler

All Implemented Interfaces:
  `Component`, `DestructableComponent`, `InitializableComponent`, `MessageHandler`

Direct Known Subclasses:
  `AbstractHeaderGeneratingMessageHandler`, `AbstractHttpServletRequestMessageHandler`, `AbstractMessageChannelSecurity`, `AddChannelBindingsHeaderHandler`, `AddConsentToResponseHandler`, `AddECPResponseHeaderHandler`, `AddGeneratedKeyHeaderHandler`, `AddRelayStateHeaderHandler`, `AddRequestAuthenticatedHeaderHandler`, `BaseTrustEngineSecurityHandler`, `BasicMessageHandlerChain`, `CheckAndRecordServerTLSEntityAuthenticationtHandler`, `CheckExpectedIssuer`, `CheckMandatoryAuthentication`, `CheckMandatoryIssuer`, `CheckMessageStatusHandler`, `CheckMessageVersionHandler`, `CheckNoPassiveHandler`, `EndpointURLSchemeSecurityHandler`, `EnvelopeBodyHandler`, `ExtractChannelBindingsExtensionsHandler`, `ExtractChannelBindingsHeadersHandler`, `ExtractConsentFromRequestHandler`, `ExtractMessageIDHandler`, `ExtractProxiedRequestersHandler`, `FunctionMessageHandler`, `InResponseToSecurityHandler`, `MessageHandlerErrorStrategyAdapter`, `MessageLifetimeSecurityHandler`, `MessageReplaySecurityHandler`, `PopulateHttpClientSecurityParametersHandler`, `PopulateSignatureSigningParametersHandler`, `PopulateSignatureValidationParametersHandler`, `SAML1ArtifactRequestIssuerHandler`, `SAML2AuthnRequestsSignedSecurityHandler`, `SAMLAddAttributeConsumingServiceHandler`, `SAMLMetadataLookupHandler`, `SAMLOutboundDestinationHandler`, `SAMLOutboundProtocolMessageSigningHandler`, `SAMLProtocolAndRoleHandler`, `SAMLSOAPDecoderBodyHandler`, `SchemaValidateXMLMessage`, `SimplePayloadBodyHandler`, `ValidateActionHandler`, `WSSecuritySAML20AssertionTokenSecurityHandler`

@Prototype public abstract class AbstractMessageHandler extends AbstractInitializableComponent implements MessageHandler
A base abstract implementation of `MessageHandler`.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Predicate<MessageContext>`
`activationCondition`
Condition dictating whether to run or not.
`private org.slf4j.Logger`
`log`
Logger.
`private boolean`
`preInvokeCalled`
Has `doPostInvoke(MessageContext)` been called?.

## Constructor Summary

Constructors
Constructor
Description
`AbstractMessageHandler()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected abstract void`
`doInvoke(MessageContext messageContext)`
Performs the handler logic.
`protected void`
`doPostInvoke(MessageContext messageContext)`
Called after execution, handlers may override this method to perform post-processing for a request.
`protected void`
`doPostInvoke(MessageContext messageContext, Exception e)`
Called after execution, handlers may override this method to perform post-processing for a request.
`protected boolean`
`doPreInvoke(MessageContext messageContext)`
Called prior to execution, handlers may override this method to perform pre-processing for a request.
`Predicate<MessageContext>`
`getActivationCondition()`
Get activation condition indicating whether the handler should be invoked.
`protected String`
`getLogPrefix()`
Return a prefix for logging messages for this component.
`void`
`invoke(MessageContext messageContext)`
Invoke the handler on the specified message context.
`protected boolean`
`isPreInvokeCalled()`
Has the `doPreInvoke(MessageContext)` method been entirely called? Note the unsynchronized access.
`void`
`setActivationCondition(Predicate<MessageContext> condition)`
Set activation condition indicating whether the handler should be invoked.

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, doInitialize, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.shibboleth.shared.component.InitializableComponent

`initialize, isInitialized`

## Field Details

### log

@Nonnull private org.slf4j.Logger log
Logger.

### activationCondition

@Nonnull private Predicate<MessageContext> activationCondition
Condition dictating whether to run or not.

### preInvokeCalled

private boolean preInvokeCalled
Has `doPostInvoke(MessageContext)` been called?. Only ever set to true

## Constructor Details

### AbstractMessageHandler

public AbstractMessageHandler()
Constructor.

## Method Details

### getActivationCondition

@Nonnull public Predicate<MessageContext> getActivationCondition()
Get activation condition indicating whether the handler should be invoked.

Defaults to a predicate which always returns `true`.

Returns:
  activation condition

### setActivationCondition

public void setActivationCondition(@Nonnull Predicate<MessageContext> condition)
Set activation condition indicating whether the handler should be invoked.

Defaults to a predicate which always returns `true`.

Parameters:
  `condition` - predicate to apply

### invoke

public void invoke(@Nonnull MessageContext messageContext) throws MessageHandlerException
Invoke the handler on the specified message context.

Specified by:
  `invoke` in interface `MessageHandler`
Parameters:
  `messageContext` - the message context on which to invoke the handler
Throws:
  `MessageHandlerException` - if the there is an error invoking the handler on the message context

### doPreInvoke

protected boolean doPreInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException
Called prior to execution, handlers may override this method to perform pre-processing for a request.

The default impl applies the `Predicate` set via the `setActivationCondition(Predicate)`.

If false is returned, execution will not proceed.

Subclasses which override this method should generally invoke the super version of this method first, so that the activation condition will be applied up front, and immediately return false if the super version returns false. This avoids unnecessary execution of the remaining pre-invocation code if the handler ultimately will not execute.

Parameters:
  `messageContext` - the message context on which to invoke the handler
Returns:
  true iff execution should proceed
Throws:
  `MessageHandlerException` - if there is a problem executing the handler pre-routine

### doInvoke

protected abstract void doInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException
Performs the handler logic.

Parameters:
  `messageContext` - the message context on which to invoke the handler
Throws:
  `MessageHandlerException` - if there is an error invoking the handler on the message context

### doPostInvoke

protected void doPostInvoke(@Nonnull MessageContext messageContext)
Called after execution, handlers may override this method to perform post-processing for a request.

Handlers must not "fail" during this step. This method will not be called if `doPreInvoke(org.opensaml.messaging.context.MessageContext)` fails, but is called if an exception is raised by `doInvoke(org.opensaml.messaging.context.MessageContext)`.

Parameters:
  `messageContext` - the message context on which the handler was invoked

### doPostInvoke

protected void doPostInvoke(@Nonnull MessageContext messageContext, @Nonnull Exception e)
Called after execution, handlers may override this method to perform post-processing for a request.

Handlers must not "fail" during this step. This method will not be called if `doPreInvoke(org.opensaml.messaging.context.MessageContext)` fails, but is called if an exception is raised by `doInvoke(org.opensaml.messaging.context.MessageContext)`.

This version of the method will be called if an exception is raised during execution of the handler. The overall handler result will be to raise this error, so any errors inadvertently raised by this method will be logged and superseded.

The default implementation simply calls the error-less version of this method.

Parameters:
  `messageContext` - the message context on which the handler was invoked
  `e` - an exception raised by the `doInvoke(org.opensaml.messaging.context.MessageContext)` method

### isPreInvokeCalled

protected boolean isPreInvokeCalled()
Has the `doPreInvoke(MessageContext)` method been entirely called? Note the unsynchronized access. The underlying field is only ever set true, so if true is returned it is correct, if false is returned is is not safe to make any assumptions (even if there was an call in flight.

Returns:
  true iff the `doPreInvoke(MessageContext)` method was called
Since:
  5.0.0

### getLogPrefix

@Nonnull @NotEmpty protected String getLogPrefix()
Return a prefix for logging messages for this component.

Returns:
  a string for insertion at the beginning of any log messages