on 2023 Aug 17 2:13 PM
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
Thanks for providing the code of abap client proxy and groovy script. I was able to replicate your issue.
This is the slightly modifed groovy is giving me the correct output.
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() > JDK 7
return result.toString(StandardCharsets.UTF_8.name());
}
Output :
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Muniyappan,
I have same requirement like outbound proxy to cpi with attachment. Please share the Abap side code and outbound proxy structure for attachment.
Thanks in advance @Muniyappan
Thanks.
User | Count |
---|---|
61 | |
10 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.