string splitter

String Splitter

Version: 17.07

Supported Since: 17.01

What is a String Splitter?

A String Splitter is a processing element which can be used to extract a value from the message context, then split that extracted value giving a delimiting pattern and finally store the resulting string array as a scope variable of type List.

For example say the extracted string value to be split is "foo:and:boo" and the delimiting pattern is set to ":", then the result would be an string list as {"foo", "and", "boo"}.

Once the list is stored as a scope variable, For Each processing element can be used to iterate through the list and do relevant processing. If the requirement is to directly access the list perhaps in a custom processing element, it can be done as follows.

@Processor(displayName = "Custom", type = ProcessorType.CUSTOM)
public class Custom extends AbstractSequencedProcessingElement {

    @Override
    protected ExecutionResult sequencedProcess(XMessageContext xMessageContext) {

        /*
         * Accessing the list.
         * Note that the first call in the following line returns and Optional and get() is called on that.
         * Depending on the scenario user might want to check ifPresent() as well. Those are omitted here for clarity.
         */
        List<String> list = xMessageContext.getScopeVariable("test", List.class, true).get();

        // rest of the code

        return ExecutionResult.SUCCESS;
    }
}

In order to use this processing element, you must first select the String Processors dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the String Processors dependency.

Alternatively, you can add the following dependency to the maven pom.xml manually.

<dependency>
    <groupId>org.adroitlogic.x.processors</groupId>
    <artifactId>x-processor-string</artifactId>
    <version>17.07</version>
</dependency>
string splitter outports

Out Ports

Next

The message will be sent to this outport if the string split operation is successful

On Exception

The message will be sent to this outport if the processing element failed in string split operation

Parameters

Variable Name*

Basic

Name for the scope variable to store the resulting string after split operation.

Extraction Type*

Basic

Defines how the value which is to be subjected to split operation, is extracted from message context. This is an select type parameter and has following options to be selected from.

  • HEADER - The value of a message transport header should be extracted

  • PROPERTY - The value of a message property should be extracted

  • VARIABLE - The value of a scope variable in any scope should be extracted

  • CURRENT_SCOPE_VARIABLE - The value of a scope variable which is in current scope should be extracted

Extraction Name*

Basic

Depending on the selected Extraction Type, input for this parameter should vary as follows.

  • HEADER - In this case the value of this parameter should be the name of the transport header

  • PROPERTY - In this case the value of this parameter should be the name of the message property

  • VARIABLE - In this case the value of this parameter should be the name of the scope variable

  • CURRENT_SCOPE_VARIABLE - In this case the value of this parameter should be the name of the scope variable in current context.

Delimiting Regex*

Basic

The delimiting Regex Pattern

The resulting string list saved by this processing element will contain each substring of the input string (value extracted from message context), that is terminated by another sub-sequence that matches this pattern or is terminated by the end of the input string. The sub-strings in the list are in the order in which they occur in the input string. Example-1 below explains these cases.

If this pattern does not match any sub-sequence of the input string then the resulting list has just one element, namely the input string (value extracted from message context) itself. Example-2 below explains this scenario.

When there is a positive-width match at the beginning of the input sequence then an empty leading substring is included at the beginning of the resulting list. A zero-width match at the beginning however never produces such empty leading substring. Example-3 and Example-4 below describes these cases.

Example 1:

Input String: "foo:and:boo"
Delimiting Regex Pattern: ":"
Resulting List: {"foo", "and", "boo"}

In the above example the first two elements "foo" and "boo" are both terminated by the ":", a sub-sequence that matches the given pattern ":" and the third and last element "boo" is terminated by the end of string and not by a sub-sequence that matches the pattern.

Example 2:

Input String: "foo:and:boo"
Delimiting Regex Pattern: "*"
Resulting List: {"foo:and:boo"}

In the above example the given pattern "*" does not match any sub-sequence hence the result is an list with only one element, the input string itself.

Example 3:

Input String: ":foo:and:boo"
Delimiting Regex Pattern: ":"
Resulting List: {"", "foo", "and", "boo"}

In this case the first character in the input string matches the given delimiting regex. Hence we can see that "" an empty string is included as the first string.

Example 4:

Input String: "ultraesb"
Delimiting Regex Pattern: "" (an empty string)
Resulting List: {"u", "l", "t", "r", "e", "s", "b"}

Now in this example the delimiter regex pattern is empty string. Therefore this has a zero-length match at the beginning of the input string as well. However since the match is zero length there will not be an empty string included in the resulting list.

Limit

Basic

This is an optional parameter which controls the number of times the pattern is applied and therefore affects the length of the resulting list. The default value is zero.

If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the list’s length will be no greater than n, and the list’s last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the list can have any length. If n is zero then the pattern will be applied as many times as possible, the list can have any length, and trailing empty strings will be discarded.

The input "boo:and:foo", for example, yields the following results with these parameters:

Regex  Limit        Result
  : 	2 	    { "boo", "and:foo" }
  : 	5 	    { "boo", "and", "foo" }
  : 	-2 	    { "boo", "and", "foo" }
  o 	5 	    { "b", "", ":and:f", "", "" }
  o 	-2 	    { "b", "", ":and:f", "", "" }
  o 	0 	    { "b", "", ":and:f" }

Sample Use Case

For the sample use case to demonstrate the String Splitter we’ll assume a scenario where the payloads are text payloads and say we get the following format in one case <product_id>:<quantity>:<price>. In such cases we can first extract the payload to a scope variable and provide that variable as input for the String Splitter processing element. Following diagram shows first part on the sample flow. It starts with a NIO HTTP Ingress Connector and then there is the Current Payload Extractor which extracts the payload to a scope variable and then there is the String Spitter which splits the extracted payload by the given delimeter.

string splitter flow

The below diagram shows the String Splitter configuration.

string splitter conf
In this topic
In this topic
Contact Us