Skip to Content
Technical Articles
Author's profile photo Harsha Gaonkar

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.

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-service.pdf

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

 

Assigned tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rishabh Sharma
      Rishabh Sharma

      Hi Harshalata,

      Thanks for your blog  

      I have one requirement, 

      Here,

      Sender Ariba cxml payload the attachment ("cid:1735239107.1592222922946@cxml.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.

      Thank you.

      Author's profile photo Harsha Gaonkar
      Harsha Gaonkar
      Blog Post Author

      Hi Rishabh,

      Please check below blog to extract attachment.

      https://blogs.sap.com/2017/02/19/replacing-the-message-body-with-an-attachment/

      You can send me details over email to understand requirement.

      Body and attachment details.

      Thanks

      Harsha

       

       

      Author's profile photo Rishabh Sharma
      Rishabh Sharma

      Hi Harshalata,

       

      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.

      Thanks.

      Author's profile photo Rishabh Sharma
      Rishabh Sharma

      Hi Harshalatha,

      The requirement is:

      Ariba system sending invoice attachment in the cxml payload..that we need to transfer to non sap system.

      Here 

      In Ariba attachment is coming in the payload like below

      <Attachment>

      <URL>cid:1735239107.1592222922946@cxml.org</URL>

      </Attachment>

       

      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.

      Or

      The cxml payload attachment it's correct or incorrect?

      Could please help me to sort this issue.

       

      Thank you.

      Author's profile photo Rishabh Sharma
      Rishabh Sharma

      Hi Harsha,

      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

      Thank you.

      Author's profile photo Rajavadivel Panneerselvam
      Rajavadivel Panneerselvam

      Is this resolved !

      Author's profile photo Yayati Ekbote
      Yayati Ekbote

      Hello Harsha,

       

      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 -

      <n0:cXMLMessage xmlns:n0="http://sap.com/xi/Ariba/Interfaces">
       <cXMLMessageContent messageType="QuoteRequest">
         <cXML>
         </cXML>
      <cXMLFolder charset="String 4" contentID="String 3">
         <cXML>anyType 5</cXML>
      </cXMLFolder>
      <AttachmentFolder charset="String 17" contentID="String 14" contentLength="18" fileName="String 16" contentType="String 15">
      <Content>base64encoded string</Content>
      </AttachmentFolder>
      </cXMLMessageContent>
      </n0:cXMLMessage>

       

      Also, this cXML payload, Ariba adapter doesn't accept with the same URL.

       

      Can you please guide on this?

       

      Regards,

      Yayati

      Author's profile photo Yayati Ekbote
      Yayati Ekbote

      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

      <Response>
      
      		<Status code="406" text="Not Acceptable">The document could not be parsed: Content is not allowed in prolog.
      			(line 1, column 1) [ANCLS-125004012]</Status>
      
      	</Response>
      Regards,
      Yayati