Skip to content

Inputs and Outputs of a Service

Similar to a function, all services consist of inputs and outputs. Inputs are parameters that your service uses to perform its process. Outputs, on the other hand, contain the resulting values of your service.

Adding Inputs and Outputs

Coder makes it easy to define the input and output variables of Gloop and Flux Services using the Input/Output view. This view is shown by default when editing a Gloop or Flux Service.

The I/O View

The I/O View

To add an input variable, right click on the Input half of the Input/Output view, select Add from the context menu, and click on the type of variable you want to add. After successfully adding your variable, you have the option to rename it.

Adding a new Gloop Service input variable

Adding a new Gloop Service input variable

The same steps apply when it comes to adding output variables; the only difference is that you have to right click on the Output half of the Input/Output view.

Pressing . while focused on the Input/Output view triggers the content-assist feature which enables the user to quickly insert a variable. Aside from basic variable types, it also allows the user to pick Gloop Models and array variables directly. Simply use the arrow keys to shuffle through the available types and hit to confirm your choice.

I/O View Shortcut

I/O View Shortcut

An alternative way to add Gloop Models as input or output variables is by dragging them from the Coder Navigator to the Input/Output view.

Dragging and dropping Gloop Models from the *Coder Navigator*

Dragging and dropping Gloop Models from the *Coder Navigator*

Meanwhile, for Groovy Services, Coder features content assist. It provides contextual code completion while typing or upon user request (tap ^ + Space). Coder analyzes the possible choices from the current caret position and shows its suggestions on a popup window.

If you're writing a piece of Groovy code that is to be used with Gloop, the Input/Output view can still be used to add inputs and outputs with Gloop-specific annotations! Place the cursor in a method and as you edit the inputs and outputs in the view, Coder Studio will modify your code, format it, and optimise your imports! Just make sure the method is public static.

Adding Input and Output Using Gloop-Enabled Groovy Editor

Injecting Input Variables

When a service is made invokable via HTTP or used in an Integrate Endpoint, additional input variables can be injected for further use. All you need to do is declare the input variables needed by your service and ensure they are named appropriately.

Strictly use standard variable names

TORO Integrate won't inject the values of parameters that do not have standard names.

Injectable variables will differ per endpoint type

Some endpoints add more variables than others so it's important that you are aware of the types of endpoints that will execute your code.

Injectable input variables include - but are not limited to - the following:

The process of specifying and mapping input variables depends on how the service itself is defined. The following subsections will discuss the procedures of injecting arguments in detail:

In a Gloop or Flux Service

To inject an argument in Gloop or Flux, you must declare the variable under the Input/Output view. You can use the designated hotkeys or simply do a right click, pick its type, and then rename the variable. In Gloop and Flux, the names of injectable arguments must be prepended by the $ character. From there, you can use the parameter by mapping.

The example below shows how you can obtain the HttpServletRequest object in an HTTP-invokable Gloop Service:

Gloop Logging HTTP Request

When a Gloop or Flux Service is invoked via HTTP, a proxy is used to map inputs to the service. The proxy will then handle the injection of the variables for you.

In a Groovy Script

Since Groovy scripts don't have declared inputs or outputs, TORO Integrate will place all the available data in a binding for you and execute your Groovy script with the binding giving it access to all the variables. Below is a simple piece of code that logs the HTTP request object to the Integrate info logger:

1
"Hello world! The request used to invoke me is ${request}".info()

In a Groovy Method

Unlike Groovy scripts, Groovy methods declare their input variables; to do something similar to the above Groovy script, simply declare the variable as a parameter. The method below publishes the string to a JMS queue.

1
2
3
public void helloWorld(HttpServletRequest request){
    "Hello world! The request used to invoke me is ${request}".publishTo('queue://my.jms.HTTPQueue')
}

Injectable Input Variables

  • Arguments that can be injected to services called by Integrate Endpoints are listed and described in every endpoint type's respective page.
  • Parameters injected by Gloop Steps are also discussed in each Gloop Step type's page.
  • In Gloop, input variables brought by HTTP invokes are listed and described in the How HTTP Requests and Responses are Mapped in Gloop page.
  • When it comes to endpoints exposed via Groovy Spring controllers, supported @RequestMapping method arguments and return types are explained in the Spring documentation.