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.
Scenario
- 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.
https://www.ariba.com/ja-jp/-/media/aribacom/assets/pdf-assets/archive/ariba-invoice-conversion-serv...
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.
Find below screenshot for Iflow1.
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.
Step 3-Groovy script-- PDF_Attach
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 5-Filter
Filter remove extra tag from data
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">
${in.body}
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
Content-Type: ${property.lv_cont_typ}
${in.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
Harshalata