Thursday, 9 August 2018

Write XML file using Oracle Integration Cloud FTP adapter

In the previous article, we have showcased how to READ XML files using FTP adapter. This article will show how to create XML files using FTP adapter.

Important Blogs to learn more about Oracle ICS / OIC


Use Case: Expose a REST API which will write XML file on FTP location

Post this blog, below XML file will be created on FTP location

<?xml version="1.0" encoding="UTF-8" ?>
<employees>
   <employee>
      <name>ankur</name>
      <skills>ICS</skills>
   </employee>
   <employee>
      <name>jain</name>
      <skills>java</skills>
   </employee>
</employees>

Let's see how to achieve this use case
  • Create a FTP connection: Please go through the article to see how to create FTP connection
  • Create a REST connection. Please go through the article to see how to create REST connection
  • Open the Integrations tab and click on Create button

  • Select Map Data Pattern
  • Enter Below information and click on Create button
    • Enter Integration Name in What do you want to call your integration text box
    • An Identifier would be picked up automatically from Integration name however you can edit it
    • Let the Version as it is
    • Enter the description in What does this integration do box
    • Leave the package box as it is
  • Drag REST connection on the Integration canvas as a Trigger point
  • Enter below information and Click Next
    • Name of the end point: WriteXML
    • Relative URI(must start with /): /create
    • Select HTTP verb: POST
    • Select Configure a request payload for this endpoint checkbox- This option allows us to assign payload in the next step
  • Select JSON Sample Radio button: This option allows us to take input in json format. Select inline link to give sample payload and enter below payload
{
                "employee": [{
                                                "name": "ankur",
                                                "skills": "ICS"
                                },
                                {
                                                "name": "Anil",
                                                "skills": "Java"
                                }
                ]
}

  • Click Done button in the Next Screen
  • Drop FTP connection as a Invoke Activity
  • Enter below information and Click Next button
    • What do you want to call your end point: CreateXML
    • Do you want to define a schema for this endpoint: Yes
    • Do you want to create a new schema or select an existing one: Select an existing schema from the file system
    • Do you want to enable PGP security: No
  • Enter below information and Click Next button
    • Select a Transfer mode: ASCII
    • Specify an Output Directory: Enter directory which will be used to write file
    • Specify a File Name Pattern: employee.xml

  • Save below xsd in file and browse
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="employees">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="employee" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="name"/>
              <xs:element type="xs:string" name="skills"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

  • Click Done on next screen
  • Click on the Mapper
  • Map Source and Target element
  • Just save the integration and Activate. Once the integration will be activated, a endpoint will be shown on the page
  • Open POSTMAN and hit the REST point endpoint with below payload
{
   "employee":[
      {
         "name":"ankur",
         "skills":"ICS"
      },
      {
         "name":"jain",
         "skills":"java"
      }
   ]
}

  • Open the FTP location and see the employee.xml should be created

No comments:

Post a Comment