SAS Business Orchestration Services is an orchestration framework that allows you to integrate multiple systems. It enables you to implement enterprise integration patterns that make it easier to send, transform, and enrich your data as our data flows from one system to another. SAS Business Orchestration Services uses Apache Camel as its execution engine. Data are sent from one system to another in Camel is via routes. Routes are a series of steps which are performed by Camel to consume and process a message. When integrating multiple systems, data structures used by the source and target systems may not match. SAS Business Orchestration Services provides the ability to convert data types without requiring extensive and time-consuming development.
To showcase this functionality, we provide a sample route, in which a JSON file containing information about an airplane is unmarshaled to a Java Map and then converted to a Java Bean. Below is the JSON file containing the data that will be transformed in this sample.
{
"planeType" : "Boeing 737",
"tailNumber" : "N147CA",
"maxCapacity" : 215,
"landed" : true
}
The route below converts the JSON file to a Java bean via the following steps:
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:input-files"/>
<log message="${body}"/>
<unmarshal>
<json/>
</unmarshal>
<log message="${body}"/>
<to uri="sas-convert-body-to:?mapperId=JsonToBeanMapper"/>
<log message="${body}"/>
</route>
</routes>
In Line 4, the file is fetched from the “input-files” directory. Lines 6-8, unmarshals the JSON file. The default object type for unmarshaling a JSON file is a map. In line 10, the sas-convert-body-to endpoint is used to send the Map to the data type converter to be converted to a Java bean. In the route, the mapperId=JsonToBeanMapper parameter indicates that the mapper file below is the file to be used for the conversion.
The purpose of the field mapping XML file below is to provide the necessary information on what the converter is expected to do. SAS Business Orchestration Services loads up the field mapping files and configures them in the system after they are validated for errors. Then the converter processes fields in the order they are defined in the field mapping file.
<?xml version="1.0"?>
<fieldMapper xmlns="https://www.sas.com/boss/fieldMapper-10.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.sas.com/boss/fieldMapper-10.2 fieldMapper-10.2.xsd"
targetType="com.sas.integration.demo.Planes"
id="JsonToBeanMapper">
<field name="planeType">
<sourceField name="planeType"/>
</field>
<field name="tailNumber">
<sourceField name="tailNumber"/>
</field>
<field name="maxCapacity">
<sourceField name="maxCapacity"/>
</field>
<field name="landed">
<sourceField name="landed"/>
</field>
</fieldMapper>
Line 6 defines the mapper's id, to which the mapperId parameter in the JSON to Bean route refers. The target type attribute in line 5 of the mapping file provides the data type that is to be produced by the converter. In this example, the type is a Java Bean. The field element declares a field in the Java Bean that is produced by the converter. These field names correspond with the instance variables in the Planes class, which is shown below. Nested inside each field element is the sourceField element, which declares which field in the input object should be read as the source value for that field element. Each source field name corresponds with the key for some value in the Map input object. The source field and output field names are kept the same for simplicity. Since a Java bean is the target type, the converter uses an introspector to determine the field type of the instance variables in the bean, invoking the proper converters. Therefore, allowing the integer and boolean fields to be handled appropriately by the converter. For more information about the Field Mapping file, see “Working with Data Types” in SAS® Business Orchestration Services 10.2: User’s Guide.
Below is the Java class Planes:
package com.sas.integration.demo;
public class Planes {
private String planeType;
private String tailNumber;
private int maxCapacity;
private boolean landed;
public String getPlaneType() {
return planeType;
}
public void setPlaneType(String planeType) {
this.planeType = planeType;
}
public String getTailNumber() {
return tailNumber;
}
public void setTailNumber(String tailNumber) {
this.tailNumber = tailNumber;
}
public int getMaxCapacity() {
return maxCapacity;
}
public void setMaxCapacity(int maxCapacity) {
this.maxCapacity = maxCapacity;
}
public boolean getLanded() {
return landed;
}
public void setLanded(boolean landed) {
this.landed = landed;
}
@Override
public String toString(){
return "Plane Type: " + getPlaneType() + "\nTail Number: " + getTailNumber() + "\nMax Capacity: " + getMaxCapacity() +
"\nStatus: " + getLanded() ;
}
}
To conclude, SAS Business Orchestration Services allows you to seamlessly convert data from one format to another with the built-in data type converter. To do so, you must fetch your data from wherever it is stored. Then, your data must be parsed into an object then sent to the converter. The field mapping file is the blueprint, giving the converter the necessary instructions to convert your data. Then send the Java Bean to your endpoint. For additional information on SAS Business Orchestration Services and Apache Camel, consult the following resources:
SAS® Business Orchestration Services 10.2 User’s Guide
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.