Wednesday, February 14, 2024

XML Palette Activities

The XML palette provides activities for parsing XML strings into schemas and rendering schemas into XML strings

Parse XML:

Parse XML  is used when you have an XML document stored in a string or binary field. This activity produces a tree representation of the XML that can be used by following activities in the business flow.

Render XML:

Render XML activity does exactly opposite to Parse XML activity. Which means, it takes an XML tree for a specified schema and converts it to a string or binary element that contains the XML document.

Transform XML:

Transform XML is a synchronous activity that invokes the built-in XSLT processor to apply an XSLT stylesheet to an XML source document and produce a result document. Which means, Transform XML converts from XML format to another XML format.

We will see how Parse XML and Render XML works with the help of small example..


First, create a XSD  as shown below..
XSD - schema
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Students" xmlns:tns="http://www.example.org/Students" elementFormDefault="qualified">


    <element name="Students" type="tns:StudentsType"></element>
    
    <complexType name="StudentsType">
    <sequence>
    <element ref="tns:Student" minOccurs="1" maxOccurs="unbounded"></element>
    </sequence>
    </complexType>
    
    <element name="Student" type="tns:StudentType"></element>


    <complexType name="StudentType">
    <sequence>
    <element ref="tns:FirstName" minOccurs="0" maxOccurs="1"></element>
    <element ref="tns:LastName" minOccurs="0" maxOccurs="1"></element>
    <element ref="tns:RollNumber" minOccurs="0" maxOccurs="1"></element>
    </sequence>
    </complexType>
    
    <element name="FirstName" type="string"></element>

    <element name="LastName" type="string"></element>

    <element name="RollNumber" type="int"></element>
</schema>

Parse XML:
Drag and drop parse XML on canvas and configure as shown below..

Point the required XSD 
Map source data

Render XML:
Point the required XSD


Map the fields..

Test the application from Postman..

<Students xmlns="http://www.example.org/Students">
<Student>
<FirstName>Paul</FirstName>
<LastName>Pi</LastName>
<RollNumber>200</RollNumber>
</Student>
<Student>
<FirstName>George</FirstName>
<LastName>RG </LastName>
<RollNumber>9001434</RollNumber>
</Student>
</Students>

And check the output..
<?xml version="1.0" encoding="UTF-8"?>
<tns3:Student xmlns:tns3="http://www.example.org/Students"> <tns3:FirstName>Paul</tns3:FirstName> <tns3:LastName>Pi </tns3:LastName> <tns3:RollNumber>200</tns3:RollNumber> </tns3:Student>

Thanks for reading :-)

Sunday, February 11, 2024

HTTP Receiver | How to retrieve file content

Create a HTTP API and apply Basic Authentication Policy



  • Consumers will send a query parameter (filename) for which they want to retrieve the file content
  • After receiving GET request , BW application will search for the requested file in a particular directory where all files are stored
  • It will read the contents of file and send those file content back in response.

Complete Flow:


First, open HTTP palette and then select HTTP Receiver activity and paste it on canvas.
Next, specify the parameters as shown in below image.

HTTP Connector details..


Next, place a Log activity for debugging purpose. But, it's not mandatory.



Read File activity
This is important to read the content as per the file name specified. Do the file name mapping as shown below..


Log Activity


HTTP Response:
Map ReadFile response to HTTP Response ->asciiContent


Implementation and configuration is completed. Now, we need to test it from PostMan.

http://localhost:8080/filecontents?filename=emp.txt

Here, the file name is emp.txt.....



How to create an authentication policy and apply it on API

First, create a policy as shown below..


Select Policy and specify required configurations.. and click on Finish.


Then, enter user name and password..


Finally, apply this policy to HTTP Receiver activity as shown below..



That's all. It's very simple. 

Thanks for reading :-)

XML Palette Activities

The XML palette provides activities for parsing XML strings into schemas and rendering schemas into XML strings Parse XML: Parse XML  is use...