Martini Services Groovy Classes Inputs & Outputs
In Martini's Groovy services, the function signature plays a crucial role in defining the expected service inputs and outputs. This section covers how inputs and outputs are handled, focusing on the injectable arguments and their usage in both scripts and functions.
Injectable Arguments
Martini supports a variety of injectable arguments for Groovy services, enhancing the flexibility and functionality of service endpoints. These arguments can be broadly categorized into two types:
-
Arguments for Martini Service Triggers:
- These are specific to the type of trigger invoking the service. A detailed description of injectable arguments for each trigger type can be found on their respective documentation pages. Refer to Trigger Types for more information.
-
Arguments for Spring Controllers:
- For APIs exposed via Groovy-based Spring controllers, the supported arguments and return types for
@RequestMapping
functions are documented extensively in the Spring framework documentation. For detailed information, refer to Spring Framework Reference: Defining RequestMapping Handler Methods.
- For APIs exposed via Groovy-based Spring controllers, the supported arguments and return types for
Injecting Arguments in Scripts
Groovy scripts in Martini do not have explicitly declared inputs or outputs. Instead, Martini provides a binding mechanism that injects all available data into the script. This binding grants the script access to all variables within the execution context.
Here's an example demonstrating how to log the HTTP request object:
1 |
|
In this script, ${request}
is an injectable argument provided by Martini, enabling access to the HTTP request details.
Injecting Arguments in Functions
Unlike scripts, Groovy functions in Martini allow for the explicit declaration of input variables. This feature provides clearer definitions and usage of service inputs.
Consider the following function example, which publishes a string message to a JMS queue:
1 2 3 |
|
In this function, HttpServletRequest request
is a declared parameter, representing the HTTP request object. The function then processes and publishes the request information to the specified JMS queue.