Skip to Content
avatar image
Former Member

Receiver file channel set to produce file in UTF-8 format but sometimes producing in ANSI and not getting updated in UNIX server.

Hi Experts,

Receiver file channel set to produce file in UTF-8 format but sometimes producing in ANSI and not getting updated in UNIX server.

Can anyone suggest how to handle this in PI?

Thanks in Advance,

Sri Gowri

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Oct 06, 2016 at 09:04 AM

    Hi Srigowri,

    • If you set the file type as binary then no conversion will be applied in the channel.
    • If the target file is text file and if you receiving the UTF-8 file to receiver channel, if you want to convert to other than UTF-8 then you can mention in File Encoding parameter in the receiver channel to convert from UTF-8 to other encoding.
    • Default is UTF-8 you no need to mention in the receiver channel to convert to UTF-8.
    • Receiver channel expecting the UTF-8 encoding if the file type as text, if it is binary then whatever the encoding it receives it will write the same encoding at target side.
    • I think in your case before coming to receiver channel the payload is not UTF-8 so you need to change the encoding before reaching receiver file adapter that means you need to it in either sender adapter or mapping level.

    Regards,

    Praveen.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Srigowri,

      As i said before receiver channel expects the payload in UTF-8 format only. it will not take any other format and change it to UTF-8.

      In your case you need to use java mapping after the message mapping to convert the encoding to UTF-8 which is mentioned in below blog.

      Handling Code page, Character encoding in SAP PI / PO

      package com.map;  
      import com.sap.aii.mapping.api.*;  
      import java.io.*;  
      public class ChangeEncoding_JavaMapping extends AbstractTransformation {  
          @Override  
          public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {  
              try {  
                  InputStream inputStream = transformationInput.getInputPayload().getInputStream();  
                  OutputStream outputStream = transformationOutput.getOutputPayload().getOutputStream();  
                  //Read input as cp1252 and write output as UTF-8.  
                  byte[] b = new byte[inputStream.available()];  
                  inputStream.read(b);  
                  String inS = new String(b, "Cp1252");  
                  outputStream.write(inS.getBytes("UTF-8"));  
              } catch (Exception ex) {  
                  getTrace().addDebugMessage(ex.getMessage());  
                  throw new StreamTransformationException(ex.toString());  
              }  
          }  
      }  
      

      Regards,

      Praveen.