Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Studio Transformers

Transformers Overview

A Transformer prepares a message to be processed through a Mule flow by enhancing or altering the message header or message payload. For example, if the message source that triggers your flow receives data in XML format, but a downstream message processor requires JSON-formatted data, one or more transformers positioned between the message source and the message processor can achieve the necessary translation. (Since no XML-to-JSON transformer exists, this particular example calls for a XML-to-Object transformer chained to an Object-to-JSON transformer).

Mule Studio provides a set of standard transformers to handle the most common data transformation scenarios. Typically, these pre-packaged building blocks require minimal configuration. However, if your particular use case requires special settings, you can open the Properties pane for the particular Transformer have selected, and modify the default configuration using the drop-down lists or text-entry fields.

Studio also provides a Custom Transformer, which you can use if no pre-packaged transformer meets your needs. This option requires you to code a Java class that performs the exact transformation you need. You then configure the Custom Transformer to reference this custom class.

You can string transformers together into chains so that the output of one becomes the input for the next, and so on. For example, if you need to implement an A-to-D transformation, but no such pre-packaged transformer exists, you may be able to find all the pre-packaged transformers necessary to implement the chain A-to-B, B-to-C, and C-to-D, which effectively and efficiently simulates the unavailable A-to-D transformer.

Common Transformer Configuration Fields

Most transformers share a set of common configuration fields, although these fields may be distributed in different ways across the General, Advanced, and Documentation tabs of the Properties pane. The following table describes each of these common fields:

Field Description

Display Name

Defaults to the generic transformer name. Change the display name, which must be alpha-numeric, to reflect the transformer’s specific role, i.e. "Appends time stamp ID."

Return Class

Specify the Java class that generates the transformer output. This value is referenced when selecting transformers automatically or checking that the transformer has returned the proper type of output.
Note : To specify an array type, postfix the class name with square brackets '[]', as in 'org.mule.tck.testmodels.fruit.Orange[]'.

Ignore Bad Input

Check this box to specify whether a transformer should pass a message it has not been able to process on to the next transformer in the transformer chain. If the box is left unchecked, the transformer will retain the result generated up to that point without passing anything to the next transformer in the chain.

Encoding

Specify from the drop-down list the type of string encoding (such as UTF-8 or US ASCII, etc.) used for output.

Mime

Specify from the drop-down list the MIME type used for output, such as text/plain or application/json.

Description

Enter a detailed description of this transformer for display in a yellow help balloon that pops up when you hover your mouse over the endpoint icon.

Operation

Specify the type of database query the Mongo DB transformer will execute. The choices are:

  • bson list to json

  • DB object to map

  • DB object to json

  • json to DB object

  • mongo collection to json

Transformers Available in Studio

The transformers provided on the Studio Palette fall into three broad categories, as detailed by the tables below:

Script Transformers

This type of transformer integrates a script to perform the transformation. One transformer is provided for each of the four supported scripting languages, and a fifth, generic transformer can implement a script written in any of the four languages.

Script
Transformer
Description Documentation

groovy-transformer-24x16

Groovy

Implements a Groovy script transformer backed by a Groovy script engine.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

javascript-transformer-24x16

JavaScript

Implements a JavaScript transformer backed by a JavaScript script engine.

Script Transformer Reference

ruby-transformer-24x16

Ruby

Java Object Transformers

Each transformer in this group changes a Java object into another Java object, a Java object into some other data type (such as an HTTP request), or some non-Java data type (such as an HTTP response) into a Java object.

Java Object
Transformer
Description Documentation

Transformer-24x16

Byte-Array-to-Object

Converts a byte array to an object, either by de-serializing the array or converting it to a string).

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Byte-Array-to-Serializable

Deserializes a byte array, thus converting it into an object.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

File-to-Byte-Array

Reads the contents of a java.io.File into a Byte array

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

HTTP-Response-to-Object

Converts an HTTP response (i.e., a string, stream, or byte array payload) into a Mule message.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

JmsMessage-to-Object

Converts a JMS message into an object by extracting the message payload.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Object-to-Byte-Array

Serializes all objects except for strings, which are converted using the getBytes() method.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Object-to-JmsMessage

Converts a Java Object into one of five types of JMS messages, depending on the object.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Object-to-String

Converts program code types into readable text strings. Used for debugging.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Serializable-to-Byte-Array

Converts a Java object to a byte array by serializing the object.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Content Transformers

This group of transformers modifies messages by adding to, deleting from, or converting a message payload (or a message header).

Content
Transformer
Description Documentation

Transformer-24x16

Append string

Appends a string to a message payload.

Append String Transformer Reference

Transformer-24x16

Body-to-Parameter-map

Converts the body of an HTTP request into a Map object.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

HTTP-Response-to-String

Converts an HTTP response into a string and preserves the message header.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Message-to-HTTP-Response

Creates a valid HTTP response using the current message and its HTTP headers.

All of the configuration fields for this transformer are covered in the Common Transformer Configuration Fields section of this page.

Transformer-24x16

Transformer Ref

References a transformer that is defined as a global element.

Transformer Reference

For detailed information on configuring standard and custom Transformers with an XML editor, see Using Transformers.