on 05-24-2012 1:00 PM
Hi there,
I have a requirement in which I need to read the email attachment which I am able to but inside the attachment I have couple of German characters which is not displaying correctly because of encoding.
I am using UDF to read the email Content and when I check the ABAP stack it is showing
MailMessage (text/xml;charset = utf-8)
MailAttachment-1 (application/octet-stream;name="abcdedg"
XML file which is coming as an attachment contains this
<STRAS>Eisenhüttenstr. 99</STRAS>
But after when the file comes to PI it will become
<STRAS>Eisenhüttenstr. 99</STRAS>
I have tried all the Content Encoding in Sender Mail adapter but nothing works.
Can anybody please tell me how to solve this problem.
Thanks,
Iqbal
Hi Iqbal,
The Attachment Java class that you are most probably using in the UDF to read the attachment content contains a method getContentType() that will help you determine the charset used. You could also read the charset from the attachment payload, as it should be starting with:
<?xml version="1.0" encoding="SOME_ENCODING"/?>
Then you can generate the UDF output with:
String output = new String(attachment.getBytes("ISO-8859-1"), "UTF-8");
return output;
Where attachment is some string variable containing the attachment payload.
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gzegorz,
Here is what I am doing to read the attachement
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments inputAttachments = globalContainer.getInputAttachments();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment attachments =inputAttachments.getAttachment(attachmentID);
Attachment attach = outputAttachments.create(attachmentID, "application/xml;charset=utf-8", attachments.getContent());
attachmentContent = new String(attach.getContent());
result.addValue(attachmentContent);
Can you please suggest what changes I do in this code to change the email attachment encoding from MailAttachment-1 (application/octet-stream;name="abcdedg" to MailAttachment-1 (application/xml;name=abcbdef"
Thanks
Try the following:
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments inputAttachments = globalContainer.getInputAttachments();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment attachments =inputAttachments.getAttachment(attachmentID);
String attachmentContent = new String(attach.getContent());
String converted = new String(attachmentContent.getBytes("ISO-8859-1"), "UTF-8");
Attachment attach = outputAttachments.create(attachmentID, "application/xml;charset=utf-8", converted);
result.addValue(attachmentContent);
Regards,
Greg
Hi Greg,
Thank you so much for your help.
I am still getting an error
Can you please check the code.
Ok, here is a little correction:
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments inputAttachments = globalContainer.getInputAttachments();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment attachments =inputAttachments.getAttachment(attachmentID);
String attachmentContent = new String(attach.getContent());
Attachment attach = outputAttachments.create(attachmentID, "application/xml;charset=utf-8", attachmentContent.getBytes("UTF-8"));
result.addValue(attachmentContent);
Regards,
Greg
Hi Greg,
Still issues
I don't think so getBytes Method in avaliable in the InputAttachment
Here are the Methods
Method Summary | |
---|---|
boolean | equals(Object object) Compare attachments. |
String | getBase64EncodedContent() Return the actual content of the attachment as Base64-encoded String. |
byte[] | getContent() Return the actual content of the attachment as byte array. |
String | getContentId() Get the identifier of the attachment. |
String | getContentType() Get the type of the attachment. |
int | hashCode() Uses the content IDs hashCode. |
String | toString() |
Now I am getting this error
Can you please suggest what else can be done to solve this problem.
I really appreciate all your help.
Message was edited by: Muhammad iqbal
Dear Iqbal,
Check that attachmentContent is of type String and String has the getBytes method. Still, there is one more issue with the code: I've forgotten that catching exceptions is mandatory in Java (got used to ABAP so much ). So simply replace:
Attachment attach = outputAttachments.create(attachmentID, "application/xml;charset=utf-8", attachmentContent.getBytes("UTF-8"));
with:
try {
Attachment attach = outputAttachments.create(attachmentID, "application/xml;charset=utf-8", attachmentContent.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) { }
You can also add some exception handling after the catch block if required.
Regards,
Greg
Hi Greg,
Once again thanks for your help.
At last Code is working fine but I am still facing the same issue
Final Code
Attachment attachments =inputAttachments.getAttachment(attachmentID);
String attachmentContent = new String(attachments.getContent());
try {
Attachment attach = outputAttachments.create(attachmentID, "application/xml;charset=utf-8", attachmentContent.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) { }
result.addValue(attachmentContent);
ABAP Stack It is still showing the MailAttachment as
MailMessage (text/xml;charset = utf-8)
MailAttachment-1 (application/octet-stream;name="abcdedg"
Don't you think we need to display attach in the result.addValue because it has the correct encoding
Any other suggestion?
Hi Baskar,
Yes it's the same problem.
I open the file in the notepad++ editor and check the encoding and it is showing ANSI and when I change this to UTF-8 then that character will appear in it's correct form.
My Scenario is Email Attachment ---> PI ----> iDoc
Please suggest if anything else can be done to resolve this problem either JAVA Mapping or XSLT Mapping.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.