Monday, October 5, 2015

Forward (Email) the received Attachment via UMS Adapter


Note : This post assumes that you already have some working knowledge of BPEL and XSLT functions and you're able to retrieve the content of Email attachment as described in my previous post - UMS Adapter - All about email attachments.

There may be cases when you have received an email attachment via UMS Adapter and you want to forward the same email as-is to another recipient e.g. if received attachment is invalid then forward to same to support team for further diagnosis. Following instructions show how you can achieve the same.

  • Drag and Drop another UMS Adapter (because the one you may have already was used to originally receive the Email) onto the right swimlane and select Outbound Send Notification in the Operation Type . Also check Receive Message Id as Reply . Click Next.
  • On the next screen choose Type of notification = Email and assign appropriate Subject and To Email ID. You can leave From as blank. Click Next.
  • Choose Message is of String type . Click Next and Finish.
  • Now drag and Drop an Invoke activity and connect to the UMS Adapter which will allow to create Input/Output variables e.g. InvokeSendErrorNotification_InputVariable and InvokeSendErrorNotification_OutputVariable
  • Now drag another Assign activity and place it just before the Invoke just created.
  • Assign relevant text for payload string to InvokeSendErrorNotification_InputVariable > body > message > payload . You can also use html formatted text if you wish in the payload.
  • Not navigate to InvokeSendErrorNotification_InputVariable > body > message > attachment > href and assign the incoming attachment href variable (ReceiveEmail_InputVariable). This variable was created as part of Receive activity when we configured previous UMS Adapter to receive the incoming email and attachment. Click OK and that's it.

The code for Assign activity is shown below for guidance.

  • First from expression - the payload that you want to appear as the email message. This is html formatted just to show how you can use html formatted tags.
  • InvokeSendErrorNotification_InputVariable.body/ns7:payload - Input variable created as new UMS Adapter. We're assigning into payload element of the same.
  • $ReceiveEmail_InputVariable.body/ns2:attachment[1]/@href - variable created from previous UMS Adapter to receve the attachment. [1] is used to refer to the first attachment in the email in case received email has multiple attachments.
  • $InvokeSendErrorNotification_InputVariable.body/ns7:attachment/@href - the variable created as part of new UMS Adapter. We're referring to the @href here which contains the reference to the attachment.

Happy Learning and let me know if any doubts!

Parse and Read the contents of Email Attachment in the BPEL process


This post assumes that you already have some working knowledge of BPEL and XSLT functions and you're able to retrieve the content of Email attachment as described in my previous post - UMS Adapter - All about email attachments.

Many a times the requirement is to parse through the content of the attachment to extract desired information out of it. As attachment read is in the base64 binary data by default, first and foremost thing is to convert it into String and then parse it into the required XSD schema. Oracle provides a function Out-of-the-box (OOTB )to do both the bits in one call. Follow below steps to parse the incoming attachment.

The simple case I have taken here is that I receive a CSV file as attachment in email and I parse it into XML for further transformations on the content.

  • Create a schema of the email attachment that you want to parse using Native Schema builder. Basically that means dragging and dropping a File Adapter and create a schema with that, later cancel or delete the adapter as we only need the schema so crated. I receive a comma delimited file as attachment, hence used a delimited option to create my schema but you can also parse XML, Fixed Length any other type of file. In case of XML files, please pay attention to the XML file namespace and the target Schema namespace .
  • Create a variable targetMessage of the schema created above (shown below in Examples)
  • Use the OOTB function ora:doTranslateFromNative(Input Message in binary format, Relative path to the schema from composite directory, Schema Root Element Name, 'DOM' ) as shown below
  • The first assign is to fetch the Attachment Content into another Custom variable of the same type
  • $targetMessage - is the Element Type variable of the target schema (Root element TargetRequest) which will hold the translated message
  • Once the targetMessage is formed, you can traverse through all elements of this message and carry out all desired transformation operations on this like any other XML variable.

Below shown is the structure of file and the associated code, although not full but should give an idea of the main components involved.

Example Email Attachment format :

Example Schema :

Variable Created in BPEL:

Please let me know if any issues and I'll try to help! Happy Emails!