Skip to content

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:

  1. 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.
  2. Arguments for Spring Controllers:

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
"Hello, world! The request used to invoke me is ${request}.".info()

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
void helloWorld(HttpServletRequest request) {
    "Hello, world! The request used to invoke me is ${request}.".publishTo('queue://my.jms.HTTPQueue')
}

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.