Retrieve nested values from documents on Integration Server

With a little bit of Java coding you can add powerful functionality to webMethods Integration Server. This one comes from the WxConfig NG project. There it is used to validate responses for auto-setup of environment configuration.

It is a common requirement in advanced integration scenarios to retrieve values from a data structure by specifying a path there. If you are an XML person, think of something a bit like XPath (although usually not as complex).

In Integration Server data are transported by “documents”, when you look at it from the Flow service development side. The underlying object in Java is called IData. It is very flexible and you can access it with a cursor-based API (classic) or also a map-style API (new).

Here is a simple sample structure.

				
					// Sample document strcuture:
//
// invoice (DOCUMENT)
//   |
//   +-- number (STRING)
//   +-- customer (DOCUMENT)
//      +-- name (STRING)
//      +-- comment (STRING)
//      +-- address (DOCUMENT)
//         +-- street (STRING)
//         +-- city (STRING)

				
			

If your value is on the top level of the IData structure, retrieving it is pretty easy.

				
					// Get invoice number

IDataMap invoiceMap = new IDataMap(invoice)
String invoiceNumber = invoiceMap.getAsString("number")
				
			

Likewise, as long as you are not in a dynamic context, getting nested values is not difficult.

				
					// Get customer name

IDataMap invoiceMap = new IDataMap(invoice)
IDataMap customerMap = invoiceMap.getAsIDataMap("customer");
String customerName = map.getAsString("name")
				
			

But what if you need a flexible mechanism to get arbitrary nested field? The good news is that with the IDataMap class there is no need for recursion, a simple for loop is enough.

				
					// Get arbitrary nested values

public static String getValueByPath(String path, IData input) {
	IDataMap mainMap = new IDataMap(input);
	
	// The simple case, when no nesting is needed
	if (!path.contains("/")) {
		return mainMap.getAsString(path);
	}
	
	// Here starts the part for nested values
	String[] pathParts = path.split("/");
	IData idata = mainMap.getAsIData(pathParts[0]);
	IDataMap nestedMap;
	for (int i = 1; i < pathParts.length-1; i++) {
		nestedMap = new IDataMap(idata);
		idata = nestedMap.getAsIData(pathParts[i]);
	}
	nestedMap =  new IDataMap(idata);
	return nestedMap.getAsString(pathParts[pathParts.length - 1]);
}


String invoiceNumber = getValueByPath("number", invoice);
String customerName = getValueByPath("customer/name", invoice);
String street = getValueByPath("customer/address/street", invoice);
				
			

Depending on your exact requirements you will need to add some details. But this hopefully helps to get you started.

If you want me to write about other aspects of this topic, please leave a comment or send an email to info@jahntech.com. The same applies if you want to talk how we at JahnTech can help you with your project.

© 2024-2026 by JahnTech GmbH and/or Christoph Jahn. No unauthorized use or distribution permitted.

Share:

Facebook
Twitter
Pinterest
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

On Key

Related Posts

Running MSR outside Service Designer

If you want to run the the webMethods Microservices Runtime that comes with Service Designer separately, you can do that. But the start script for Linux and macOS contains an error. It is easy to fix and here are the details.

Tips for job seekers

The IT job market is not a cozy place right now. To help people find their new job, I put together this list of recommendations. While originally targeted for webMethods, much of it is also applicable for other roles.

webMethods and AS/400

The IBM AS/400 midrange system is a fascinating piece of technology. But it does quite a few things differently than PC-based servers. So be prepared to run into a few challenges when working with it for the first time. Here is my story from a really interesting project.

How to give a presentation

Giving a presentation is vital not only in business but many situations in life. In essence it is about conveying some content in an effective way. Here are a few basic points that will help you.