on 08-29-2012 4:11 PM
HI all,
I am using "Inputattachment" method from the Java API com.sap.aii.mapping.api in the mapping in a UDF.
There are some methods here which are working fine however there are some methods which are not working.
String B64 = "";
String AttachmentID = "";
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments IA = globalContainer.getInputAttachments();
OutputAttachments OA = globalContainer.getOutputAttachments();
OA = IA.copyInputAttachments();
B64 = IA.getBase64EncodedContent();
Collection<String> CollectionIDs = IA.getAllContentIds(true);
Object[] arrayObj = CollectionIDs.toArray();
int attachmentCount = arrayObj.length;
for(int i=0;i<attachmentCount;i++)
{
AttachmentID =(String) arrayObj[i];
Attachment attachments =IA.getAttachment(AttachmentID);
}
OA.setAttachment(attachments);
if(IA.areAttachmentsAvailable())
{return "true";}
else
return "false";
The above two methods are not working though they are available in the documentation of help.sap.com or maybe I am not using them with proper syntax.
My requirement is to get the attachment into this UDF via Inputattachments and use Outputattachments to send it after Encoding it into base64.
Regards,
Vkjoat
> maybe I am not using them with proper syntax.
One general suggestion. You use for loop to get attachmentID and using getAttachment method you assign attachment object. What will happen in your loop count if the attachment not available for the last attachmentID and so no attachment object attached? Why are you overwriting attachment with new values each time?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is some basic level code. You might have to customize for your needs.
GlobalContainer globalContainer = container.getGlobalContainer();
InputAttachments IA = globalContainer.getInputAttachments();
OutputAttachments OA = globalContainer.getOutputAttachments();
if(IA.areAttachmentsAvailable()) {
Collection<String> CollectionIDs = IA.getAllContentIds(true);
Object[] arrayObj = CollectionIDs.toArray();
if(arrayObj.length > 0){
String attachmentID =(String) arrayObj[0];
Attachment attachment =IA.getAttachment(attachmentID);
String base64 = attachment.getBase64EncodedContent();
String contentType = attachment.getContentType();
OA.create(attachmentID, base64.getBytes() , contentType); // if you dont want contentType then use first two arguments method.
}
}
HI Baskar,
Awesome!!
The code compiled without an Error, i had just declared AttachmentID.
I will test it and I may have to change the statistics of the thread from helpful to correct. 🙂
The whole Problem is with RNIF Adapter where the Content Transfer Encoding of attachment is expected to be Base64 by the trading partner.We are sending it as Base64via ABAP proxy, but the RNIF adapter overwrites the attachment with Content Transfer Encoding as Binary.
I have raised other discussions, we can continue discussion there if you have time.
Thanks a lot!!
Regards,
Vkjoat
HI Baskar,
I have tested syntax,
I am receiving an attachment from ECC which is binary (I can see the PDF file content in sxmb_moni).
But, while executing the method "Attachment.getBase64EncodedContent()" I am getting the following exception.
... 49 more Caused by: java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.Attachment.getBase64EncodedContent() of an object loaded from local variable '<9>' at com.sap.xi.tf._MM_TEST_ATTACHMENT_.Attachment_Modification(_MM_TEST_ATTACHMENT_.java:436) ... 54 more</Trac
does the method requires any particular format of attachment or any binary will do ?
Regards,
Vkjoat
>The File is not Based64 Encoded. In the Output I see that it is not Encoded properly
Actually we try to do as per the API recommendation. Otherwise you pass as byte content and later you can use base64 logic to encode the file content. Search online for converting string to base64 encode logic. you will see plenty of them.
>The logic which you have suggested is API or base64 encoding ?
base64 encoding. What I'm trying to tell is implement base64 encoding instead of that api method and see how that helps. Example coding as below... Call this method in output attachment data content.
>The Code doesnt recognize the Base64 variable
That means you don't have required jar file in the java mapping. Please use it. Refer this link
Looks like you need aii_utilxi_misc.jar, aii_map_api.jar
Hope that helps.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.