cancel
Showing results for 
Search instead for 
Did you mean: 

Outbound proxy attachment to CPI Encoding Problem

dan166
Discoverer
0 Kudos

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.

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, even German umlaute like <POTX1>äöüÄÖÜ</POTX1>.

In the CPI/IS, I have a groovy script based on Morten Wittrocks 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 German umlaute are showing up as <POTX1>äöüÄÖÜ</POTX1> now.

Did anybody experience a similar issue and solved it or has an idea how this could be handled to show those characters correctly?

Thanks in advance for the feedback,

Daniel

View Entire Topic
Muniyappan
Active Contributor
0 Kudos

Hi Daniel,

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.

Could you please pass on the abap report code wich uploads the files? what is the code page are you using?

Also please share us the groovy script you are using to read the attachment.

dan166
Discoverer

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:

form xml_processing.

data:
l_rc type i,
li_files type filetable,
l_action type i,
l_filesize type w3param-cont_len,
l_filetype type w3param-cont_type,
li_bin_data type w3mimetabtype,
l_xml_data type string.

data:
lcl_file type ref to zbc_co_file_out,
lcl_attachment_protocol type ref to if_wsprotocol_attachments,
lcl_attachment type ref to if_ai_attachment,
lcl_attachments type prx_attach,
ls_output type zbc_mt_file_out_request,
ls_record type zbc_dt_file_out_request.

try.

"call file open dialog
cl_gui_frontend_services=>file_open_dialog(
exporting
file_filter = |xml (*.xml)\|*.xml\|{ cl_gui_frontend_services=>filetype_all }|
multiselection = abap_false
changing
file_table = li_files
rc = l_rc
user_action = l_action ).

if l_action = cl_gui_frontend_services=>action_ok.
if lines( li_files ) > 0. "file entries selected

"call binary file upload
cl_gui_frontend_services=>gui_upload(
exporting
filename = |{ li_files[ 1 ]-filename }|
filetype = 'BIN'
importing
filelength = l_filesize
changing
data_tab = li_bin_data ).

"Convert uploaded data to string
call function 'SCMS_BINARY_TO_STRING'
exporting
input_length = l_filesize
importing
text_buffer = l_xml_data
tables
binary_tab = li_bin_data
exceptions
failed = 1
others = 2.
if sy-subrc <> 0.
message i219 with '<StringConversion>'.
exit.
endif.

endif.
endif.

catch cx_root into data(e_text).
message e_text->get_text( ) type 'S' display like 'E'.

endtry.

if lines( li_files ) = 0. "file entries selected
message i074.
exit.
endif.

"create client proxy object by passing logical port
try.
create object lcl_file exporting logical_port_name = space.
catch cx_ai_system_fault.
endtry.

* send pdf attachment xstring in request
lcl_attachment_protocol ?= lcl_file->get_protocol( if_wsprotocol=>attachments ).

"pdf mime type
lcl_attachment = lcl_attachment_protocol->get_attachment_from_text(
data = l_xml_data
type = if_ai_attachment=>c_mimetype_text_xml
name = 'File_Attachment' ).
append lcl_attachment to lcl_attachments.
lcl_attachment_protocol->set_attachments( lcl_attachments ).

* pass data in request field
ls_record-name = li_files[ 1 ]-filename.
ls_output-mt_file_out_request = ls_record.

* call proxy
if lcl_file is bound.
try.
call method lcl_file->execute
exporting
output = ls_output.
commit work.
catch cx_ai_system_fault.
endtry.
endif.

message i048. "success

endform.

The groovy script that retrieves the attachment and puts it into the body (and the MPL) is as following:

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;
}
Muniyappan
Active Contributor
0 Kudos

thanks for that.