cancel
Showing results for 
Search instead for 
Did you mean: 

File to File scenario to transfer a .CSV file adding a BOM using java mapping in PI.

Former Member
0 Kudos

Hi Experts,

I have a file to file scenario in which i have to pickup a ".CSV" file and transfer it as it is to another location in SAP PI 7.1 .The challenge is that i have to add a UTF-8 BOM . So, i followed the below steps :

1)Create a data type, message  for input and output  with dummy structure.

Both input and output Message type the similar structure as below.

2) Two service interfaces , one for inbound and another for outbound  as in any normal scenario.

3)Operational mapping with a java mapping class to add UTF-8 BOM

public class AddBOM  implements StreamTransformation  {

  private Map  param = null;

  private MappingTrace trace = null;

  public void execute(InputStream inStream, OutputStream outStream)

  throws StreamTransformationException {

  // TODO Auto-generated method stub

//BufferedReader to read inputStream

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

//Trace object declaration

AbstractTrace trace = null;

    trace =

    (AbstractTrace) param.get(

        StreamTransformationConstants.MAPPING_TRACE);

  String reading=null;

  StringBuffer buf=new StringBuffer();

  String CSV_content;

  try

  {

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

  {

  buf.append(reading);

  buf.append(System.getProperty("line.separator"));

  }

  CSV_content=buf.toString();

  //Character array to add UTF-8 BOM in CSV

  char[] c = {0xEF, 0xBB, 0xBF};

  for(int i=0; i<3; i++)

  {

  outStream.write(c[i]);

  }

  outStream.write(CSV_content.getBytes());

  outStream.flush();

  }

  catch (Exception e) {

  // TODO: handle exception

  trace.addDebugMessage(e.getMessage());

  }

  }

  public void setParameter(Map Param) {

  // TODO Auto-generated method stub

  if (param == null) {

         this.param = new HashMap();

     }

  }

  }

4. Created an ICO with OM implementing the above java mapping.

But, when the scenario is tested it throws me an error  "Error.com.sap.aii.adapter.xi.routing.RoutingException:Unable to parse XML message payload to extract operation for receiver determinationorg.xml.sax.SAXParseException:Content is not allowed in prolog" .

Can you experts kindly help me  to know if this adding BOM is possible only if i do FCC forming the exact XML structure and is there any possibility to add BOM using java mapping without converting using FCC as i am not doing any change between source and target .csv files except adding this BOM .

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

If you are using dummy structure and your source is not XML, always remember to clear off the SWCV for the sender interface. This ensures that the receiver determination step does not try to run the XML parser on the source data.

As you can see from the error, the parser is trying to extract the operation (by determining the name of the root element) during the receiver determination step.


"Error.com.sap.aii.adapter.xi.routing.RoutingException:Unable to parse XML message payload to extract operation for receiver determinationorg.xml.sax.SAXParseException:Content is not allowed in prolog" .

The following blogs explains this error for both classical scenarios and ICOs.

Note that your message has not reached the mapping step yet.

Former Member
0 Kudos

Hi Eng Swee Yeoh,

Thanks a lot for your reply, I did changes as you recommended and  the interface works fine now giving me the required output

stenishpeter_s
Explorer
0 Kudos

Hi Dhinesh,

Try configuring the sender service interface with "Staleless XI3.0". If you are using iflows, this method is useful since, the ICO is automatically configured.

-Sten

Answers (2)

Answers (2)

RaghuVamseedhar
Active Contributor
0 Kudos

Dhinesh,

Steps in ESR Link.

Java Mapping.


package com.map;

import com.sap.aii.mapping.api.*;

import java.io.*;

public class Transform_JavaMapping extends AbstractTransformation {

    @Override

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {

        try {

            InputStream inputstream = transformationInput.getInputPayload().getInputStream();

            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

            //Just copy Input file content to Output file content

            byte[] b = new byte[inputstream.available()];

            inputstream.read(b);

            outputstream.write('\ufeff'); //Add BOM at starting of stream.

            outputstream.write(b);

        } catch (Exception exception) {

            getTrace().addDebugMessage(exception.getMessage());

            throw new StreamTransformationException(exception.toString());

        }

    }

}

Former Member
0 Kudos

Hi Raghu,

Thanks for your reply. I think we add "\uFEFF" for UTF-16 (BE )

reference Link : Handle UTF8 file with BOM - Real's Java How-to

Muniyappan
Active Contributor
0 Kudos

Hi,

when you test the payload with operation mapping are you getting the correct output as you expected?

in the receiver determination can you select "not operation specific" and try to run the scenario?