Matter faced during integration project

Friday, May 29, 2009

A BPEL process that saves e-mail attachment

BPEL process that receive e-mails, get the attachment and save it somewhere in the disk.

The process looks like that:




Create a process that receives mail

follow the steps here:
http://blogs.bpel-people.com/2007/01/using-email-to-initiate-bpel-process.html

Save the attachment

There are 3 options:
1. Use a file adapter: you cannot easily define the file name, it always has to be the same. Furthermore there are some issues with the base64 encoding.

2. Use another web service to save the file (not a BPEL one): if you need to do some complex processing of the file it might be your only option.

3. Save the file with a "Java embedding" activities: this is the option I choose as I can easily set the name of the file + don't have to worry about the encoding.

The assign attachment is:



The java embedding is:



<bpelx:exec name="saveFile" language="java" version="1.5">
<![CDATA[java.io.Writer output = null;
try{
String name = (String)getVariableData("attachmentName");
int pos = name.lastIndexOf("name=");
String newName = name.substring(pos+6, name.length()-1);

java.io.File file = new java.io.File("c:\\" + newName);
output = new java.io.FileWriter(file);
output.write((String)getVariableData("attachment"));
} catch (Exception e) {
addAuditTrailEntry(e);
} finally {
try {
output.close();
} catch (java.io.IOException e) {
addAuditTrailEntry(e);
}
}]]>
</bpelx:exec>



http://forums.oracle.com/forums/thread.jspa?threadID=602700

1 comment: