Hi All,

In one of our projects, we had a requirement to read the incoming .CSV file and pass its entire content as-is in one of the Target Structure Node.

As in normal scenario, I decided to use FCC in order to achieve this requirement. But when I started testing the scenario, I noticed that we are not able to read the Entire CSV data in one single Target field. Instead it creates a new Record of each single line in CSV file. (Whenever a Newline is encountered in Source File, it creates a new Record node; even placing some vague value for endSeparator did not help).

Thus with FCC, we were not able to achieve this.

As next steps I started to look for other alternatives. I had the option to achieve it using either XSLT mapping or using Java Mapping.

I decided to go for Java mapping over XSLT because its light weight & performance efficient.

To start With Java Mapping we have to import all the relevant jar files and also have the Local IDE – Eclipse or NWDS available for our development. Since there were some challenges in getting these we were stuck in our development, until I stumbled across this blog: Write Java Mapping directly in ESR!

written by Sunil Chandra

I decided to extend the same logic as mentioned in the blog for my case. I wrote the java logic in Message Mapping – Functions Tab under Attributes and Methods as follows:

//Following code is to read the Flat File As-Is from source into the Target Node and to map Constants to rest of the Target XML Nodes:

public void transform(TransformationInput in, TransformationOutput out)

  throws StreamTransformationException {

try {

  String source = “”; String targetxml =””; String line =””;

  InputStream ins =    in.getInputPayload().getInputStream();

  BufferedReader br = new BufferedReader( new InputStreamReader(ins));

  while ((line = br.readLine()) != null) 

  source +=line+’\n’; 

  br.close();

     String XML_START_TAG = “<?xml version=\”1.0\” encoding=\”UTF-8\”?><ns1:SendFile xmlns:ns1=\”http://test.com/\”>”;

  String XML_END_TAG = “</ns1:SendFile>”;

  targetxml = XML_START_TAG+

   “<ns1:EM>”+

   “<ns1:Security>”+

   “<ns1:CompanyName>ABC</ns1:CompanyName>”+

   “<ns1:UserId>test</ns1:UserId>” +

   “</ns1:Security>” +

   ” <ns1:Action>New</ns1:Action>” +

   “<ns1:File>” +

   “<ns1:FileContent>”+source+”</ns1:FileContent>” +

   “<ns1:FileType>CSV</ns1:FileType>” +

   “</ns1:File>” +

   “</ns1:EM>” +

  XML_END_TAG;

  out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

  }

  catch (Exception e) {   throw new StreamTransformationException(e.getMessage());  

}

//End of the code

Following are the screenshots attached for the Function Mapping and Testing in ESR:

1. Message Mapping – Functions Tab:

CSV-MM.jpg

2. ESR Testing:

CSV-1.jpg

3. ESR Testing:


CSV-2.jpg

We are able to see & verify the required output in ESR Message Mapping Testing.

Rest of the configuration remains same as we do in other scenarios. However there is one important configuration setting that needs to be taken care. Since we are not parsing the Input file (not doing conversion from CSV to XML) we need to keep the Sender SWCV empty in our Configuration Scenario, else we might end up getting error at runtime – “Content not allowed in prolog” as mentioned in the blog- The Mystery of ‘Content is not allowed in prolog’

We will use dummy Sender Interface in this case, since we are not converting the CSV file into XML structure, but passing it as-is to target.

Advantages of this approach:

1. No need to worry about getting the Jar files and having IDE in your local system.

2. No need to do FCC conversions in Configuration

3. Instantaneous testing can be done in ESR – MM test tab for your Java code

Same logic and steps can be further extended to suit other requirements as well.

This blog covers one of the possible ways to read the entire Source file data into single Node field. There are few other blogs that provides alternative solution like: Read Input Text File as a Single Field. – Process Integration – SCN Wiki

Whole Payload to a XML field – Process Integration – SCN Wiki

Hope this blog will be helpful and informative & as one of the alternatives to achieve this requirement.

Please let me know your valuable feedback and suggestions.

Regards,

Azhar


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply