Friday, February 8, 2013

Send XML file as attachment using Email activity in SOA / BPEL 11g

Few days back I got requirement of sending email with attachments. 

The catchy part of it is sending an XML file as attachment. Thought of sharing the solution.

Steps are:
(Version of J-Dev used is

1. Create a BPEL project. 
2. Modify input schema element 'process' to have 'To' and 'AttachmentBody' as string type elements. 
3. Insert a Email Activity inside BPEL.
4. Double Click on the Email activity and set / pass values to required fields. 

5. Create a Temp variable say 'EncodedTemp' and copy 'AttachmentBody' to the EncodedTemp' using assign activity.

6. Insert a JavaEmbedding Activity which will encode the contents of 'EncodedTemp' to Base64Encoding. Below is the code which is used - 

          To use Java Embedding you also need to import oracle.soa.common.util inside BPEL.
          Go to BPEL Source and paste import statements above Java Embedding activity -

7. Now Double click on Email activity again and click on Attachments. Set the values as shown below - 

That is only what you need to do. Deploy the project and test it. It works absolutely fine.. :)

No comments:

Post a Comment