<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Outbound proxy attachment to CPI Encoding Problem in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745460#M4783797</link>
    <description>&lt;P&gt;Hi Muni&lt;/P&gt;&lt;P&gt;Fantastic, thanks for your solution which also works great on my end! Being an UTF-16 issue seems plausible, nevertheless getting the defaultCharset in the script returns UTF-8 and not 16. Anyhow, I'll play around a bit more but very much appreciate your solution.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
    <pubDate>Mon, 21 Aug 2023 15:03:49 GMT</pubDate>
    <dc:creator>dan166</dc:creator>
    <dc:date>2023-08-21T15:03:49Z</dc:date>
    <item>
      <title>Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaq-p/12745453</link>
      <description>&lt;P&gt;I am working on a scenario where I want to upload an XML file in ABAP and send it as an attachment through an outbound proxy to the CPI/IS for further processing.&lt;/P&gt;
  &lt;P&gt;As a PoC, I am uploading an XML file from the frontend and attaching it to the proxy as string using the corresponding attachment classes and methods. This generally works fine and in SXMB_MONI I see the attachment correctly presented, &lt;STRONG&gt;even German umlaute like &lt;/STRONG&gt;&lt;STRONG&gt;&amp;lt;POTX1&amp;gt;äöüÄÖÜ&lt;/STRONG&gt;&lt;STRONG&gt;&amp;lt;/POTX1&amp;gt;&lt;/STRONG&gt;.&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2197724-2023-08-17-15-04-34.png" /&gt;&lt;/P&gt;
  &lt;P&gt;In the CPI/IS, I have a groovy script based on &lt;A href="https://blogs.sap.com/2017/02/19/replacing-the-message-body-with-an-attachment/"&gt;Morten Wittrocks&lt;/A&gt; blog that retrieves the attachment from the proxy message and puts it into the message body for further processing. Everything looks fine, except that the &lt;STRONG&gt;German umlaute are showing up as &amp;lt;POTX1&amp;gt;Ã¤Ã¶Ã¼Ã&amp;#132;Ã&amp;#150;Ã&amp;#156;&amp;lt;/POTX1&amp;gt;&lt;/STRONG&gt; now.&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2197725-2023-08-17-15-08-36.png" /&gt;&lt;/P&gt;
  &lt;P&gt;Did anybody experience a similar issue and solved it or has an idea how this could be handled to show those characters correctly?&lt;/P&gt;
  &lt;P&gt;Thanks in advance for the feedback,&lt;/P&gt;
  &lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 13:13:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaq-p/12745453</guid>
      <dc:creator>dan166</dc:creator>
      <dc:date>2023-08-17T13:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745454#M4783791</link>
      <description>&lt;P&gt;For those western Europe characters (e.g. German umlauts, French accented characters) try using ISO8859-1 (Latin-1) encoding specified in front of the root element (sample) to prevent a parsing error 201&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0" encoding="ISO8859-1"?&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Aug 2023 13:47:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745454#M4783791</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2023-08-17T13:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745455#M4783792</link>
      <description>&lt;P&gt;Thank you Raymond for your suggestion. Unfortunately, this doesn't make it any better&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2197732-2023-08-17-16-39-10.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:42:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745455#M4783792</guid>
      <dc:creator>dan166</dc:creator>
      <dc:date>2023-08-17T14:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745456#M4783793</link>
      <description>&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;It could be that when you upload a file you are using different encoding and when you read in cpi, you are using different encoding. &lt;/P&gt;&lt;P&gt;Could you please pass on the abap report code wich uploads the files? what is the code page are you using?&lt;/P&gt;&lt;P&gt;Also please share us the groovy script you are using to read the attachment. &lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 21:22:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745456#M4783793</guid>
      <dc:creator>Muniyappan</dc:creator>
      <dc:date>2023-08-17T21:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745457#M4783794</link>
      <description>&lt;P&gt;Hi Muni, thanks for your feedback. I am not specifically defining any codepage anywhere. I am just wondering why it shows correctly in SXMB_MONI but not in the CPI. The ABAP code reading the file and sending it through the proxy is as following:&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;form xml_processing.&lt;BR /&gt;&lt;BR /&gt;  data:&lt;BR /&gt;    l_rc        type i,&lt;BR /&gt;    li_files    type filetable,&lt;BR /&gt;    l_action    type i,&lt;BR /&gt;    l_filesize  type w3param-cont_len,&lt;BR /&gt;    l_filetype  type w3param-cont_type,&lt;BR /&gt;    li_bin_data type w3mimetabtype,&lt;BR /&gt;    l_xml_data  type string.&lt;BR /&gt;&lt;BR /&gt;  data:&lt;BR /&gt;    lcl_file                type ref to zbc_co_file_out,&lt;BR /&gt;    lcl_attachment_protocol type ref to if_wsprotocol_attachments,&lt;BR /&gt;    lcl_attachment          type ref to if_ai_attachment,&lt;BR /&gt;    lcl_attachments         type prx_attach,&lt;BR /&gt;    ls_output               type zbc_mt_file_out_request,&lt;BR /&gt;    ls_record               type zbc_dt_file_out_request.&lt;BR /&gt;&lt;BR /&gt;  try.&lt;BR /&gt;&lt;BR /&gt;      "call file open dialog&lt;BR /&gt;      cl_gui_frontend_services=&amp;gt;file_open_dialog(&lt;BR /&gt;        exporting&lt;BR /&gt;          file_filter = |xml (*.xml)\|*.xml\|{ cl_gui_frontend_services=&amp;gt;filetype_all }|&lt;BR /&gt;                        multiselection = abap_false&lt;BR /&gt;        changing&lt;BR /&gt;          file_table  = li_files&lt;BR /&gt;          rc          = l_rc&lt;BR /&gt;          user_action = l_action ).&lt;BR /&gt;&lt;BR /&gt;      if l_action = cl_gui_frontend_services=&amp;gt;action_ok.&lt;BR /&gt;        if lines( li_files ) &amp;gt; 0. "file entries selected&lt;BR /&gt;&lt;BR /&gt;          "call binary file upload&lt;BR /&gt;          cl_gui_frontend_services=&amp;gt;gui_upload(&lt;BR /&gt;            exporting&lt;BR /&gt;              filename   = |{ li_files[ 1 ]-filename }|&lt;BR /&gt;              filetype   = 'BIN'&lt;BR /&gt;            importing&lt;BR /&gt;              filelength = l_filesize&lt;BR /&gt;            changing&lt;BR /&gt;              data_tab   = li_bin_data ).&lt;BR /&gt;&lt;BR /&gt;          "Convert uploaded data to string&lt;BR /&gt;          call function 'SCMS_BINARY_TO_STRING'&lt;BR /&gt;            exporting&lt;BR /&gt;              input_length = l_filesize&lt;BR /&gt;            importing&lt;BR /&gt;              text_buffer  = l_xml_data&lt;BR /&gt;            tables&lt;BR /&gt;              binary_tab   = li_bin_data&lt;BR /&gt;            exceptions&lt;BR /&gt;              failed       = 1&lt;BR /&gt;              others       = 2.&lt;BR /&gt;          if sy-subrc &amp;lt;&amp;gt; 0.&lt;BR /&gt;            message i219 with '&amp;lt;StringConversion&amp;gt;'.&lt;BR /&gt;            exit.&lt;BR /&gt;          endif.&lt;BR /&gt;&lt;BR /&gt;        endif.&lt;BR /&gt;      endif.&lt;BR /&gt;&lt;BR /&gt;    catch cx_root into data(e_text).&lt;BR /&gt;      message e_text-&amp;gt;get_text( ) type 'S' display like 'E'.&lt;BR /&gt;&lt;BR /&gt;  endtry.&lt;BR /&gt;&lt;BR /&gt;  if lines( li_files ) = 0. "file entries selected&lt;BR /&gt;    message i074.&lt;BR /&gt;    exit.&lt;BR /&gt;  endif.&lt;BR /&gt;&lt;BR /&gt;  "create client proxy object by passing logical port&lt;BR /&gt;  try.&lt;BR /&gt;      create object lcl_file exporting logical_port_name = space.&lt;BR /&gt;    catch cx_ai_system_fault.&lt;BR /&gt;  endtry.&lt;BR /&gt;&lt;BR /&gt;* send pdf attachment xstring in request&lt;BR /&gt;  lcl_attachment_protocol ?= lcl_file-&amp;gt;get_protocol( if_wsprotocol=&amp;gt;attachments ).&lt;BR /&gt;&lt;BR /&gt;  "pdf mime type&lt;BR /&gt;  lcl_attachment = lcl_attachment_protocol-&amp;gt;get_attachment_from_text(&lt;BR /&gt;                     data = l_xml_data&lt;BR /&gt;                     type = if_ai_attachment=&amp;gt;c_mimetype_text_xml&lt;BR /&gt;                     name = 'File_Attachment' ).&lt;BR /&gt;  append lcl_attachment to lcl_attachments.&lt;BR /&gt;  lcl_attachment_protocol-&amp;gt;set_attachments( lcl_attachments ).&lt;BR /&gt;&lt;BR /&gt;* pass data in request field&lt;BR /&gt;  ls_record-name = li_files[ 1 ]-filename.&lt;BR /&gt;  ls_output-mt_file_out_request = ls_record.&lt;BR /&gt;&lt;BR /&gt;* call proxy&lt;BR /&gt;  if lcl_file is bound.&lt;BR /&gt;    try.&lt;BR /&gt;        call method lcl_file-&amp;gt;execute&lt;BR /&gt;          exporting&lt;BR /&gt;            output = ls_output.&lt;BR /&gt;        commit work.&lt;BR /&gt;      catch cx_ai_system_fault.&lt;BR /&gt;    endtry.&lt;BR /&gt;  endif.&lt;BR /&gt;&lt;BR /&gt;  message i048. "success&lt;BR /&gt;&lt;BR /&gt;endform.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The groovy script that retrieves the attachment and puts it into the body (and the MPL) is as following:&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
      
    //get attachment
    def attach = message.getAttachments();
    def datahandler = attach.values()[0];
    def content =  datahandler.getContent();
  
    // Read from properties to get an attachment name
    def mapProperties = message.getProperties();
    def attachmentName = mapProperties.get("AttachmentName");
    def attachmentType = mapProperties.get("AttachmentType");
    // Set default values
	if (!attachmentName?.trim()) {
	    attachmentName = "Attachment";
	}
	if (!attachmentType?.trim()) {
	    attachmentType = "text/plain";
	}

    def messageLog = messageLogFactory.getMessageLog(message);
    if(messageLog != null){
        messageLog.setStringProperty("Logging", "Payload As Attachment");
        messageLog.addAttachmentAsString(attachmentName, content, attachmentType);
    }
    message.setBody(content);
    return message;
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 08:13:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745457#M4783794</guid>
      <dc:creator>dan166</dc:creator>
      <dc:date>2023-08-18T08:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745458#M4783795</link>
      <description>&lt;P&gt;Thanks for providing the code of abap client proxy and groovy script. I was able to replicate your issue. &lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2200769-screenshot-2023-08-18-at-200952.png" /&gt;&lt;/P&gt;&lt;P&gt;This is the slightly modifed groovy is giving me the correct output. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

def Message processData(Message message) {
      
    //get attachment
    def attach = message.getAttachments();
    def datahandler = attach.values()[0];
    def content =  datahandler.	getInputStream();
 
     def content_string = getString(content)
  
    // Read from properties to get an attachment name
    def mapProperties = message.getProperties();
    def attachmentName = mapProperties.get("AttachmentName");
    def attachmentType = mapProperties.get("AttachmentType");
    // Set default values
	if (!attachmentName?.trim()) {
	    attachmentName = "Attachment";
	}
	if (!attachmentType?.trim()) {
	    attachmentType = "text/plain";
	}

    def messageLog = messageLogFactory.getMessageLog(message);
    if(messageLog != null){
        messageLog.setStringProperty("Logging", "Payload As Attachment");
        messageLog.addAttachmentAsString(attachmentName, content_string, attachmentType);
    }
    message.setBody(content);
    return message;
}

def String getString(def inputStream){
     ByteArrayOutputStream result = new ByteArrayOutputStream();
 byte[] buffer = new byte[1024];
 for (int length; (length = inputStream.read(buffer)) != -1; ) {
     result.write(buffer, 0, length);
 }
 // StandardCharsets.UTF_8.name() &amp;gt; JDK 7
 return result.toString(StandardCharsets.UTF_8.name());

}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output :&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2200768-screenshot-2023-08-18-at-201010.png" /&gt;&lt;/P&gt;&lt;P&gt;the issue you are facing could be due to java 8 is using utf-16 as default encoding. I might be wrong here. But feel free to correct me. &lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 18:19:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745458#M4783795</guid>
      <dc:creator>Muniyappan</dc:creator>
      <dc:date>2023-08-18T18:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745459#M4783796</link>
      <description>&lt;P&gt;thanks for that.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 19:28:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745459#M4783796</guid>
      <dc:creator>Muniyappan</dc:creator>
      <dc:date>2023-08-18T19:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745460#M4783797</link>
      <description>&lt;P&gt;Hi Muni&lt;/P&gt;&lt;P&gt;Fantastic, thanks for your solution which also works great on my end! Being an UTF-16 issue seems plausible, nevertheless getting the defaultCharset in the script returns UTF-8 and not 16. Anyhow, I'll play around a bit more but very much appreciate your solution.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2023 15:03:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/12745460#M4783797</guid>
      <dc:creator>dan166</dc:creator>
      <dc:date>2023-08-21T15:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Outbound proxy attachment to CPI Encoding Problem</title>
      <link>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/13705244#M4829810</link>
      <description>&lt;P&gt;Hi Muniyappan,&lt;/P&gt;&lt;P&gt;I have same requirement like outbound proxy to cpi with attachment. Please share the Abap side code and outbound proxy structure for attachment.&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/163801"&gt;@Muniyappan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 19:17:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/outbound-proxy-attachment-to-cpi-encoding-problem/qaa-p/13705244#M4829810</guid>
      <dc:creator>SrikanthR-P</dc:creator>
      <dc:date>2024-05-17T19:17:32Z</dc:date>
    </item>
  </channel>
</rss>

