Introduction to Groovy
Groovy is a scripting language that runs on the Java Virtual Machine and is used in 1Gateway to apply custom logic at different stages of message processing.
Groovy is typically used when standard configuration is not sufficient, for example when using less common communication protocols or when additional message processing is required.
In addition to the groovy general scripting offering you can use various functions in 1Gateway through the SDK which provides extended capabilities such as message handling, logging, HTTP, FTP, and data storage and more. Click here to go to the Groovy SDK.
When to use Groovy
Groovy plugins are intended as a powerful extension mechanism, not a replacement for built-in functionality.
Groovy is most appropriate when:
- Message processing depends on conditional or dynamic rules
- External systems need to be accessed in a custom way
- Standard configuration cannot express the required behavior
What Groovy SDK provides
The 1Gateway Groovy SDK provides a consistent and supported way to interact with the platform and external systems and can be used for:
- Message content and metadata
- Logging utilities
- HTTP and FTP clients
- SQL and datastore access
- Parsing utilities for structured data
Where to use Groovy
Groovy can be used in the following places within 1Gateway.
1. Groovy Pollers (Inbound)
Groovy can be used in custom Groovy pollers, which execute a script on a fixed interval.
Groovy pollers are typically used:
- Poll external systems (for example, HTTP APIs or FTP locations)
- Run scheduled background logic
- Create and publish messages to 1Gateway
In this case, Groovy acts as a scheduled entry point into message processing.
Groovy pollers do not receive messages.
2. Groovy Senders (Outbound)
Groovy can be used in custom Groovy sender plugins, which execute logic when a message is about to be sent to an external system.
Groovy senders are typically used when:
- Sending data to custom or non-standard endpoints
- Applying destination-specific logic
- Performing additional validation or enrichment before delivery
Groovy senders receive messages that have already passed through routing and mapping and allow full control over outbound behavior.
3. Groovy for Message Transformation in Mappers
Groovy can be used inside mappers as part of message transformation.
Groovy mappings are typical used:
- Apply conditional logic during transformation
- Enrich the message with additional data
- Perform complex calculations or data restructuring
- Work with structured data formats such as JSON or XML
Groovy scripts in mappings are executed as part of the transformation of the message in a mapper.
4. Groovy Filters in Mappers
Overview Options how filters get applied during transformation.
Mappers:
Groovy can be used in mapper filters to decide whether a message should be transformed or not.
A mapper filter is evaluated before transformation:
- If the message matches the filter, the mapper gets applied.
- If the message does not match the filter, the message does not go through that mapper and is published unchanged (not discarted).
- Other mappers in the same plugin may still receive and process the message.
The message is not discarded.
Sender Plugins
Groovy filters can also be configured on any sender plugins.
In this case:
- If a message matches the plugin filter, it is processed by that plugin.
- If the message does not match the filter, it is not processed by that plugin.
- Messages that do not match a sender plugin filter are not discarded.
Filters in sender plugins apply only to plugins that receive messages. They do not apply to Groovy pollers, as pollers do not receive messages.