Package org.apache.synapse.mediators.bsf
Class ScriptMediator
java.lang.Object
org.apache.synapse.mediators.AbstractMediator
org.apache.synapse.mediators.bsf.ScriptMediator
- All Implemented Interfaces:
org.apache.synapse.aspects.AspectConfigurable,org.apache.synapse.Mediator,org.apache.synapse.SynapseArtifact
public class ScriptMediator
extends org.apache.synapse.mediators.AbstractMediator
A Synapse mediator that calls a function in any scripting language supported by the BSF.
The ScriptMediator supports scripts specified in-line or those loaded through a registry
<script [key="entry-key"]
[function="script-function-name"] language="nashornJs|javascript|groovy|ruby"invalid input: '>'
(text | xml)?
</script>
The function is an optional attribute defining the name of the script function to call,
if not specified it defaults to a function named 'mediate'. The function takes a single
parameter which is the Synapse MessageContext. The function may return a boolean, if it
does not then true is assumed.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ScriptEngineThe BSF engine created to validate each JSON payloadprotected ScriptEngineThe BSF engine created to process each message through the scriptFields inherited from class org.apache.synapse.mediators.AbstractMediator
log, trace, traceState -
Constructor Summary
ConstructorsConstructorDescriptionScriptMediator(String language, String scriptSourceCode, ClassLoader classLoader) Create a script mediator for the given language and given script source.ScriptMediator(String language, Map<org.apache.synapse.mediators.Value, Object> includeKeysMap, org.apache.synapse.mediators.Value key, String function, ClassLoader classLoader) Create a script mediator for the given language and given script entry key and function. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.synapse.mediators.ValuegetKey()protected voidInitialise the Mediator for the inline scriptprotected voidbooleanbooleanmediate(org.apache.synapse.MessageContext synCtx) Perform Script mediation.protected ScriptEngineWrapperprepareExternalScript(org.apache.synapse.MessageContext synCtx) Prepares the mediator for the invocation of an external scriptvoidsetInputArgumentMap(Map<String, org.apache.synapse.mediators.v2.ext.InputArgument> inputArgumentMap) voidsetLoader(ClassLoader loader) voidsetResultTarget(String resultTarget) voidsetVariableName(String variableName) Methods inherited from class org.apache.synapse.mediators.AbstractMediator
auditLog, auditWarn, configure, disableStatistics, disableTracing, divertMediationRoute, enableStatistics, enableTracing, getArtifactIdentifier, getAspectConfiguration, getCommentsList, getDescription, getInputType, getLastSequenceFaultHandler, getLog, getMediatorId, getMediatorName, getMediatorPosition, getOutputType, getRegisteredMediationFlowPoint, getShortDescription, getTraceState, getType, handleException, handleException, isBreakPoint, isContentAware, isSkipEnabled, isStatisticsEnable, isTraceOn, isTraceOrDebugOn, isTracingEnabled, registerMediationFlowPoint, reportCloseStatistics, reportCloseStatisticsWithError, reportOpenStatistics, setArtifactIdentifier, setBreakPoint, setCommentsList, setComponentStatisticsId, setDescription, setEffectiveTraceState, setMediatorId, setMediatorPosition, setShortDescription, setSkipEnabled, setTraceState, shouldCaptureTracing, shouldTrace, shouldTrace, traceOrDebug, traceOrDebugWarn, unregisterMediationFlowPoint
-
Field Details
-
scriptEngine
The BSF engine created to process each message through the script -
jsEngine
The BSF engine created to validate each JSON payload
-
-
Constructor Details
-
ScriptMediator
Create a script mediator for the given language and given script source.- Parameters:
language- the BSF languagescriptSourceCode- the source code of the script
-
ScriptMediator
public ScriptMediator(String language, Map<org.apache.synapse.mediators.Value, Object> includeKeysMap, org.apache.synapse.mediators.Value key, String function, ClassLoader classLoader) Create a script mediator for the given language and given script entry key and function.- Parameters:
language- the BSF languageincludeKeysMap- Include script keyskey- the registry entry key to load the scriptfunction- the function to be invoked
-
-
Method Details
-
mediate
public boolean mediate(org.apache.synapse.MessageContext synCtx) Perform Script mediation.- Parameters:
synCtx- the Synapse message context- Returns:
- the boolean result from the script invocation
-
initInlineScript
protected void initInlineScript()Initialise the Mediator for the inline script -
prepareExternalScript
protected ScriptEngineWrapper prepareExternalScript(org.apache.synapse.MessageContext synCtx) throws ScriptException Prepares the mediator for the invocation of an external script- Parameters:
synCtx- MessageContext script- Throws:
ScriptException- For any errors , when compile the script
-
initScriptEngine
protected void initScriptEngine() -
getLanguage
-
getKey
public org.apache.synapse.mediators.Value getKey() -
getFunction
-
getScriptSrc
-
getIncludeMap
-
getLoader
-
setLoader
-
getNewScriptEngine
-
isContentAltering
public boolean isContentAltering()- Specified by:
isContentAlteringin interfaceorg.apache.synapse.Mediator- Overrides:
isContentAlteringin classorg.apache.synapse.mediators.AbstractMediator
-
setInputArgumentMap
-
getInputArgumentList
-
setResultTarget
-
getResultTarget
-
setVariableName
-
getVariableName
-