In Oracle SOA Suite we deal with XML request and response messages. There are cases when we receive XML message and that xml message contains delimited or fixed length string. In 11g version we didn’t have any activity which converts delimited or fixed length string to XML format so we need to go for alternative solutions. However we have native format builder wizard in file/ftp adapter from where we can generate the required schema from flat file and use that schema to convert XML to Native format and vice versa.
In Oracle SOA 12c, new activity is introduced which solves our problem, with the help of this activity, we can convert Native to XML format and vice versa. All the steps remain same as we follow while we use native format builder in file/ftp adapter.
In this post, we will discuss about that activity and see how to convert from Native to XML format and vice versa using translate activity.You can find this activity under Oracle Extensions. So to add this activity, drag it to required BPEL and start configuring it.
Double click on this activity and go to translation tab. You can see two options there “Native to XML” and “XML to Native”. In Native to XML, we convert delimited string to XML format and in XML to Native; we convert XML to native format. Let’s first see how “Native to XML” works.We need to choose the input variable from where we get the delimited string, for this post we choose input variable as we pass delimited string in that variable.
Now we need to specify the schema which convert Native (delimited string) to XML format, if you already have that schema then simply browse the schema and choose the required element from that schema but if you don’t have then we need to create it using native format builder wizard. Click on second button which is there for NSXD schema and open the native format builder wizard. Specify the schema name and schema directory, also choose the type of Native format, here we choose delimited as we get the data in delimited format.
Now we need to specify the file which contain sample native format i.e. sample file which contain at-least one sample delimited record. If you don’t have that file, create it first and add one sample row in that. There are different options available; you can choose that as per your requirement. We also need to specify the types of record present in the file, in our case we can have multiple records in one file which are of same type so we choose that option, once done click on next. Now we need to specify schema root element and other element name, you can also edit the schema namespace.
Specify al required delimiters; we need to specify record delimiter and field delimiter. We use Complex lookAhead Record processing when we deal with COBOL file so we need not to set this fields for now. Once done, click on next, now we need to specify the field properties, these properties are nothing but schema elements name, by default this wizard shows C1, C2, etc names for fields but we can change it as per our requirement. For our use case we changed it to meaningful names.
Once you are done with above steps, your Translate activity should look like below. You can see schema already generated for you and that schema has all required elements. In the translate activity, you can see we need to specify output variable also. If you already have output variable which is based on above generated then you can use that otherwise you need to create a new output variable.
Now let’s test it, before we test it deploy it to the server, open the em console, go to the composite and click on test. This should open the request message window; provide delimited string which we need to convert to XML. As you can see in below screen shot, delimited string got converted to XML.
If we need to convert XML to Native format then we needs to provide the input variable from where we receive XML input which gets converted to native format. Choose schema if you already have or follow above steps to generate schema using native format builder. In this case output will be string so create output variable as string type. Once complete, your activity should look like below. Now deploy your composite and test it. In the output you see response in native format.