Package org.frankframework.pipes
Class IfPipe
java.lang.Object
org.frankframework.core.TransactionAttributes
org.frankframework.pipes.AbstractPipe
org.frankframework.pipes.IfPipe
- All Implemented Interfaces:
HasTransactionAttribute
,IConfigurable
,IConfigurationAware
,IForwardTarget
,INamedObject
,IPipe
,IScopeProvider
,IWithParameters
,EventThrowing
,HasStatistics
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
@Forward(name="*",description="when {@literal thenForwardName} or {@literal elseForwardName} are used") @Forward(name="then",description="the configured condition is met") @Forward(name="else",description="the configured condition is not met")
@EnterpriseIntegrationPattern(ROUTER)
public class IfPipe
extends AbstractPipe
Selects a forward based on an expression. The expression type is coupled to the mediaType:
- XML (application/xml) uses Xpath
- JSON (application/json) uses jsonPath
Expressions
Expressions are used to select nodes in the given input document. Imagine a collection of books:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
}
}
With both expression languages you'll be able to select one or multiple nodes from this collection.
Using this pipe there are two options. Use it only with an expression
or combine it with an expressionValue
. When using the expression,
the pipe evaluates to thenForwardName
when there is a match, even it is empty. In the given example, this might be one of:
$.store
$.store.book[1]
$.store.book[?(@.price == 22.99)].author
$.store.book[?(@.category == 'fiction')]
expressionValue
When using expression combined with expressionValue, the pipe evaluates tothenForwardName
when the the matched value is equal to
expressionValue. This needs to be an exact match.
XML/XPATH
Xpath has been around a long time, information about the syntax can be found everywhere on the internet. The XML implementation wraps the Xpath expression in an XSL. This enables us to use complex expressions which evaluate to true or false instead of being used only as a selector of nodes in the input XML. This is available to be backwards compatible with theXmlIf
pipe.
For instance, take the following example input:
<results>
<result name="test"></result>
<result name="test"></result>
</results>
Examples with complex expressions might be something like: number(count(/results/result[contains(@name , 'test')])) > 1
, to test if there's more
than one node found containing the string 'test'. Please check if a simpler, less error-prone expression like
/results/result[contains(@name, 'test')]
can suffice.
Without expression
Without an expression, the default behaviour is to assume the input is a string, the code will try to match the string to an optional regular expression or tries to match the string value to the optional expressionValue.Resources
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.frankframework.pipes.AbstractPipe
parameterNamesMustBeUnique
Fields inherited from class org.frankframework.core.TransactionAttributes
log
Fields inherited from interface org.frankframework.core.IPipe
LONG_DURATION_MONITORING_EVENT, MESSAGE_SIZE_MONITORING_EVENT, PIPE_EXCEPTION_MONITORING_EVENT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
doPipe
(Message message, PipeLineSession session) This is where the action takes place.void
setDefaultMediaType
(IfPipe.SupportedMediaType defaultMediaType) void
setElseForwardName
(String elseForwardName) Deprecated, for removal: This API element is subject to removal in a future version.void
setExpressionValue
(String expressionValue) a string to compare the result of the xpathExpression (or the input-message itself) to.void
setJsonPathExpression
(String jsonPathExpression) jsonPath expression to be applied to the input-message. if not set, no transformation is done when the input message is mediatype JSONvoid
setNamespaceAware
(boolean namespaceAware) controls namespace-awareness of XSLT transformationvoid
setNamespaceDefs
(String namespaceDefinitions) namespace definitions for xpathExpression.void
Deprecated, for removal: This API element is subject to removal in a future version.void
setThenForwardName
(String thenForwardName) Deprecated, for removal: This API element is subject to removal in a future version.void
setXpathExpression
(String string) xpath expression to be applied to the input-message. if not set, no transformation is done when the input message is mediatype XMLvoid
setXsltVersion
(int xsltVersion) If set to2
or3
a Saxon (net.sf.saxon) xslt processor 2.0 or 3.0 respectively will be used, otherwise xslt processor 1.0 (org.apache.xalan)Methods inherited from class org.frankframework.pipes.AbstractPipe
addForward, addParameter, consumesSessionVariable, createBean, findForward, getAdapter, getApplicationContext, getChompCharSize, getConfigurationClassLoader, getDurationThreshold, getElementToMove, getElementToMoveChain, getElementToMoveSessionKey, getEmptyInputReplacement, getEventSourceName, getForwards, getGetInputFromFixedValue, getGetInputFromSessionKey, getHideRegex, getLocker, getLogIntermediaryResults, getMaxThreads, getName, getParameterList, getPipeLine, getSecLogSessionKeys, getStoreResultInSessionKey, hasRegisteredForward, isPreserveInput, isRemoveCompactMsgNamespaces, isRestoreMovedElements, isWriteToSecLog, registerEvent, setApplicationContext, setChompCharSize, setDurationThreshold, setElementToMove, setElementToMoveChain, setElementToMoveSessionKey, setEmptyInputReplacement, setEventPublisher, setGetInputFromFixedValue, setGetInputFromSessionKey, setHideRegex, setLocker, setLogIntermediaryResults, setMaxThreads, setName, setPipeLine, setPreserveInput, setRemoveCompactMsgNamespaces, setRestoreMovedElements, setSecLogSessionKeys, setSizeStatistics, setStoreResultInSessionKey, setWriteToSecLog, sizeStatisticsEnabled, start, stop, throwEvent
Methods inherited from class org.frankframework.core.TransactionAttributes
configureTransactionAttributes, getTransactionAttribute, getTransactionTimeout, getTxDef, isTransacted, isTransacted, setTransacted, setTransactionAttribute, setTransactionTimeout
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.frankframework.core.IPipe
throwEvent
-
Constructor Details
-
IfPipe
public IfPipe()
-
-
Method Details
-
configure
Description copied from class:AbstractPipe
configure()
is called after thePipeline
is registered at theAdapter
. Purpose of this method is to reduce creating connections to databases etc. in thedoPipe()
method. As much as possible class-instantiating should take place in theconfigure()
method, to improve performance.- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceIPipe
- Overrides:
configure
in classAbstractPipe
- Throws:
ConfigurationException
-
doPipe
Description copied from interface:IPipe
This is where the action takes place. Pipes may only throw a PipeRunException, to be handled by the caller of this object. Implementations must either consume the message, or pass it on to the next Pipe in the PipeRunResult. If the result of the Pipe does not depend on the input, like for theFixedResultPipe
, the Pipe can schedule the input to be closed at session exit, by callingMessage.closeOnCloseOf(PipeLineSession, String)
This allows the previous Pipe to release any resources (e.g. connections) that it might have kept open until the message was consumed. Doing so avoids connections leaking from pools, while it enables efficient streaming processing of data while it is being read from a stream.- Throws:
PipeRunException
-
setThenForwardName
@Deprecated(forRemoval=true, since="9.0") @ConfigurationWarning("Use the \'then\' forward in your configuration") public void setThenForwardName(String thenForwardName) Deprecated, for removal: This API element is subject to removal in a future version.forward returned when output istrue
- Default value
- then
-
setElseForwardName
@Deprecated(forRemoval=true, since="9.0") @ConfigurationWarning("Use the \'else\' forward in your configuration") public void setElseForwardName(String elseForwardName) Deprecated, for removal: This API element is subject to removal in a future version.forward returned when output isfalse
- Default value
- else
-
setExpressionValue
a string to compare the result of the xpathExpression (or the input-message itself) to. If not specified, a non-empty result leads to the 'then'-forward, an empty result to 'else'-forward -
setXpathExpression
xpath expression to be applied to the input-message. if not set, no transformation is done when the input message is mediatype XML -
setJsonPathExpression
jsonPath expression to be applied to the input-message. if not set, no transformation is done when the input message is mediatype JSON -
setRegex
@Deprecated(forRemoval=true, since="9.0") @ConfigurationWarning("Use RegExPipe instead") public void setRegex(String regex) Deprecated, for removal: This API element is subject to removal in a future version.Regular expression to be applied to the input-message (ignored if eitherxpathExpression
orjsonPathExpression
is specified). The input-message fully matching the given regular expression leads to the 'then'-forward -
setXsltVersion
public void setXsltVersion(int xsltVersion) If set to2
or3
a Saxon (net.sf.saxon) xslt processor 2.0 or 3.0 respectively will be used, otherwise xslt processor 1.0 (org.apache.xalan)- Default value
- 2
-
setNamespaceDefs
namespace definitions for xpathExpression. Must be in the form of a comma or space separated list ofprefix=namespaceuri
definitions. -
setNamespaceAware
public void setNamespaceAware(boolean namespaceAware) controls namespace-awareness of XSLT transformation- Default value
- true
-
setDefaultMediaType
- Parameters:
defaultMediaType
- the default media type to use when the media type of the message could not be determined.- Default value
- DefaultMediaType.XML
-