Monday 30 July 2018

WstxUnexpectedCharException: Unexpected character in prolog; expected '<'

Are you getting this below error:

Could not generate the XML stream caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]., cause: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]

Solution:

Note: below comment on this error is not exact solution always, depend on the steps it may vary. This is one of the cause.

1. This is due to structure data mismatch to the next step.

If it is mapping step then source wsdl and the input data structure/namespace to it is different. It is expecting <xml version ........ at 1st line but that is not present. 

2.   Operation specification at header field in mapping level is  mentioned constant( instead of Create/Update etc.)



Count row/ line from csv file in SAP HCI/CPI

We had a requirement to count the lines in CSV file and return the value at end of that payload.

For this, we had written a groovy script to count the lines and return it to store in property . By that we retrieved it in the content modifier.


Code:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {
def lineNo = 0;
def lines = message.getBody(java.lang.String) as String;
    lines.eachLine {
    lineNo++} 
message.setProperty("count1",lineNo);
return message;
}

Content Modifier:

Add this in body to print the count of the lines

${property.count1}



Tuesday 3 July 2018

Collecting a field from different input structure and pass it to SuccessFactor Query

I have a requirement, where we need to pick all the personIdExternal fields from the source data (may be different structure as well) and combine all then pass it to the query at the receiver channel.

From all the values, If any of the personIdExternal value is matching at SuccessFactor need to be fetch as response.

Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.*;
import groovy.util.logging.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import org.codehaus.*;

def Message processData(Message message)
{

 def body = message.getBody(java.lang.String) as String;
 def XmlDataObject = new XmlSlurper().parseText(body)

    def xmldata = []
    def s="";
    XmlDataObject.'**'.findAll { it.name()== 'personIdExternal'}.each { a ->
    xmldata << a.text() }

//Removed duplicates

    xmldata.unique()   
    def last = xmldata.last()

//Need to find the last value to remove "or" from it

    for (i in xmldata){
     
       if (last == i){
      
          s= s.concat("(personIdExternal eq ${i}) ");
          }
       else{
             s= s.concat("(personIdExternal eq ${i}) or ");
           }
               }
    message.setBody(s);
    return message; 
    }

Output:


(personIdExternal eq 101) or (personIdExternal eq 112) or (personIdExternal eq 123) or (personIdExternal eq 144) or (personIdExternal eq 115) or (personIdExternal eq 167) or (personIdExternal eq 179) or (personIdExternal eq 189) or (personIdExternal eq 136) or (personIdExternal eq 182)


Happy Learning!!!



File Counter in FileName Implementation - SAP CPI/HCI

We have a requirement to add the sequence number at target filename. In this we need to append the counter sequence number at the end of filename.

Whenever the file is processed at CPI, the file number need to generated and appended as below.
Output_(FileName)_0001.xml
Output_(FileName)_0002.xml
Output_(FileName)_0003.xml


Main Iflow process:


 File counter logic process:



This is SOAP to SFTP scenario, whenever the data received, it triggers the Counter sub process in parallel.

Content modifier:

Add the Global variable name in Property tab to retrieve the stored value (file count) in data store. 

Note: Add the Default value to 1.
Below Body tab shows the input data send from SOAP (C4C) with retrieved value in P_OPERATION field


Mapping :

Mapping is used to add the logic of increment from the retrieved global value.
P_OPERATION field value is  5 then it adds 1 to it and output will be 6 now.


Content modifier:

Frame the file in the content modifier itself.
Read the FileCount value from the mapping step and frame it in CamelFileName expression with value: /IncidentOUT/Output_POC_${header.FileCount}.xml

/IncidentOUT   -Directory

Output_POC_${header.FileCount}.xml    - Filename

${header.FileCount}  - 6 for our case


Write Variable:

Here we update the current file sequence number into the global variable at data store.


Receiver channel:

No need to specify directory and filename in the receiver SFTP channel



Happy Learning !!!