Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member637863
Participant
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

 
17 Comments
0 Kudos
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.
former_member637863
Participant
0 Kudos
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

 

 
0 Kudos
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.
0 Kudos
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.
0 Kudos
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.
YayatiEkbote
Contributor
0 Kudos
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
0 Kudos
Is this resolved !
YayatiEkbote
Contributor
0 Kudos
Hello harsha_122018,

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
alex_radu
Employee
Employee
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.
former_member637863
Participant
0 Kudos
hi

 

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.

 
former_member637863
Participant
0 Kudos
Thanks for sharing feedback.
former_member796657
Discoverer
0 Kudos
Thanks for the details Harsha. Can you please upload the code snippets? currently they are snapshots.
former_member796657
Discoverer
0 Kudos
Thanks for the informative blog. Can you please add code as snippets instead of snapshots ?
vinchen
Discoverer
0 Kudos
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.
alex_radu
Employee
Employee
0 Kudos
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.
scar
Employee
Employee
0 Kudos
We met 411 when try to send multipart body. If the body is plainText, then it works
0 Kudos
Thanks for posting such a wonderful and detailed blog. It really helped me.
Labels in this area