MIME Multipart Encoder for handling more than one attachments
In this blog post you will learn use of MIME Multipart Encoder for attachment handling
I came across requirement where two attachment needs to be processed and send it to Ariba network. I decided to use MIME Multipart encoder but there was little information available on internet how to use it for attachment handling.
I am writing this blog post to understand behavior of Multipart encoder for attachment handling.
- Read .cxml and .pdf file from file server
- Create providerDatarequest and add pdf and cxml file as attachment and processed to Ariba network
Below pdf document help to understand processing of Incomplete or image-only invoices to Ariba network.
Page no 65 to 68 help to understand expected request format-ProviderDataRequest with image and invoice cXML attachments
I created two Iflow .
- Iflow 1- cxml file processing—it processes cxml file and save it using CPI data store
- Iflow2 – Main iflow- this iflow read pdf file and check for relevant cxml file data in data store. It creates ProviderDataRequest cxml and attach bot pdf and cxml file
File name is same for both cxml and pdf.
Main iflow to read pdf and process both pdf and cxml as attachment
Step 1-Content Modifier–Parameter Externalization
To send data to Ariba network we need to populate below fields in ProviderDatarequest .
Except ‘ FileName2’ all parameters are externalized
Step 2-Groovy Script–Create Variables
In this step variable are created to pass to main body-providerDataRequest and set as properties.
This groovy script read pdf file and add it as attachment.This groovy script set header properties for pdf attachment.
Step 4-Data store Operation-Select
This step help to read data from Datastore (Cxml file data)
Router step check if there is any data available or not.If yes then continue with next step no 5. If there is no data available then raise exception and end process.
Step 6- Content Modifier to add tag
<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE cXML SYSTEM “http://xml.cxml.org/schemas/cXML/1.2.034/InvoiceDetail.dtd”>
Step 7 – Groovy script-InvoiceDetailRequest CXML as Attachment
This groovy script add cxml data as attachment and set header for cxml file.
Step 8 – Groovy script- Create ProviderDataRequest XML
This groovy script create providerDataRequest and add url for both cxml and pdf attachment.It also set header for ProviderDataRequest.
Step 9 – MIME Multipart Encoder 1
This step add Provider data request as main body and both cxml and pdf file as attachment
Step 10– Groovy Script- Modify Content-Type
This groovy script modify content type as per expected request structure
Step 11– Content Modifier- Add Content-Type to Message
This step add Content type to main body
Step 12– Request-Reply
This step make call to Ariba network using HTTP adapter and post request.
Generic address https://service-2.ariba.com/service/transaction/cxml.asp
Step 13– Groovy script- Log Response
This step log Ariba response as attachment
Step 14– Data store-Delete
This step delete data store.
Step 15– End
Expected format of data before calling Ariba(Request-reply step) is as below.I removed pdf and cxml data and put dummy value.Check header field for main body and attachments.
MIME multipart encoder help to add attachment in expected format.
This request is successfully processed in AribaNetwork and attachments are posted.
Conclusion-If you activate trace and check payload before and after MIME multipart encoder,you will notice that attachments are added with predefined header and ——=_Part_XX_111777.111888(Boundary line)
Hope this blog post helps.
Thanks for your blog
I have one requirement,
Sender Ariba cxml payload the attachment ("cid:firstname.lastname@example.org")
document is coming in above format need to extract this content and send to base64 with third party... could you please suggest me with your inputs, that how we can extract the content.
It's very helpful.
Please check below blog to extract attachment.
You can send me details over email to understand requirement.
Body and attachment details.
Thanks a lot for your response.
I have tried with the code but couldn't able to extract the content in cxml attachment URL which is coming from Ariba system.
I will send more details in email.
The requirement is:
Ariba system sending invoice attachment in the cxml payload..that we need to transfer to non sap system.
In Ariba attachment is coming in the payload like below
This we need to extract the content and send to non sap system.
Here I am facing difficulty to extract the content in the above attachment.
The cxml payload attachment it's correct or incorrect?
Could please help me to sort this issue.
Thanks for useful information,
I had similar requirement, but in receiver http adapter I'm getting http 411 error,
I maintained all required headers and script for content length as well.
but getting same error.
I really appreciate for your help
Is this resolved !
I get same 411 error from Ariba. But if I send the message to other service, it replies me 200, do you have any idea, thanks.
I'm not sure why some folks are getting 411 err code from AN. In my test iflow I have not explicitly set a content-length header at all, and after I enabled tracing I don't see this http header set anywhere in the logs (I thought it would be calculated and added by CI but I don't see it!), yet for me this works fine.
We met 411 when try to send multipart body. If the body is plainText, then it works
We have a requirement to send Quote Request cXML with attachment to Ariba Sourcing. Now this goes through AN and we are developing iflow for QuoteRequest with Attachment. Now the attachment we are going to get from non SAP ERP system is in base64 encoded string inside a JSON payload. Do we need the data store operations in this case, as I have the attachment string already in the payload?
What I have done is, I have created XSLT mapping to generate QuoteRequest cXML. But as per cXML reference guide, attachments are taken as multipart/MIME type.
Can you guide how to develop iflow?
Also, the URL https://service.ariba.com/service/transaction/cxml.asp works only with cXML envelope.
But if attachment is also added, the structure of payload becomes like this -
Also, this cXML payload, Ariba adapter doesn't accept with the same URL.
Can you please guide on this?
I was not active last one year due to medical condition.
I did not check this on time.
is problem resolved? if yes please share solution.
It might help others.
Hello Harsha Gaonkar,
We are having similar requirement to post quote request with attachments to Ariba network. I referred to this blog and other blogs to use multipart encoder to send attachments with cXML to Ariba. Now my final payload looks like the one shared by you as output.
Could you please share HTTP receiver adapter config?
Also I read discussion - https://answers.sap.com/questions/12945137/cpi-send-attachment-to-ariba.html
In my case, message is reaching Ariba network but I am getting response as
Thanks for this blog, it helped me figure out how to add attachments to a cXML invoice and send it to Ariba Network as MIME.
Thanks for sharing feedback.
Thanks for the details Harsha. Can you please upload the code snippets? currently they are snapshots.
Thanks for the informative blog. Can you please add code as snippets instead of snapshots ?
Thanks for posting such a wonderful and detailed blog. It really helped me.