Wednesday, September 2, 2015

How to retrieve name of the Email Attachment


Once you have made Attachments to work (UMS Adapter - All about email attachments) in your BPEL process and able to parse them, it may be necessary to retrieve the actual name of the email attachment read. The best way to do that is using out-of-the-box function as given below

The above should return attachment; filename="test.txt"; however, nothing is as simple in this world and to make it true, it is a known BUG:19492062. Luckily, we have a patch 1941333.1 available to apply and get going but it may be time consuming to request a patch, do the impact assessment and get it applied across all environments. Whilst that may be the ideal solution in the long term but to quickly test and retrieve the attachment name you can use property Content-Type as given under.

  • ora:getAttachmentProperty() function on Content-Type returns text/plain; charset=UTF-8; name=test.txt; any additional text;
  • Substring-before() and substring-after() have been done to intelligently extract string after name=
  • emailAttachmentName- is a string type custom variable to store the attachment name

Quite simple till the patch is applied, or do we indeed need the patch now!

UMS Adapter - All about email attachments


SOA Suite -

A lot has already been written at this blog about how to configure UMS Adapter and read attachments from it. Hence this post is just to describe additional points to read/process the attachments. The post assumes that you're able to receive the incoming email using UMS Adapter successfully and able to get the BPEL process instantiated.

How to Read/Fetch the Attachment?

BPEL 1.1 - It's fairly simple in BPEL 1.1 using the following syntax in the Assign Activity.

  • Receive1_ReceiveNotification_InputVariable - is the variable created out of Receive Activity connected to Inbound UMS Adapter
  • Body, ns2:message/ns2:attachment - are the variable part and element inside the variable respectively created by default.
  • ns2:/attachment [1] is used to read the first attachment always. You may want to loop through all the attachments and choose the one you desire based on Content-Type or Attachment Name or etc. Read my another post on how to retrieve the attachment names from the Email attachments.
  • CustomAttachmentVariable - is the custom Element type variable of Attachment Message with the namespace {}message. I created this variable simply to complete the Assign. You may further access this variable for extracting the contents of the attachment or writing to file etc.

BPEL 2.0 - It's not a rocket science here as well, just one thing to note is that default BPEL 2.0 variable format ($Receive1_ReceiveNotification_InputVariable.body/ns2:attachment) (note the . between InputVariable.body ) is not supported by the ora:getAttachmentContent() function. So you have to explicitly write the variable in the BPEL 1.1 format. You can assign intially from the Design View and then go into BPEL source and modify the default Assign code generated to below: (ora:getAttachmentContent('Receive1_ReceiveNotification_InputVariable' , 'body','/ns2:message/ns2:attachment[1]')) - note the body part.


What to do with the Attachment read?

There are basically 3 things that you may want to do with the attachment just read. To keep this post concise, they have been put into separate posts.

Please feel free to navigate through and let me know if any doubts! Happy Emailing!